Skip to content

Commit

Permalink
Update GetAzureRmRecoveryServicesBackupSchedulePolicyObject to defa…
Browse files Browse the repository at this point in the history
…ult the `PolicySubType` to `Enhanced` for AzureVM. (Azure#27039)

* Set default policy for IaaSVM as enhanced policy

* update Test-AzureVMEnhancedPolicyAsDefault

* update in logic and readme

* Update in readme
  • Loading branch information
SourabhSomnathGholap authored Jan 24, 2025
1 parent 9704192 commit d8ba659
Show file tree
Hide file tree
Showing 6 changed files with 885 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,17 @@ public void TestAzureVMCrashconsistentPolicy()
"Test-AzureVMCrashconsistentPolicy"
);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(TestConstants.Workload, TestConstants.AzureVM)]
public void TestAzureVMEnhancedPolicyAsDefaultPolicy()
{
TestRunner.RunTestScript(
$"Import-Module {_IaasVmcommonModule.AsAbsoluteLocation()}",
$"Import-Module {_IaasVmtestModule.AsAbsoluteLocation()}",
"Test-AzureVMEnhancedPolicyAsDefault"
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,54 @@ function Test-AzureVMPolicy
# Cleanup
Cleanup-ResourceGroup $resourceGroupName
}
}

function Test-AzureVMEnhancedPolicyAsDefault
{
try
{
$resourceGroupName = "sgholapCZRTesting"
$vaultName = "sgholapZRSTestingVault"
$owner = "sgholap"
$AzureVMPolicyName = "AzureVMPolicy"
$AzureFilesPolicyName = "AzureFilesPolicy"

$vault = Get-AzRecoveryServicesVault -ResourceGroupName $resourceGroupName -Name $vaultName

$azureVMSchedulePolicy = Get-AzRecoveryServicesBackupSchedulePolicyObject -WorkloadType AzureVM -BackupManagementType AzureVM -ScheduleRunFrequency Weekly
Assert-NotNull $azureVMSchedulePolicy

$azureVMRetentionPolicy = Get-AzRecoveryServicesBackupRetentionPolicyObject -WorkloadType AzureVM -BackupManagementType AzureVM -ScheduleRunFrequency Weekly
Assert-NotNull $azureVMRetentionPolicy

$azureVMPolicy = New-AzRecoveryServicesBackupProtectionPolicy -Name $AzureVMPolicyName -WorkloadType AzureVM -BackupManagementType AzureVM -RetentionPolicy $azureVMRetentionPolicy -SchedulePolicy $azureVMSchedulePolicy -VaultId $vault.ID

Assert-NotNull $azureVMPolicy
Assert-AreEqual $azureVMPolicy.Name $AzureVMPolicyName
# Default policy type for AzureVM should be Enhanced
Assert-AreEqual $azureVMPolicy.PolicySubType "Enhanced"

$azureFilesSchedulePolicy = Get-AzRecoveryServicesBackupSchedulePolicyObject -WorkloadType AzureFiles
Assert-NotNull $azureVMSchedulePolicy

$azureFilesRetentionPolicy = Get-AzRecoveryServicesBackupRetentionPolicyObject -WorkloadType AzureFiles
Assert-NotNull $azureVMRetentionPolicy

$azureFilesPolicy = New-AzRecoveryServicesBackupProtectionPolicy -Name $AzureFilesPolicyName -WorkloadType AzureFiles -RetentionPolicy $azureFilesRetentionPolicy -SchedulePolicy $azureFilesSchedulePolicy -VaultId $vault.ID

Assert-NotNull $azureFilesPolicy
Assert-AreEqual $azureFilesPolicy.Name $AzureFilesPolicyName
# Default policy type for AzureFiles should be Standard
Assert-AreNotEqual $azureFilesPolicy.PolicySubType "Enhanced"
}
finally
{
# Cleanup
# Delete policy
$policy = Get-AzRecoveryServicesBackupProtectionPolicy -VaultId $vault.ID -Name $AzureVMPolicyName
Remove-AzRecoveryServicesBackupProtectionPolicy -VaultId $vault.ID -Policy $policy -Force

$policy = Get-AzRecoveryServicesBackupProtectionPolicy -VaultId $vault.ID -Name $AzureFilesPolicyName
Remove-AzRecoveryServicesBackupProtectionPolicy -VaultId $vault.ID -Policy $policy -Force
}
}
Loading

0 comments on commit d8ba659

Please sign in to comment.