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 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 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"); } }