Skip to content

Commit ab4b64e

Browse files
Add new optional parameter CVMOsDiskEncryptionSetId in Restore-AzRecoveryServicesBackupItem (#28203)
1 parent e92a8e2 commit ab4b64e

File tree

9 files changed

+4173
-7
lines changed

9 files changed

+4173
-7
lines changed

src/RecoveryServices/RecoveryServices.Backup.Models/CmdletParamEnums.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ public enum RestoreVMBackupItemParams
8787
TargetSubscriptionId,
8888
RestoreToEdgeZone,
8989
DiskAccessOption,
90-
TargetDiskAccessId
90+
TargetDiskAccessId,
91+
CVMOsDiskEncryptionSetId
9192
}
9293

9394
public enum RestoreFSBackupItemParams

src/RecoveryServices/RecoveryServices.Backup.Providers/Providers/IaasVmPsBackupProvider.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,8 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
518518

519519
Dictionary<UriEnums, string> uriDict = HelperUtils.ParseUri(rp.Id);
520520
string containerUri = HelperUtils.GetContainerUri(uriDict, rp.Id);
521+
string cVMOsDiskEncryptionSetId = ProviderData.ContainsKey(RestoreVMBackupItemParams.CVMOsDiskEncryptionSetId) ?
522+
ProviderData[RestoreVMBackupItemParams.CVMOsDiskEncryptionSetId].ToString() : null;
521523

522524
if (targetSubscriptionId == null || targetSubscriptionId == "") targetSubscriptionId = ServiceClientAdapter.SubscriptionId;
523525

@@ -647,6 +649,11 @@ public RestAzureNS.AzureOperationResponse TriggerRestore()
647649
}
648650
}
649651

652+
if (!string.IsNullOrWhiteSpace(cVMOsDiskEncryptionSetId))
653+
{
654+
restoreRequest.SecuredVMDetails = new SecuredVMDetails(cVMOsDiskEncryptionSetId);
655+
}
656+
650657
if (restoreType == "OriginalLocation") // replace existing
651658
{
652659
restoreRequest.RecoveryType = RecoveryType.OriginalLocation;

src/RecoveryServices/RecoveryServices.Backup.Test/ScenarioTests/IaasVm/ItemTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,5 +339,17 @@ public void TestAzurePERestore()
339339
"Test-AzurePERestore"
340340
);
341341
}
342+
343+
[Fact]
344+
[Trait(Category.AcceptanceType, Category.CheckIn)]
345+
[Trait(TestConstants.Workload, TestConstants.AzureVM)]
346+
public void TestAzureRestoreWithCVMOsDiskEncryptionSetId()
347+
{
348+
TestRunner.RunTestScript(
349+
$"Import-Module {_IaasVmcommonModule.AsAbsoluteLocation()}",
350+
$"Import-Module {_IaasVmtestModule.AsAbsoluteLocation()}",
351+
"Test-AzureRestoreWithCVMOsDiskEncryptionSetId"
352+
);
353+
}
342354
}
343355
}

src/RecoveryServices/RecoveryServices.Backup.Test/ScenarioTests/IaasVm/ItemTests.ps1

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,3 +1332,62 @@ function Test-AzureVMDiskExclusion
13321332
cleanup-ResourceGroup $resourceGroupName
13331333
}
13341334
}
1335+
1336+
function Test-AzureRestoreWithCVMOsDiskEncryptionSetId()
1337+
{
1338+
$location = "eastus2euap"
1339+
$resourceGroupName = "sgholap-rg"
1340+
$vaultName = "PSTestingVault"
1341+
$vmName = "PSCVMRestoreTestingVM"
1342+
$saName = "sgholapecysa3"
1343+
$targetVMName = "PSRestoreVM"
1344+
$targetVNetName = "testadeecy-vnet"
1345+
$targetRG = "asmaskarrg"
1346+
$targetSubnetName = "default"
1347+
$owner = "sgholap"
1348+
$subscriptionId = "5288acd1-ba79-4377-9205-9f220331a44a"
1349+
$recoveryPointId = "807152782396876"
1350+
$cVMOSDiskEncryptionSetId = "/subscriptions/5288acd1-ba79-4377-9205-9f220331a44a/resourceGroups/sgholap-rg/providers/Microsoft.Compute/diskEncryptionSets/CVMPSRestoreDES"
1351+
try
1352+
{
1353+
# Setup
1354+
$vault = Get-AzRecoveryServicesVault -ResourceGroupName $resourceGroupName -Name $vaultName
1355+
$namedContainer = Get-AzRecoveryServicesBackupContainer -ContainerType "AzureVM" -FriendlyName $vmName -VaultId $vault.ID
1356+
$backupitem = Get-AzRecoveryServicesBackupItem -Container $namedContainer -WorkloadType "AzureVM" -VaultId $vault.ID
1357+
$rp = Get-AzRecoveryServicesBackupRecoveryPoint -Item $backupitem -VaultId $vault.ID -RecoveryPointId $recoveryPointId
1358+
1359+
# Test command by passing CVMOSDiskEncryptionSetId as non-empty string
1360+
$restoreJob = Restore-AzRecoveryServicesBackupItem -VaultId $vault.ID -VaultLocation $vault.Location `
1361+
-RecoveryPoint $rp[0] -StorageAccountName $saName -StorageAccountResourceGroupName $vault.ResourceGroupName -TargetResourceGroupName $targetRG -TargetVMName $targetVMName -TargetVNetName $targetVNetName -TargetVNetResourceGroup $targetRG -TargetSubnetName $targetSubnetName -CVMOSDiskEncryptionSetId $cVMOSDiskEncryptionSetId
1362+
1363+
$restoreJob = $restoreJob | Wait-AzRecoveryServicesBackupJob -VaultId $vault.ID
1364+
1365+
Assert-True { $restoreJob.Status -eq "Completed" }
1366+
1367+
Delete-VM $targetRG $targetVMName
1368+
1369+
# Test command by passing CVMOSDiskEncryptionSetId as empty string
1370+
$cVMOSDiskEncryptionSetId = ""
1371+
1372+
$restoreJob = Restore-AzRecoveryServicesBackupItem -VaultId $vault.ID -VaultLocation $vault.Location `
1373+
-RecoveryPoint $rp[0] -StorageAccountName $saName -StorageAccountResourceGroupName $vault.ResourceGroupName -TargetResourceGroupName $targetRG -TargetVMName $targetVMName -TargetVNetName $targetVNetName -TargetVNetResourceGroup $targetRG -TargetSubnetName $targetSubnetName -CVMOSDiskEncryptionSetId $cVMOSDiskEncryptionSetId
1374+
1375+
$restoreJob = $restoreJob | Wait-AzRecoveryServicesBackupJob -VaultId $vault.ID
1376+
1377+
Assert-True { $restoreJob.Status -eq "Completed" }
1378+
1379+
Delete-VM $targetRG $targetVMName
1380+
1381+
# Test command without passing CVMOSDiskEncryptionSetId
1382+
$restoreJob = Restore-AzRecoveryServicesBackupItem -VaultId $vault.ID -VaultLocation $vault.Location `
1383+
-RecoveryPoint $rp[0] -StorageAccountName $saName -StorageAccountResourceGroupName $vault.ResourceGroupName -TargetResourceGroupName $targetRG -TargetVMName $targetVMName -TargetVNetName $targetVNetName -TargetVNetResourceGroup $targetRG -TargetSubnetName $targetSubnetName
1384+
1385+
$restoreJob = $restoreJob | Wait-AzRecoveryServicesBackupJob -VaultId $vault.ID
1386+
1387+
Assert-True { $restoreJob.Status -eq "Completed" }
1388+
}
1389+
finally
1390+
{
1391+
Delete-VM $targetRG $targetVMName
1392+
}
1393+
}

0 commit comments

Comments
 (0)