Ejemplo n.º 1
0
        private async Task <Uri> GrantAccess(SnapshotResource snapshot)
        {
            var grantOperation = await snapshot.GrantAccessAsync(WaitUntil.Completed,
                                                                 new GrantAccessData(AccessLevel.Read, 3600));

            AccessUri accessUri = await grantOperation.WaitForCompletionAsync();

            return(new Uri(accessUri.AccessSas));
        }
Ejemplo n.º 2
0
        private async Task <Uri> GrantAccess(Snapshot snapshot)
        {
            var grantOperation = await snapshot.GrantAccessAsync(true,
                                                                 new GrantAccessData(AccessLevel.Read, 3600));

            AccessUri accessUri = await grantOperation.WaitForCompletionAsync();

            return(new Uri(accessUri.AccessSAS));
        }
        // Verify disk restore points.
        private void VerifyDiskRestorePoint(string rgName, string rpcName, string rpName)
        {
            IPage <DiskRestorePoint> listDiskRestorePoint = m_CrpClient.DiskRestorePoint.ListByRestorePoint(rgName, rpcName, rpName);
            GrantAccessData          accessData           = new GrantAccessData {
                Access = AccessLevel.Read, DurationInSeconds = 1000
            };

            foreach (DiskRestorePoint drp in listDiskRestorePoint)
            {
                var getDrp = m_CrpClient.DiskRestorePoint.Get(rgName, rpcName, rpName, drp.Name);
                ValidateDiskRestorePoint(getDrp, drp.Name);

                AccessUri accessUri = m_CrpClient.DiskRestorePoint.GrantAccess(rgName, rpcName, rpName, getDrp.Name, accessData);
                Assert.NotNull(accessUri.AccessSAS);

                getDrp = m_CrpClient.DiskRestorePoint.Get(rgName, rpcName, rpName, drp.Name);
                ValidateDiskRestorePoint(getDrp, drp.Name);

                m_CrpClient.DiskRestorePoint.RevokeAccess(rgName, rpcName, rpName, drp.Name);
            }
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
0
        protected void Disk_CRUD_Execute(string diskCreateOption, string methodName, int?diskSizeGB = null, string location = null, IList <string> zones = null)
        {
            using (MockContext context = MockContext.Start(this.GetType().FullName, methodName))
            {
                EnsureClientsInitialized(context);
                DiskRPLocation = location ?? DiskRPLocation;

                // Data
                var  rgName   = TestUtilities.GenerateName(TestPrefix);
                var  diskName = TestUtilities.GenerateName(DiskNamePrefix);
                Disk disk     = GenerateDefaultDisk(diskCreateOption, rgName, diskSizeGB, zones);

                try
                {
                    // **********
                    // SETUP
                    // **********
                    // Create resource group, unless create option is import in which case resource group will be created with vm
                    if (diskCreateOption != DiskCreateOption.Import)
                    {
                        m_ResourcesClient.ResourceGroups.CreateOrUpdate(rgName, new ResourceGroup {
                            Location = DiskRPLocation
                        });
                    }

                    // **********
                    // TEST
                    // **********
                    // Put
                    Disk diskOut = m_CrpClient.Disks.CreateOrUpdate(rgName, diskName, disk);
                    Validate(disk, diskOut, DiskRPLocation);

                    // Get
                    diskOut = m_CrpClient.Disks.Get(rgName, diskName);
                    Validate(disk, diskOut, DiskRPLocation);

                    // Get disk access
                    AccessUri accessUri = m_CrpClient.Disks.GrantAccess(rgName, diskName, AccessDataDefault);
                    Assert.NotNull(accessUri.AccessSAS);

                    // Get
                    diskOut = m_CrpClient.Disks.Get(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 = m_CrpClient.Disks.Update(rgName, diskName, updatedisk);
                        Validate(disk, diskOut, DiskRPLocation);
                    }

                    // Get
                    diskOut = m_CrpClient.Disks.Get(rgName, diskName);
                    Validate(disk, diskOut, DiskRPLocation);

                    // End disk access
                    m_CrpClient.Disks.RevokeAccess(rgName, diskName);

                    // Delete
                    m_CrpClient.Disks.Delete(rgName, diskName);

                    try
                    {
                        // Ensure it was really deleted
                        m_CrpClient.Disks.Get(rgName, diskName);
                        Assert.False(true);
                    }
                    catch (CloudException ex)
                    {
                        Assert.Equal(HttpStatusCode.NotFound, ex.Response.StatusCode);
                    }
                }
                finally
                {
                    // Delete resource group
                    m_ResourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }
Ejemplo n.º 7
0
        protected void Snapshot_CRUD_Execute(string diskCreateOption, string methodName, int?diskSizeGB = null, string location = null)
        {
            using (MockContext context = MockContext.Start(this.GetType().FullName, methodName))
            {
                EnsureClientsInitialized(context);
                DiskRPLocation = location ?? DiskRPLocation;

                // Data
                var  rgName       = TestUtilities.GenerateName(TestPrefix);
                var  diskName     = TestUtilities.GenerateName(DiskNamePrefix);
                var  snapshotName = TestUtilities.GenerateName(DiskNamePrefix);
                Disk sourceDisk   = GenerateDefaultDisk(diskCreateOption, rgName, diskSizeGB);

                try
                {
                    // **********
                    // SETUP
                    // **********
                    // Create resource group
                    m_ResourcesClient.ResourceGroups.CreateOrUpdate(rgName, new ResourceGroup {
                        Location = DiskRPLocation
                    });

                    // Put disk
                    Disk diskOut = m_CrpClient.Disks.CreateOrUpdate(rgName, diskName, sourceDisk);
                    Validate(sourceDisk, diskOut, DiskRPLocation);

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

                    // **********
                    // TEST
                    // **********
                    // Put
                    Snapshot snapshotOut = m_CrpClient.Snapshots.CreateOrUpdate(rgName, snapshotName, snapshot);
                    Validate(snapshot, snapshotOut);

                    // Get
                    snapshotOut = m_CrpClient.Snapshots.Get(rgName, snapshotName);
                    Validate(snapshot, snapshotOut);

                    // Get access
                    AccessUri accessUri = m_CrpClient.Snapshots.GrantAccess(rgName, snapshotName, AccessDataDefault);
                    Assert.NotNull(accessUri.AccessSAS);

                    // Get
                    snapshotOut = m_CrpClient.Snapshots.Get(rgName, snapshotName);
                    Validate(snapshot, snapshotOut);

                    // Patch
                    var          updatesnapshot = new SnapshotUpdate();
                    const string tagKey         = "tageKey";
                    updatesnapshot.Tags = new Dictionary <string, string>()
                    {
                        { tagKey, "tagvalue" }
                    };
                    snapshotOut = m_CrpClient.Snapshots.Update(rgName, snapshotName, updatesnapshot);
                    Validate(snapshot, snapshotOut);

                    // Get
                    snapshotOut = m_CrpClient.Snapshots.Get(rgName, snapshotName);
                    Validate(snapshot, snapshotOut);

                    // End access
                    m_CrpClient.Snapshots.RevokeAccess(rgName, snapshotName);

                    // Delete
                    m_CrpClient.Snapshots.Delete(rgName, snapshotName);

                    try
                    {
                        // Ensure it was really deleted
                        m_CrpClient.Snapshots.Get(rgName, snapshotName);
                        Assert.False(true);
                    }
                    catch (CloudException ex)
                    {
                        Assert.Equal(HttpStatusCode.NotFound, ex.Response.StatusCode);
                    }
                }
                finally
                {
                    // Delete resource group
                    m_ResourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }