public void RestoreDiskTest() { using (UndoContext context = UndoContext.Current) { context.Start(); string resourceNamespace = ConfigurationManager.AppSettings["ResourceNamespace"]; string resourceGroupName = ConfigurationManager.AppSettings["RsVaultRgNameRP"]; string resourceName = ConfigurationManager.AppSettings["RsVaultNameRP"]; string location = ConfigurationManager.AppSettings["vaultLocationRP"]; // TODO: Create VM instead of taking these parameters from config string containerUniqueName = ConfigurationManager.AppSettings["RsVaultIaasVMContainerUniqueNameRP"]; string itemUniqueName = ConfigurationManager.AppSettings["RsVaultIaasVMItemUniqueNameRP"]; string containeType = ConfigurationManager.AppSettings["IaaSVMContainerType"]; string itemType = ConfigurationManager.AppSettings["IaaSVMItemType"]; string containerUri = containeType + ";" + containerUniqueName; string itemUri = itemType + ";" + itemUniqueName; string storageAccountId = ConfigurationManager.AppSettings["StorageAccountId"]; var client = GetServiceClient<RecoveryServicesBackupManagementClient>(resourceNamespace); // 1. Create vault VaultTestHelpers vaultTestHelper = new VaultTestHelpers(client); vaultTestHelper.CreateVault(resourceGroupName, resourceName, location); // 2. Get default policy PolicyTestHelpers policyTestHelper = new PolicyTestHelpers(client); string policyId = policyTestHelper.GetDefaultPolicyId(resourceGroupName, resourceName); // 3. Enable protection ProtectedItemTestHelpers protectedItemTestHelper = new ProtectedItemTestHelpers(client); protectedItemTestHelper.EnableProtection(resourceGroupName, resourceName, policyId, containerUri, itemUri); // 4. Get protected item's source resource ID var protectedItemResponse = protectedItemTestHelper.GetProtectedItem(resourceGroupName, resourceName, containerUri, itemUri); string sourceResourceId = ((AzureIaaSVMProtectedItem)protectedItemResponse.Item.Properties).VirtualMachineId; // 5. Trigger backup and wait for completion BackupTestHelpers backupTestHelper = new BackupTestHelpers(client); DateTime backupStartTime = DateTime.UtcNow; string backupJobId = backupTestHelper.BackupProtectedItem(resourceGroupName, resourceName, containerUri, itemUri); JobTestHelpers jobTestHelper = new JobTestHelpers(client); jobTestHelper.WaitForJob(resourceGroupName, resourceName, backupJobId); DateTime backupEndTime = DateTime.UtcNow; // 6. Get latest RP RecoveryPointTestHelpers recoveryPointTestHelper = new RecoveryPointTestHelpers(client); var recoveryPoints = recoveryPointTestHelper.ListRecoveryPoints( resourceGroupName, resourceName, containerUri, itemUri, backupStartTime, backupEndTime); var recoveryPointResource = recoveryPointTestHelper.GetRecoveryPointDetails( resourceGroupName, resourceName, containerUri, itemUri, recoveryPoints[0].Name); // ACTION: Trigger disk restore on the latest RP and wait for completion RestoreTestHelpers restoreTestHelper = new RestoreTestHelpers(client); string restoreJobId = restoreTestHelper.RestoreProtectedItem( resourceGroupName, resourceName, containerUri, itemUri, sourceResourceId, storageAccountId, recoveryPointResource); jobTestHelper.WaitForJob(resourceGroupName, resourceName, restoreJobId); } }
public void ListJobsAndGetJobTest() { using (UndoContext context = UndoContext.Current) { context.Start(); string resourceNamespace = ConfigurationManager.AppSettings["ResourceNamespace"]; string resourceGroupName = ConfigurationManager.AppSettings["RsVaultRgNameRP"]; string resourceName = ConfigurationManager.AppSettings["RsVaultNameRP"]; string location = ConfigurationManager.AppSettings["vaultLocationRP"]; // TODO: Create VM instead of taking these parameters from config string containerUniqueName = ConfigurationManager.AppSettings["RsVaultIaasVMContainerUniqueNameRP"]; string itemUniqueName = ConfigurationManager.AppSettings["RsVaultIaasVMItemUniqueNameRP"]; string containeType = ConfigurationManager.AppSettings["IaaSVMContainerType"]; string itemType = ConfigurationManager.AppSettings["IaaSVMItemType"]; string containerUri = containeType + ";" + containerUniqueName; string itemUri = itemType + ";" + itemUniqueName; string utcDateTimeFormat = ConfigurationManager.AppSettings["UTCDateTimeFormat"]; var client = GetServiceClient<RecoveryServicesBackupManagementClient>(resourceNamespace); // 1. Create vault VaultTestHelpers vaultTestHelper = new VaultTestHelpers(client); vaultTestHelper.CreateVault(resourceGroupName, resourceName, location); // 2. Get default policy PolicyTestHelpers policyTestHelper = new PolicyTestHelpers(client); string policyId = policyTestHelper.GetDefaultPolicyId(resourceGroupName, resourceName); // 3. Enable protection ProtectedItemTestHelpers protectedItemTestHelper = new ProtectedItemTestHelpers(client); DateTime protectionStartTime = DateTime.UtcNow; protectedItemTestHelper.EnableProtection(resourceGroupName, resourceName, policyId, containerUri, itemUri); DateTime protectionEndTime = DateTime.UtcNow; // ACTION: List jobs CommonJobQueryFilters commonFilters = new CommonJobQueryFilters(); commonFilters.BackupManagementType = BackupManagementType.AzureIaasVM.ToString(); commonFilters.StartTime = protectionStartTime.ToString(utcDateTimeFormat); commonFilters.EndTime = protectionEndTime.ToString(utcDateTimeFormat); JobTestHelpers helper = new JobTestHelpers(client); var jobList = helper.ListJobs(resourceGroupName, resourceName, commonFilters, null); // VALIDATION foreach (var job in jobList.ItemList.Value) { Assert.NotNull(job.Id); Assert.NotNull(job.Name); helper.ValidateJobResponse(job.Properties, commonFilters); // validating getjob var jobDetails = helper.GetJob(resourceGroupName, resourceName, job.Name); Assert.NotNull(jobDetails); Assert.NotNull(jobDetails.Item); helper.ValidateJobResponse(jobDetails.Item.Properties, null); } } }
public void ListRecoveryPointTest() { using (UndoContext context = UndoContext.Current) { context.Start(); string resourceNamespace = ConfigurationManager.AppSettings["ResourceNamespace"]; string resourceGroupName = ConfigurationManager.AppSettings["RsVaultRgNameRP"]; string resourceName = ConfigurationManager.AppSettings["RsVaultNameRP"]; string location = ConfigurationManager.AppSettings["vaultLocationRP"]; // TODO: Create VM instead of taking these parameters from config string containerUniqueName = ConfigurationManager.AppSettings["RsVaultIaasVMContainerUniqueNameRP"]; string itemUniqueName = ConfigurationManager.AppSettings["RsVaultIaasVMItemUniqueNameRP"]; string containeType = ConfigurationManager.AppSettings["IaaSVMContainerType"]; string itemType = ConfigurationManager.AppSettings["IaaSVMItemType"]; string containerUri = containeType + ";" + containerUniqueName; string itemUri = itemType + ";" + itemUniqueName; string fabricName = ConfigurationManager.AppSettings["AzureBackupFabricName"]; string utcDateTimeFormat = ConfigurationManager.AppSettings["UTCDateTimeFormat"]; var client = GetServiceClient<RecoveryServicesBackupManagementClient>(resourceNamespace); // 1. Create vault VaultTestHelpers vaultTestHelper = new VaultTestHelpers(client); vaultTestHelper.CreateVault(resourceGroupName, resourceName, location); // 2. Get default policy PolicyTestHelpers policyTestHelper = new PolicyTestHelpers(client); string policyId = policyTestHelper.GetDefaultPolicyId(resourceGroupName, resourceName); // 3. Enable protection ProtectedItemTestHelpers protectedItemTestHelper = new ProtectedItemTestHelpers(client); protectedItemTestHelper.EnableProtection(resourceGroupName, resourceName, policyId, containerUri, itemUri); // 4. Trigger backup and wait for completion BackupTestHelpers backupTestHelper = new BackupTestHelpers(client); DateTime backupStartTime = DateTime.UtcNow; string jobId = backupTestHelper.BackupProtectedItem(resourceGroupName, resourceName, containerUri, itemUri); JobTestHelpers jobTestHelper = new JobTestHelpers(client); jobTestHelper.WaitForJob(resourceGroupName, resourceName, jobId); DateTime backupEndTime = DateTime.UtcNow; // ACTION: Fetch RP RecoveryPointQueryParameters queryFilter = new RecoveryPointQueryParameters(); queryFilter.StartDate = backupStartTime.ToString(utcDateTimeFormat); queryFilter.EndDate = backupEndTime.ToString(utcDateTimeFormat); var response = client.RecoveryPoints.List( resourceGroupName, resourceName, CommonTestHelper.GetCustomRequestHeaders(), fabricName, containerUri, itemUri, queryFilter); // VALIDATION: Should be only one RP Assert.NotNull(response.RecoveryPointList); Assert.NotNull(response.RecoveryPointList.RecoveryPoints); Assert.Equal(1, response.RecoveryPointList.RecoveryPoints.Count); } }
public void BackupProtectedItemTest() { using (UndoContext context = UndoContext.Current) { context.Start(); string resourceNamespace = ConfigurationManager.AppSettings["ResourceNamespace"]; string resourceGroupName = ConfigurationManager.AppSettings["RsVaultRgNameRP"]; string resourceName = ConfigurationManager.AppSettings["RsVaultNameRP"]; string location = ConfigurationManager.AppSettings["vaultLocationRP"]; // TODO: Create VM instead of taking these parameters from config string containerUniqueName = ConfigurationManager.AppSettings["RsVaultIaasVMContainerUniqueNameRP"]; string itemUniqueName = ConfigurationManager.AppSettings["RsVaultIaasVMItemUniqueNameRP"]; string containeType = ConfigurationManager.AppSettings["IaaSVMContainerType"]; string itemType = ConfigurationManager.AppSettings["IaaSVMItemType"]; string containerUri = containeType + ";" + containerUniqueName; string itemUri = itemType + ";" + itemUniqueName; var client = GetServiceClient<RecoveryServicesBackupManagementClient>(resourceNamespace); // 1. Create vault VaultTestHelpers vaultTestHelper = new VaultTestHelpers(client); vaultTestHelper.CreateVault(resourceGroupName, resourceName, location); // 2. Get default policy PolicyTestHelpers policyTestHelper = new PolicyTestHelpers(client); string policyId = policyTestHelper.GetDefaultPolicyId(resourceGroupName, resourceName); // 3. Enable protection ProtectedItemTestHelpers protectedItemTestHelper = new ProtectedItemTestHelpers(client); protectedItemTestHelper.EnableProtection(resourceGroupName, resourceName, policyId, containerUri, itemUri); // Action: Trigger backup and wait for completion BackupTestHelpers backupTestHelper = new BackupTestHelpers(client); string jobId = backupTestHelper.BackupProtectedItem(resourceGroupName, resourceName, containerUri, itemUri); JobTestHelpers jobTestHelper = new JobTestHelpers(client); jobTestHelper.WaitForJob(resourceGroupName, resourceName, jobId); } }
public void CancelJobTest() { using (UndoContext context = UndoContext.Current) { context.Start(); string resourceNamespace = ConfigurationManager.AppSettings["ResourceNamespace"]; string resourceGroupName = ConfigurationManager.AppSettings["RsVaultRgNameRP"]; string resourceName = ConfigurationManager.AppSettings["RsVaultNameRP"]; string location = ConfigurationManager.AppSettings["vaultLocationRP"]; // TODO: Create VM instead of taking these parameters from config string containerUniqueName = ConfigurationManager.AppSettings["RsVaultIaasVMContainerUniqueNameRP"]; string itemUniqueName = ConfigurationManager.AppSettings["RsVaultIaasVMItemUniqueNameRP"]; string containeType = ConfigurationManager.AppSettings["IaaSVMContainerType"]; string itemType = ConfigurationManager.AppSettings["IaaSVMItemType"]; string containerUri = containeType + ";" + containerUniqueName; string itemUri = itemType + ";" + itemUniqueName; var client = GetServiceClient<RecoveryServicesBackupManagementClient>(resourceNamespace); // 1. Create vault VaultTestHelpers vaultTestHelper = new VaultTestHelpers(client); vaultTestHelper.CreateVault(resourceGroupName, resourceName, location); // 2. Get default policy PolicyTestHelpers policyTestHelper = new PolicyTestHelpers(client); string policyId = policyTestHelper.GetDefaultPolicyId(resourceGroupName, resourceName); // 3. Enable protection ProtectedItemTestHelpers protectedItemTestHelper = new ProtectedItemTestHelpers(client); DateTime protectionStartTime = DateTime.UtcNow; protectedItemTestHelper.EnableProtection(resourceGroupName, resourceName, policyId, containerUri, itemUri); DateTime protectionEndTime = DateTime.UtcNow; // 4. Trigger backup and get the job BackupTestHelpers backupTestHelper = new BackupTestHelpers(client); string jobId = backupTestHelper.BackupProtectedItem(resourceGroupName, resourceName, containerUri, itemUri); CommonJobQueryFilters commonFilters = new CommonJobQueryFilters(); commonFilters.Status = JobStatus.InProgress.ToString(); commonFilters.Operation = JobOperation.Backup.ToString(); JobTestHelpers helper = new JobTestHelpers(client); var job = helper.GetJob(resourceGroupName, resourceName, jobId); // ACTION: Cancel the job var cancelResponse = helper.CancelJob(resourceGroupName, resourceName, jobId); var opId = helper.GetOpId(cancelResponse.Location); var opStatus = helper.GetJobOperationStatus(resourceGroupName, resourceName, jobId, opId); TestUtilities.RetryActionWithTimeout( () => opStatus = helper.GetJobOperationStatus(resourceGroupName, resourceName, jobId, opId), () => opStatus.StatusCode != HttpStatusCode.Accepted, TimeSpan.FromMinutes(30), statusCode => { if (HttpMockServer.Mode == HttpRecorderMode.Record) { Thread.Sleep(15 * 1000); } return true; }); } }
public void GetRecoveryPointDetailTest() { using (UndoContext context = UndoContext.Current) { context.Start(); string resourceNamespace = ConfigurationManager.AppSettings["ResourceNamespace"]; var client = GetServiceClient<RecoveryServicesBackupManagementClient>(resourceNamespace); // 1. Create vault string resourceGroupName = ConfigurationManager.AppSettings["RsVaultRgNameRP"]; string resourceName = ConfigurationManager.AppSettings["RsVaultNameRP"]; string location = ConfigurationManager.AppSettings["vaultLocationRP"]; VaultTestHelpers vaultTestHelper = new VaultTestHelpers(client); vaultTestHelper.CreateVault(resourceGroupName, resourceName, location); // 2. Get default policy PolicyTestHelpers policyTestHelper = new PolicyTestHelpers(client); string policyId = policyTestHelper.GetDefaultPolicyId(resourceGroupName, resourceName); // 3. Enable protection // TODO: Create VM instead of taking these parameters from config string containerUniqueName = ConfigurationManager.AppSettings["RsVaultIaasVMContainerUniqueNameRP"]; string itemUniqueName = ConfigurationManager.AppSettings["RsVaultIaasVMItemUniqueNameRP"]; string containeType = ConfigurationManager.AppSettings["IaaSVMContainerType"]; string itemType = ConfigurationManager.AppSettings["IaaSVMItemType"]; string containerUri = containeType + ";" + containerUniqueName; string itemUri = itemType + ";" + itemUniqueName; ProtectedItemTestHelpers protectedItemTestHelper = new ProtectedItemTestHelpers(client); protectedItemTestHelper.EnableProtection(resourceGroupName, resourceName, policyId, containerUri, itemUri); // 4. Trigger backup and wait for completion BackupTestHelpers backupTestHelper = new BackupTestHelpers(client); DateTime backupStartTime = DateTime.UtcNow; string jobId = backupTestHelper.BackupProtectedItem(resourceGroupName, resourceName, containerUri, itemUri); JobTestHelpers jobTestHelper = new JobTestHelpers(client); jobTestHelper.WaitForJob(resourceGroupName, resourceName, jobId); DateTime backupEndTime = DateTime.UtcNow; // 5. Get latest RP RecoveryPointTestHelpers recoveryPointTestHelper = new RecoveryPointTestHelpers(client); var recoveryPoints = recoveryPointTestHelper.ListRecoveryPoints( resourceGroupName, resourceName, containerUri, itemUri, backupStartTime, backupEndTime); var recoveryPointResource = recoveryPoints[0]; var recoveryPoint = (RecoveryPoint)recoveryPointResource.Properties; // ACTION: Get RP details string fabricName = ConfigurationManager.AppSettings["AzureBackupFabricName"]; var response = client.RecoveryPoints.Get( resourceGroupName, resourceName, CommonTestHelper.GetCustomRequestHeaders(), fabricName, containerUri, itemUri, recoveryPointResource.Name); // VALIDATION: Should be valid RP Assert.NotNull(response); Assert.NotNull(response.RecPoint); Assert.True(!string.IsNullOrEmpty(response.RecPoint.Name), "RP Id cant be null"); Assert.True(!string.IsNullOrEmpty(((RecoveryPoint)response.RecPoint.Properties).RecoveryPointTime), "RecoveryPointTime can't be null or empty"); Assert.True(!string.IsNullOrEmpty(((RecoveryPoint)response.RecPoint.Properties).SourceVMStorageType), "SourceVMStorageType can't be null or empty"); } }