Esempio n. 1
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);
            }
        }