public void TestAttachServerVolume() { IComputeProvider provider = new CloudServersProvider(Bootstrapper.Settings.TestIdentity); IBlockStorageProvider blockStorageProvider = new CloudBlockStorageProvider(Bootstrapper.Settings.TestIdentity); VolumeType volumeType = UserBlockStorageTests.GetSsdVolumeTypeOrDefault(blockStorageProvider); string volumeName = UserBlockStorageTests.UnitTestVolumePrefix + Path.GetRandomFileName(); Volume volume = blockStorageProvider.CreateVolume(UserBlockStorageTests.MinimumVolumeSize, displayName: volumeName, volumeType: volumeType != null ? volumeType.Id : null); Assert.AreEqual(VolumeState.Available, blockStorageProvider.WaitForVolumeAvailable(volume.Id).Status); /* AttachServerVolume */ ServerVolume serverVolume = provider.AttachServerVolume(_server.Id, volume.Id); Assert.IsNotNull(serverVolume); Assert.IsFalse(string.IsNullOrEmpty(serverVolume.Id)); Assert.AreEqual(_server.Id, serverVolume.ServerId); Assert.AreEqual(volume.Id, serverVolume.VolumeId); Assert.AreEqual(VolumeState.InUse, blockStorageProvider.WaitForVolumeState(volume.Id, VolumeState.InUse, new[] { VolumeState.Available, VolumeState.Error }).Status); /* ListServerVolumes */ ServerVolume[] serverVolumes = provider.ListServerVolumes(_server.Id).ToArray(); Assert.IsNotNull(serverVolumes); Assert.AreEqual(1, serverVolumes.Length); Assert.AreEqual(serverVolume.Id, serverVolumes[0].Id); Assert.AreEqual(serverVolume.ServerId, serverVolumes[0].ServerId); Assert.AreEqual(serverVolume.VolumeId, serverVolumes[0].VolumeId); /* GetServerVolumeDetails */ ServerVolume volumeDetails = provider.GetServerVolumeDetails(_server.Id, volume.Id); Assert.IsNotNull(volumeDetails); Assert.AreEqual(serverVolume.Id, volumeDetails.Id); Assert.AreEqual(serverVolume.ServerId, volumeDetails.ServerId); Assert.AreEqual(serverVolume.VolumeId, volumeDetails.VolumeId); bool detach = provider.DetachServerVolume(_server.Id, volume.Id); Assert.IsTrue(detach); ServerVolume[] remainingVolumes = provider.ListServerVolumes(_server.Id).ToArray(); Assert.AreEqual(0, remainingVolumes.Length); Assert.AreEqual(VolumeState.Available, blockStorageProvider.WaitForVolumeAvailable(volume.Id).Status); bool deleted = blockStorageProvider.DeleteVolume(volume.Id); Assert.IsTrue(blockStorageProvider.WaitForVolumeDeleted(volume.Id)); }
public void TestBasicVolumeFeatures() { IBlockStorageProvider provider = new CloudBlockStorageProvider(Bootstrapper.Settings.TestIdentity); string displayName = UnitTestVolumePrefix + Path.GetRandomFileName(); Volume result = provider.CreateVolume(MinimumVolumeSize, displayName: displayName); Assert.IsNotNull(result); Assert.IsNotNull(result.Id); Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented)); Volume updated = provider.WaitForVolumeAvailable(result.Id); Assert.IsNotNull(updated); Assert.AreEqual(result.Id, updated.Id); Assert.AreEqual(VolumeState.Available, updated.Status); bool deleted = provider.DeleteVolume(result.Id); Assert.IsTrue(deleted); deleted = provider.WaitForVolumeDeleted(result.Id); Assert.IsTrue(deleted); try { provider.ShowVolume(result.Id); Assert.Fail("Expected an exception after a volume is deleted."); } catch (ItemNotFoundException) { // this makes the most sense } catch (UserNotAuthorizedException) { // this is allowed by the interface, and some providers could report it for security reasons } catch (ResponseException) { // this is allowed by the interface } }
public void Should_Wait_Until_Test_Volume_Becomes_Available_Or_Exceeds_Timeout_For_Becoming_Available() { var provider = new CloudBlockStorageProvider(); var volumeListResponse = provider.ListVolumes(identity: _testIdentity); if (volumeListResponse != null && volumeListResponse.Any()) { var testVolume = volumeListResponse.FirstOrDefault(x => x.DisplayName == volumeDisplayName); if (testVolume == null) { Assert.Fail("Could not find test volume to query for Available status."); } var volumeDetails = provider.WaitForVolumeAvailable(testVolume.Id, identity: _testIdentity); Assert.IsNotNull(volumeDetails); Assert.AreEqual(VolumeState.Available, volumeDetails.Status); } else { Assert.Fail("No volumes present to obtain Available status."); } }
public void TestBasicSnapshotFeatures() { IBlockStorageProvider provider = new CloudBlockStorageProvider(Bootstrapper.Settings.TestIdentity); // // Volume setup... // string volumeDisplayName = UnitTestVolumePrefix + Path.GetRandomFileName(); VolumeType ssdType = GetSsdVolumeTypeOrDefault(provider); if (ssdType != null) { Console.WriteLine("Using an SSD volume to improve snapshot test performance."); } else { Console.WriteLine("No SSD volume type is available for the snapshot test... falling back to the default."); } Volume result = provider.CreateVolume(MinimumVolumeSize, displayName: volumeDisplayName, volumeType: ssdType != null ? ssdType.Id : null); Assert.IsNotNull(result); Assert.IsNotNull(result.Id); Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented)); Volume updated = provider.WaitForVolumeAvailable(result.Id); Assert.IsNotNull(updated); Assert.AreEqual(result.Id, updated.Id); Assert.AreEqual(VolumeState.Available, updated.Status); // // Snapshot testing // string snapshotDisplayName = UnitTestSnapshotPrefix + Path.GetRandomFileName(); Snapshot snapshot = provider.CreateSnapshot(result.Id, displayName: snapshotDisplayName); Assert.IsNotNull(snapshot); Assert.IsNotNull(snapshot.Id); Console.WriteLine(JsonConvert.SerializeObject(snapshot, Formatting.Indented)); Snapshot updatedSnapshot = provider.WaitForSnapshotAvailable(snapshot.Id); Assert.IsNotNull(updatedSnapshot); Assert.AreEqual(snapshot.Id, updatedSnapshot.Id); Assert.AreEqual(SnapshotState.Available, updatedSnapshot.Status); bool deleted = provider.DeleteSnapshot(snapshot.Id); Assert.IsTrue(deleted); deleted = provider.WaitForSnapshotDeleted(snapshot.Id); Assert.IsTrue(deleted); try { provider.ShowSnapshot(snapshot.Id); Assert.Fail("Expected an exception after a snapshot is deleted."); } catch (ItemNotFoundException) { // this makes the most sense } catch (UserNotAuthorizedException) { // this is allowed by the interface, and some providers could report it for security reasons } catch (ResponseException) { // this is allowed by the interface } // // Volume cleanup... // bool deletedVolume = provider.DeleteVolume(result.Id); Assert.IsTrue(deletedVolume); deletedVolume = provider.WaitForVolumeDeleted(result.Id); Assert.IsTrue(deletedVolume); }
public void TestBasicSnapshotFeatures() { IBlockStorageProvider provider = new CloudBlockStorageProvider(Bootstrapper.Settings.TestIdentity); // // Volume setup... // string volumeDisplayName = UnitTestVolumePrefix + Path.GetRandomFileName(); VolumeType ssdType = GetSsdVolumeTypeOrDefault(provider); if (ssdType != null) Console.WriteLine("Using an SSD volume to improve snapshot test performance."); else Console.WriteLine("No SSD volume type is available for the snapshot test... falling back to the default."); Volume result = provider.CreateVolume(MinimumVolumeSize, displayName: volumeDisplayName, volumeType: ssdType != null ? ssdType.Id : null); Assert.IsNotNull(result); Assert.IsNotNull(result.Id); Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented)); Volume updated = provider.WaitForVolumeAvailable(result.Id); Assert.IsNotNull(updated); Assert.AreEqual(result.Id, updated.Id); Assert.AreEqual(VolumeState.Available, updated.Status); // // Snapshot testing // string snapshotDisplayName = UnitTestSnapshotPrefix + Path.GetRandomFileName(); Snapshot snapshot = provider.CreateSnapshot(result.Id, displayName: snapshotDisplayName); Assert.IsNotNull(snapshot); Assert.IsNotNull(snapshot.Id); Console.WriteLine(JsonConvert.SerializeObject(snapshot, Formatting.Indented)); Snapshot updatedSnapshot = provider.WaitForSnapshotAvailable(snapshot.Id); Assert.IsNotNull(updatedSnapshot); Assert.AreEqual(snapshot.Id, updatedSnapshot.Id); Assert.AreEqual(SnapshotState.Available, updatedSnapshot.Status); bool deleted = provider.DeleteSnapshot(snapshot.Id); Assert.IsTrue(deleted); deleted = provider.WaitForSnapshotDeleted(snapshot.Id); Assert.IsTrue(deleted); try { provider.ShowSnapshot(snapshot.Id); Assert.Fail("Expected an exception after a snapshot is deleted."); } catch (ItemNotFoundException) { // this makes the most sense } catch (UserNotAuthorizedException) { // this is allowed by the interface, and some providers could report it for security reasons } catch (ResponseException) { // this is allowed by the interface } // // Volume cleanup... // bool deletedVolume = provider.DeleteVolume(result.Id); Assert.IsTrue(deletedVolume); deletedVolume = provider.WaitForVolumeDeleted(result.Id); Assert.IsTrue(deletedVolume); }