public async Task DiskEncryptionPositiveTest()
        {
            EnsureClientsInitialized(DefaultLocation);
            string testVaultId               = @"/subscriptions/" + TestEnvironment.SubscriptionId + "/resourceGroups/24/providers/Microsoft.KeyVault/vaults/swaggervault2";
            string encryptionKeyUri          = @"https://swaggervault2.vault.azure.net/keys/swaggerkey/6108e4eb47c14bdf863f1465229f8e66";
            string secretUri                 = @"https://swaggervault2.vault.azure.net/secrets/swaggersecret/c464e5083aab4f73968700e8b077c54d";
            string encryptionSettingsVersion = "1.0";

            var  rgName   = Recording.GenerateAssetName(TestPrefix);
            var  diskName = Recording.GenerateAssetName(DiskNamePrefix);
            Disk disk     = await GenerateDefaultDisk(DiskCreateOption.Empty.ToString(), rgName, 10);

            disk.EncryptionSettingsCollection = GetDiskEncryptionSettings(testVaultId, encryptionKeyUri, secretUri, encryptionSettingsVersion: encryptionSettingsVersion);
            disk.Location = DiskRPLocation;
            await ResourceGroupsOperations.CreateOrUpdateAsync(rgName, new ResourceGroup(DiskRPLocation));

            //put disk
            await WaitForCompletionAsync((await DisksOperations.StartCreateOrUpdateAsync(rgName, diskName, disk)));

            Disk diskOut = await DisksOperations.GetAsync(rgName, diskName);

            Validate(disk, diskOut, disk.Location);
            Assert.AreEqual(encryptionSettingsVersion, diskOut.EncryptionSettingsCollection.EncryptionSettingsVersion);
            Assert.AreEqual(disk.EncryptionSettingsCollection.EncryptionSettings.First().DiskEncryptionKey.SecretUrl, diskOut.EncryptionSettingsCollection.EncryptionSettings.First().DiskEncryptionKey.SecretUrl);
            Assert.AreEqual(disk.EncryptionSettingsCollection.EncryptionSettings.First().DiskEncryptionKey.SourceVault.Id, diskOut.EncryptionSettingsCollection.EncryptionSettings.First().DiskEncryptionKey.SourceVault.Id);
            Assert.AreEqual(disk.EncryptionSettingsCollection.EncryptionSettings.First().KeyEncryptionKey.KeyUrl, diskOut.EncryptionSettingsCollection.EncryptionSettings.First().KeyEncryptionKey.KeyUrl);
            Assert.AreEqual(disk.EncryptionSettingsCollection.EncryptionSettings.First().KeyEncryptionKey.SourceVault.Id, diskOut.EncryptionSettingsCollection.EncryptionSettings.First().KeyEncryptionKey.SourceVault.Id);
            await WaitForCompletionAsync(await DisksOperations.StartDeleteAsync(rgName, diskName));
        }
Esempio n. 2
0
        protected async Task DiskEncryptionSet_CreateDisk_Execute(string methodName, string location = null)
        {
            EnsureClientsInitialized(DefaultLocation);
            var  rgName   = Recording.GenerateAssetName(TestPrefix);
            var  diskName = Recording.GenerateAssetName(DiskNamePrefix);
            var  desName  = "longlivedSwaggerDES";
            Disk disk     = await GenerateDefaultDisk(DiskCreateOption.Empty.ToString(), rgName, 10);

            disk.Location = location;

            await ResourceGroupsOperations.CreateOrUpdateAsync(rgName, new ResourceGroup(location));

            // Get DiskEncryptionSet
            DiskEncryptionSet desOut = await DiskEncryptionSetsOperations.GetAsync("longrunningrg-southeastasia", desName);

            Assert.NotNull(desOut);
            disk.Encryption = new Encryption
            {
                Type = EncryptionType.EncryptionAtRestWithCustomerKey.ToString(),
                DiskEncryptionSetId = desOut.Id
            };
            //Put Disk
            await WaitForCompletionAsync(await DisksOperations.StartCreateOrUpdateAsync(rgName, diskName, disk));

            Disk diskOut = await DisksOperations.GetAsync(rgName, diskName);

            Validate(disk, diskOut, disk.Location);
            Assert.AreEqual(desOut.Id.ToLower(), diskOut.Encryption.DiskEncryptionSetId.ToLower());
            Assert.AreEqual(EncryptionType.EncryptionAtRestWithCustomerKey, diskOut.Encryption.Type);

            await WaitForCompletionAsync(await DisksOperations.StartDeleteAsync(rgName, diskName));
        }
Esempio n. 3
0
        private async Task <Disk> CreateDataDisk(string diskName)
        {
            var disk = new Disk(null, null, null, TestEnvironment.Location, null, null, null, null, null, null, null, null, null, 10, null, null, null, null, null, null, null, null, null, null, null, null);

            disk.Sku          = new DiskSku(StorageAccountTypes.StandardLRS.ToString(), null);
            disk.CreationData = new CreationData(DiskCreateOption.Empty);
            return(await WaitForCompletionAsync((await DisksOperations.StartCreateOrUpdateAsync(rgName, diskName, disk))));
        }
Esempio n. 4
0
        protected async Task Disk_List_Execute(string diskCreateOption, string methodName, int?diskSizeGB = null, string location = null)
        {
            EnsureClientsInitialized(DefaultLocation);
            DiskRPLocation = location ?? DiskRPLocation;

            // Data
            var  rgName1   = Recording.GenerateAssetName(TestPrefix);
            var  rgName2   = Recording.GenerateAssetName(TestPrefix);
            var  diskName1 = Recording.GenerateAssetName(DiskNamePrefix);
            var  diskName2 = Recording.GenerateAssetName(DiskNamePrefix);
            Disk disk1     = await GenerateDefaultDisk(diskCreateOption, rgName1, diskSizeGB, location : location);

            Disk disk2 = await GenerateDefaultDisk(diskCreateOption, rgName2, diskSizeGB, location : location);

            // **********
            // SETUP
            // **********
            // Create resource groups, unless create option is import in which case resource group will be created with vm
            if (diskCreateOption != DiskCreateOption.Import)
            {
                await ResourceGroupsOperations.CreateOrUpdateAsync(rgName1, new ResourceGroup(DiskRPLocation));

                await ResourceGroupsOperations.CreateOrUpdateAsync(rgName2, new ResourceGroup(DiskRPLocation));
            }

            // Put 4 disks, 2 in each resource group
            await WaitForCompletionAsync(await DisksOperations.StartCreateOrUpdateAsync(rgName1, diskName1, disk1));
            await WaitForCompletionAsync(await DisksOperations.StartCreateOrUpdateAsync(rgName1, diskName2, disk2));
            await WaitForCompletionAsync(await DisksOperations.StartCreateOrUpdateAsync(rgName2, diskName1, disk1));
            await WaitForCompletionAsync(await DisksOperations.StartCreateOrUpdateAsync(rgName2, diskName2, disk2));

            // **********
            // TEST
            // **********
            // List disks under resource group
            var disksOut = await DisksOperations.ListByResourceGroupAsync(rgName1).ToEnumerableAsync();

            //Page<Disk> disksOut = (await DisksClient.ListByResourceGroupAsync(rgName1)).ToEnumerableAsync;
            Assert.AreEqual(2, disksOut.Count());
            //Assert.Null(disksOut.NextPageLink);

            disksOut = await DisksOperations.ListByResourceGroupAsync(rgName2).ToEnumerableAsync();

            Assert.AreEqual(2, disksOut.Count());
            //Assert.Null(disksOut.NextPageLink);

            // List disks under subscription
            disksOut = await DisksOperations.ListAsync().ToEnumerableAsync();

            Assert.True(disksOut.Count() >= 4);
            //if (disksOut.NextPageLink != null)
            //{
            //    disksOut = await DisksClient.ListNext(disksOut.NextPageLink);
            //    Assert.True(disksOut.Any());
            //}
        }
Esempio n. 5
0
        /// <summary>
        /// Generates a disk used when the DiskCreateOption is Copy
        /// </summary>
        /// <returns></returns>
        private async Task <Disk> GenerateCopyDisk(string rgName, int diskSizeGB, string location)
        {
            // Create an empty disk
            Disk originalDisk = await GenerateDefaultDisk("Empty", rgName, diskSizeGB : diskSizeGB);

            await ResourceGroupsOperations.CreateOrUpdateAsync(rgName, new ResourceGroup(location));

            Disk diskOut = await WaitForCompletionAsync((await DisksOperations.StartCreateOrUpdateAsync(rgName, Recording.GenerateAssetName(DiskNamePrefix + "_original"), originalDisk)));

            Snapshot snapshot    = GenerateDefaultSnapshot(diskOut.Id);
            Snapshot snapshotOut = await WaitForCompletionAsync((await SnapshotsOperations.StartCreateOrUpdateAsync(rgName, "snapshotswaaggertest", snapshot)));

            Disk copyDisk = GenerateBaseDisk("Import");

            copyDisk.CreationData.SourceResourceId = snapshotOut.Id;
            return(copyDisk);
        }
Esempio n. 6
0
        public async Task DiskHyperVGenerationOmittedTest()
        {
            EnsureClientsInitialized(DefaultLocation);
            var  rgName   = Recording.GenerateAssetName(TestPrefix);
            var  diskName = Recording.GenerateAssetName(DiskNamePrefix);
            Disk disk     = await GenerateDefaultDisk(DiskCreateOption.Empty.ToString(), rgName, 10);

            disk.Location = DiskRPLocation;
            await ResourceGroupsOperations.CreateOrUpdateAsync(rgName, new ResourceGroup(DiskRPLocation));

            //put disk
            await WaitForCompletionAsync(await DisksOperations.StartCreateOrUpdateAsync(rgName, diskName, disk));

            Disk diskOut = await DisksOperations.GetAsync(rgName, diskName);

            Validate(disk, diskOut, disk.Location);
            Assert.AreEqual(disk.HyperVGeneration, diskOut.HyperVGeneration);
            await WaitForCompletionAsync(await DisksOperations.StartDeleteAsync(rgName, diskName));
        }
        public async Task DiskFromGalleryImageVersion()
        {
            EnsureClientsInitialized(DefaultLocation);
            var  rgName   = Recording.GenerateAssetName(TestPrefix);
            var  diskName = Recording.GenerateAssetName(DiskNamePrefix);
            Disk disk     = GenerateBaseDisk(DiskCreateOption.FromImage.ToString());

            disk.Location = DiskRPLocation;
            disk.CreationData.GalleryImageReference = new ImageDiskReference("/subscriptions/0296790d-427c-48ca-b204-8b729bbd8670/resourceGroups/swaggertests/providers/Microsoft.Compute/galleries/swaggergallery/images/lunexample2/versions/1.0.0", 1);
            await ResourceGroupsOperations.CreateOrUpdateAsync(rgName, new ResourceGroup(DiskRPLocation));

            //put disk
            await WaitForCompletionAsync(await DisksOperations.StartCreateOrUpdateAsync(rgName, diskName, disk));

            Disk diskOut = await DisksOperations.GetAsync(rgName, diskName);

            Validate(disk, diskOut, disk.Location);
            Assert.AreEqual(disk.CreationData.CreateOption, diskOut.CreationData.CreateOption);
            await WaitForCompletionAsync(await DisksOperations.StartDeleteAsync(rgName, diskName));
        }
        public async Task DiskEncryptionNegativeTest()
        {
            EnsureClientsInitialized(DefaultLocation);
            string fakeTestVaultId =
                @"/subscriptions/" + TestEnvironment.SubscriptionId + "/resourceGroups/testrg/providers/Microsoft.KeyVault/vaults/keyvault";
            string fakeEncryptionKeyUri = @"https://testvault.vault.azure.net/secrets/swaggersecret/test123";

            var  rgName   = Recording.GenerateAssetName(TestPrefix);
            var  diskName = Recording.GenerateAssetName(DiskNamePrefix);
            Disk disk     = await GenerateDefaultDisk(DiskCreateOption.Empty.ToString(), rgName, 10);

            disk.EncryptionSettingsCollection = GetDiskEncryptionSettings(fakeTestVaultId, fakeEncryptionKeyUri, fakeEncryptionKeyUri);
            disk.Location = DiskRPLocation;
            try
            {
                await ResourceGroupsOperations.CreateOrUpdateAsync(rgName,
                                                                   new ResourceGroup(DiskRPLocation));
                await WaitForCompletionAsync((await DisksOperations.StartCreateOrUpdateAsync(rgName, diskName, disk)));

                Disk diskOut = await DisksOperations.GetAsync(rgName, diskName);

                Validate(disk, diskOut, disk.Location);
                Assert.AreEqual(disk.EncryptionSettingsCollection.EncryptionSettings.First().DiskEncryptionKey.SecretUrl, diskOut.EncryptionSettingsCollection.EncryptionSettings.First().DiskEncryptionKey.SecretUrl);
                Assert.AreEqual(disk.EncryptionSettingsCollection.EncryptionSettings.First().DiskEncryptionKey.SourceVault.Id, diskOut.EncryptionSettingsCollection.EncryptionSettings.First().DiskEncryptionKey.SourceVault.Id);
                Assert.AreEqual(disk.EncryptionSettingsCollection.EncryptionSettings.First().KeyEncryptionKey.KeyUrl, diskOut.EncryptionSettingsCollection.EncryptionSettings.First().KeyEncryptionKey.KeyUrl);
                Assert.AreEqual(disk.EncryptionSettingsCollection.EncryptionSettings.First().KeyEncryptionKey.SourceVault.Id, diskOut.EncryptionSettingsCollection.EncryptionSettings.First().KeyEncryptionKey.SourceVault.Id);
                await WaitForCompletionAsync(await DisksOperations.StartDeleteAsync(rgName, diskName));
            }
            catch (Exception cex)
            {
                string coreresponsestring = fakeEncryptionKeyUri +
                                            " is not a valid versioned Key Vault Secret URL. It should be in the format https://<vaultEndpoint>/secrets/<secretName>/<secretVersion>.";
                Assert.IsTrue(cex.Message.Contains(coreresponsestring));
                //Assert.True(ex.Response.StatusCode == HttpStatusCode.BadRequest);
            }
        }
        private async Task UltraSSD_CRUD_Helper(string location, string methodName, bool useZones = false, bool sharedDisks = false)
        {
            EnsureClientsInitialized(DefaultLocation);

            // Data
            var  rgName   = Recording.GenerateAssetName(TestPrefix);
            var  diskName = Recording.GenerateAssetName(DiskNamePrefix);
            Disk disk     = GenerateBaseDisk("Empty");

            disk.Sku        = new DiskSku(DiskStorageAccountTypes.UltraSSDLRS, "Ultra");
            disk.DiskSizeGB = 32;
            if (useZones)
            {
                disk.Zones = new List <string> {
                    "1"
                };
            }
            disk.DiskMBpsReadWrite = 8;
            disk.DiskIopsReadWrite = 512;
            disk.Location          = location;
            if (sharedDisks)
            {
                disk.DiskIopsReadOnly = 512;
                disk.DiskMBpsReadOnly = 8;
                disk.MaxShares        = 2;
            }
            await ResourceGroupsOperations.CreateOrUpdateAsync(rgName, new ResourceGroup(location));

            // Put
            Disk diskOut = await WaitForCompletionAsync(await DisksOperations.StartCreateOrUpdateAsync(rgName, diskName, disk));

            Validate(disk, diskOut, location);

            // Get
            diskOut = (await DisksOperations.GetAsync(rgName, diskName)).Value;
            Validate(disk, diskOut, location);

            // Patch
            const string tagKey     = "tagKey";
            var          updatedisk = new DiskUpdate();

            updatedisk.Tags = new Dictionary <string, string>()
            {
                { tagKey, "tagValue" }
            };
            updatedisk.DiskMBpsReadWrite = 9;
            updatedisk.DiskIopsReadWrite = 600;
            if (sharedDisks)
            {
                updatedisk.DiskMBpsReadOnly = 9;
                updatedisk.DiskIopsReadOnly = 600;
                updatedisk.MaxShares        = 3;
            }
            updatedisk.Sku = new DiskSku(DiskStorageAccountTypes.UltraSSDLRS, "Ultra");
            diskOut        = await WaitForCompletionAsync(await DisksOperations.StartUpdateAsync(rgName, diskName, updatedisk));

            Validate(disk, diskOut, location, update: true);
            Assert.AreEqual(updatedisk.DiskIopsReadWrite, diskOut.DiskIopsReadWrite);
            Assert.AreEqual(updatedisk.DiskMBpsReadWrite, diskOut.DiskMBpsReadWrite);
            if (sharedDisks)
            {
                Assert.AreEqual(updatedisk.DiskIopsReadOnly, diskOut.DiskIopsReadOnly);
                Assert.AreEqual(updatedisk.DiskMBpsReadOnly, diskOut.DiskMBpsReadOnly);
                Assert.AreEqual(updatedisk.MaxShares, diskOut.MaxShares);
            }

            // Get
            diskOut = await DisksOperations.GetAsync(rgName, diskName);

            Validate(disk, diskOut, location, update: true);
            Assert.AreEqual(updatedisk.DiskIopsReadWrite, diskOut.DiskIopsReadWrite);
            Assert.AreEqual(updatedisk.DiskMBpsReadWrite, diskOut.DiskMBpsReadWrite);
            if (sharedDisks)
            {
                Assert.AreEqual(updatedisk.DiskIopsReadOnly, diskOut.DiskIopsReadOnly);
                Assert.AreEqual(updatedisk.DiskMBpsReadOnly, diskOut.DiskMBpsReadOnly);
                Assert.AreEqual(updatedisk.MaxShares, diskOut.MaxShares);
            }

            // Delete
            await WaitForCompletionAsync(await DisksOperations.StartDeleteAsync(rgName, diskName));

            try
            {
                // Ensure it was really deleted
                await DisksOperations.GetAsync(rgName, diskName);

                Assert.False(true);
            }
            catch (Exception ex)
            {
                Assert.NotNull(ex);
                //Assert.AreEqual(HttpStatusCode.NotFound, ex.Response.StatusCode);
            }
        }
Esempio n. 10
0
        protected async Task Disk_CRUD_Execute(string diskCreateOption, string methodName, int?diskSizeGB = null, string location = null, IList <string> zones = null)
        {
            EnsureClientsInitialized(DefaultLocation);
            DiskRPLocation = location ?? DiskRPLocation;

            // Data
            var  rgName   = Recording.GenerateAssetName(TestPrefix);
            var  diskName = Recording.GenerateAssetName(DiskNamePrefix);
            Disk disk     = await GenerateDefaultDisk(diskCreateOption, rgName, diskSizeGB, zones, location);

            // **********
            // SETUP
            // **********
            // Create resource group, unless create option is import in which case resource group will be created with vm,
            // or copy in which casethe resource group will be created with the original disk.
            if (diskCreateOption != DiskCreateOption.Import && diskCreateOption != DiskCreateOption.Copy)
            {
                await ResourceGroupsOperations.CreateOrUpdateAsync(rgName, new ResourceGroup(DiskRPLocation));
            }

            // **********
            // TEST
            // **********
            // Put
            Disk diskOut = await WaitForCompletionAsync((await DisksOperations.StartCreateOrUpdateAsync(rgName, diskName, disk)));

            Validate(disk, diskOut, DiskRPLocation);

            // Get
            diskOut = await DisksOperations.GetAsync(rgName, diskName);

            Validate(disk, diskOut, DiskRPLocation);
            //string resourceGroupName, string diskName, AccessLevel access, int durationInSeconds, CancellationToken cancellationToken = default
            // Get disk access
            AccessUri accessUri = await WaitForCompletionAsync(await DisksOperations.StartGrantAccessAsync(rgName, diskName, new GrantAccessData(AccessDataDefault.Access, AccessDataDefault.DurationInSeconds)));

            Assert.NotNull(accessUri.AccessSAS);

            // Get
            diskOut = await DisksOperations.GetAsync(rgName, diskName);

            Validate(disk, diskOut, DiskRPLocation);

            // Patch
            // TODO: Bug 9865640 - DiskRP doesn't follow patch semantics for zones: skip this for zones
            if (zones == null)
            {
                const string tagKey     = "tageKey";
                var          updatedisk = new DiskUpdate();
                updatedisk.Tags = new Dictionary <string, string>()
                {
                    { tagKey, "tagvalue" }
                };
                diskOut = await WaitForCompletionAsync(await DisksOperations.StartUpdateAsync(rgName, diskName, updatedisk));

                Validate(disk, diskOut, DiskRPLocation);
            }

            // Get
            diskOut = await DisksOperations.GetAsync(rgName, diskName);

            Validate(disk, diskOut, DiskRPLocation);

            // End disk access
            await WaitForCompletionAsync(await DisksOperations.StartRevokeAccessAsync(rgName, diskName));

            // Delete
            await WaitForCompletionAsync(await DisksOperations.StartDeleteAsync(rgName, diskName));

            try
            {
                // Ensure it was really deleted
                await DisksOperations.GetAsync(rgName, diskName);

                Assert.False(true);
            }
            catch (Exception ex)
            {
                Assert.NotNull(ex);
                //Assert.AreEqual(HttpStatusCode.NotFound, ex.Response.StatusCode);
            }
        }
Esempio n. 11
0
        protected async Task Snapshot_List_Execute(string diskCreateOption, string methodName, int?diskSizeGB = null)
        {
            EnsureClientsInitialized(DefaultLocation);

            // Data
            var  rgName1       = Recording.GenerateAssetName(TestPrefix);
            var  rgName2       = Recording.GenerateAssetName(TestPrefix);
            var  diskName1     = Recording.GenerateAssetName(DiskNamePrefix);
            var  diskName2     = Recording.GenerateAssetName(DiskNamePrefix);
            var  snapshotName1 = Recording.GenerateAssetName(DiskNamePrefix);
            var  snapshotName2 = Recording.GenerateAssetName(DiskNamePrefix);
            Disk disk1         = await GenerateDefaultDisk(diskCreateOption, rgName1, diskSizeGB);

            Disk disk2 = await GenerateDefaultDisk(diskCreateOption, rgName2, diskSizeGB);

            // **********
            // SETUP
            // **********
            // Create resource groups
            await ResourceGroupsOperations.CreateOrUpdateAsync(rgName1, new ResourceGroup(DiskRPLocation));

            await ResourceGroupsOperations.CreateOrUpdateAsync(rgName2, new ResourceGroup(DiskRPLocation));

            // Put 4 disks, 2 in each resource group
            Disk diskOut11 = await WaitForCompletionAsync(await DisksOperations.StartCreateOrUpdateAsync(rgName1, diskName1, disk1));

            Disk diskOut12 = await WaitForCompletionAsync(await DisksOperations.StartCreateOrUpdateAsync(rgName1, diskName2, disk2));

            Disk diskOut21 = await WaitForCompletionAsync(await DisksOperations.StartCreateOrUpdateAsync(rgName2, diskName1, disk1));

            Disk diskOut22 = await WaitForCompletionAsync(await DisksOperations.StartCreateOrUpdateAsync(rgName2, diskName2, disk2));

            // Generate 4 snapshots using disks info
            Snapshot snapshot11 = GenerateDefaultSnapshot(diskOut11.Id);
            Snapshot snapshot12 = GenerateDefaultSnapshot(diskOut12.Id, SnapshotStorageAccountTypes.StandardZRS.ToString());
            Snapshot snapshot21 = GenerateDefaultSnapshot(diskOut21.Id);
            Snapshot snapshot22 = GenerateDefaultSnapshot(diskOut22.Id);

            // Put 4 snapshots, 2 in each resource group
            await WaitForCompletionAsync(await SnapshotsOperations.StartCreateOrUpdateAsync(rgName1, snapshotName1, snapshot11));
            await WaitForCompletionAsync(await SnapshotsOperations.StartCreateOrUpdateAsync(rgName1, snapshotName2, snapshot12));
            await WaitForCompletionAsync(await SnapshotsOperations.StartCreateOrUpdateAsync(rgName2, snapshotName1, snapshot21));
            await WaitForCompletionAsync(await SnapshotsOperations.StartCreateOrUpdateAsync(rgName2, snapshotName2, snapshot22));

            // **********
            // TEST
            // **********
            // List snapshots under resource group
            //IPage<Snapshot> snapshotsOut = await SnapshotsClient.ListByResourceGroupAsync(rgName1);
            var snapshotsOut = await SnapshotsOperations.ListByResourceGroupAsync(rgName1).ToEnumerableAsync();

            Assert.AreEqual(2, snapshotsOut.Count());
            //Assert.Null(snapshotsOut.NextPageLink);

            snapshotsOut = await SnapshotsOperations.ListByResourceGroupAsync(rgName2).ToEnumerableAsync();

            Assert.AreEqual(2, snapshotsOut.Count());
            //Assert.Null(snapshotsOut.NextPageLink);

            // List snapshots under subscription
            snapshotsOut = await SnapshotsOperations.ListAsync().ToEnumerableAsync();

            Assert.True(snapshotsOut.Count() >= 4);
            //if (snapshotsOut.NextPageLink != null)
            //{
            //    snapshotsOut = await SnapshotsClient.ListNext(snapshotsOut.NextPageLink);
            //    Assert.True(snapshotsOut.Any());
            //}
        }
Esempio n. 12
0
        protected async Task Snapshot_CRUD_Execute(string diskCreateOption, string methodName, int?diskSizeGB = null, string location = null, bool incremental = false)
        {
            EnsureClientsInitialized(DefaultLocation);
            DiskRPLocation = location ?? DiskRPLocation;

            // Data
            var  rgName       = Recording.GenerateAssetName(TestPrefix);
            var  diskName     = Recording.GenerateAssetName(DiskNamePrefix);
            var  snapshotName = Recording.GenerateAssetName(DiskNamePrefix);
            Disk sourceDisk   = await GenerateDefaultDisk(diskCreateOption, rgName, diskSizeGB);

            // **********
            // SETUP
            // **********
            // Create resource group
            await ResourceGroupsOperations.CreateOrUpdateAsync(rgName, new ResourceGroup(DiskRPLocation));

            // Put disk
            Disk diskOut = await WaitForCompletionAsync(await DisksOperations.StartCreateOrUpdateAsync(rgName, diskName, sourceDisk));

            Validate(sourceDisk, diskOut, DiskRPLocation);

            // Generate snapshot using disk info
            Snapshot snapshot = GenerateDefaultSnapshot(diskOut.Id, incremental: incremental);

            // **********
            // TEST
            // **********
            // Put
            Snapshot snapshotOut = await WaitForCompletionAsync(await SnapshotsOperations.StartCreateOrUpdateAsync(rgName, snapshotName, snapshot));

            Validate(snapshot, snapshotOut, incremental: incremental);

            // Get
            snapshotOut = (await SnapshotsOperations.GetAsync(rgName, snapshotName)).Value;
            Validate(snapshot, snapshotOut, incremental: incremental);

            // Get access
            AccessUri accessUri = await WaitForCompletionAsync((await SnapshotsOperations.StartGrantAccessAsync(rgName, snapshotName, new GrantAccessData(AccessDataDefault.Access, AccessDataDefault.DurationInSeconds))));

            Assert.NotNull(accessUri.AccessSAS);

            // Get
            snapshotOut = (await SnapshotsOperations.GetAsync(rgName, snapshotName)).Value;
            Validate(snapshot, snapshotOut, incremental: incremental);

            // Patch
            var          updatesnapshot = new SnapshotUpdate();
            const string tagKey         = "tageKey";

            updatesnapshot.Tags = new Dictionary <string, string>()
            {
                { tagKey, "tagvalue" }
            };
            snapshotOut = await WaitForCompletionAsync(await SnapshotsOperations.StartUpdateAsync(rgName, snapshotName, updatesnapshot));

            Validate(snapshot, snapshotOut, incremental: incremental);

            // Get
            snapshotOut = (await SnapshotsOperations.GetAsync(rgName, snapshotName)).Value;
            Validate(snapshot, snapshotOut, incremental: incremental);

            // End access
            await WaitForCompletionAsync(await SnapshotsOperations.StartRevokeAccessAsync(rgName, snapshotName));

            // Delete
            await WaitForCompletionAsync(await SnapshotsOperations.StartDeleteAsync(rgName, snapshotName));

            try
            {
                // Ensure it was really deleted
                await SnapshotsOperations.GetAsync(rgName, snapshotName);

                Assert.False(true);
            }
            catch (Exception ex)
            {
                Assert.NotNull(ex);
                //Assert.AreEqual(HttpStatusCode.NotFound, ex.Response.StatusCode);
            }
        }