Skip to content

Commit

Permalink
added new tests and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
hiaga committed Feb 1, 2023
1 parent feed072 commit ec0d188
Show file tree
Hide file tree
Showing 8 changed files with 3,375 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,28 @@ public void TestAzureVMCRRWithDES()
);
}


[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(TestConstants.Workload, TestConstants.AzureVM)]
public void TestAzureVaultPublicNetworkAccess()
{
TestRunner.RunTestScript(
$"Import-Module {_IaasVmcommonModule.AsAbsoluteLocation()}",
$"Import-Module {_IaasVmtestModule.AsAbsoluteLocation()}",
"Test-AzureVaultPublicNetworkAccess"
);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(TestConstants.Workload, TestConstants.AzureVM)]
public void TestAzureVaultImmutability()
{
TestRunner.RunTestScript(
$"Import-Module {_IaasVmcommonModule.AsAbsoluteLocation()}",
$"Import-Module {_IaasVmtestModule.AsAbsoluteLocation()}",
"Test-AzureVaultImmutability"
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,89 @@
# limitations under the License.
# ----------------------------------------------------------------------------------

function Test-AzureVaultPublicNetworkAccess
{
$resourceGroupName = "hiagaCZR-rg"
$vaultName = "hiagaPNAVault"
$location = "eastus2euap"
$tag= @{"MABUsed"="Yes";"Owner"="hiaga";"Purpose"="Testing";"DeleteBy"="01-2099"}

try
{
# new vault
# Public Network Access is by default enabled for this vault and can be updated using Update-AzRecoveryServicesVault cmdlet
$vault = New-AzRecoveryServicesVault -Name $vaultName -ResourceGroupName $resourceGroupName -Location $location -Tag $tag
$vault = Get-AzRecoveryServicesVault -Name $vaultName -ResourceGroupName $resourceGroupName

Assert-True { $vault.Properties.PublicNetworkAccess -eq "Enabled"}

$vault = Update-AzRecoveryServicesVault -ResourceGroupName $resourceGroupName -Name $vaultName -PublicNetworkAccess "Disabled"
Assert-True { $vault.Properties.PublicNetworkAccess -eq "Disabled"}
}
finally
{
# remove vault
$vault = Get-AzRecoveryServicesVault -ResourceGroupName $resourceGroupName -Name $vaultName
Remove-AzRecoveryServicesVault -Vault $vault
}
}

function Test-AzureVaultImmutability
{
$resourceGroupName = "hiagaCZR-rg"
$vaultName = "hiagaImmutableVault"
$location = "eastus2euap"
$tag= @{"MABUsed"="Yes";"Owner"="hiaga";"Purpose"="Testing";"DeleteBy"="01-2099"}

$suspendVaultName = "hiaga-adhoc-vault"
$suspendResourceGroupName = "hiagarg"

try
{
# new vault
$vault = New-AzRecoveryServicesVault -Name $vaultName -ResourceGroupName $resourceGroupName -Location $location -Tag $tag -ImmutabilityState "Disabled"
$vault = Get-AzRecoveryServicesVault -Name $vaultName -ResourceGroupName $resourceGroupName

Assert-True { $vault.Properties.ImmutabilitySettings.ImmutabilityState -eq "Disabled"}

Assert-ThrowsContains { $vault = Update-AzRecoveryServicesVault -Name $vaultName -ResourceGroupName $resourceGroupName -ImmutabilityState Locked } `
"Immutability can only be locked when it is Unlocked(Enabled)";

$vault = Update-AzRecoveryServicesVault -Name $vaultName -ResourceGroupName $resourceGroupName -ImmutabilityState "Unlocked"
$vault = Get-AzRecoveryServicesVault -Name $vaultName -ResourceGroupName $resourceGroupName

Assert-True { $vault.Properties.ImmutabilitySettings.ImmutabilityState -eq "Unlocked"}

# get suspend vault
$suspendVault = Update-AzRecoveryServicesVault -Name $suspendVaultName -ResourceGroupName $suspendResourceGroupName -ImmutabilityState "Unlocked"
$suspendVault = Get-AzRecoveryServicesVault -Name $suspendVaultName -ResourceGroupName $suspendResourceGroupName

$item = Get-AzRecoveryServicesBackupItem -VaultId $suspendVault.ID -BackupManagementType AzureVM -WorkloadType AzureVM
Assert-True { $item[0].ProtectionState -eq "Protected" }

# suspend backup
Disable-AzRecoveryServicesBackupProtection -Item $item[0] -RetainRecoveryPointsAsPerPolicy -VaultId $suspendVault.ID -Force
$item = Get-AzRecoveryServicesBackupItem -VaultId $suspendVault.ID -BackupManagementType AzureVM -WorkloadType AzureVM
Assert-True { $item[0].ProtectionState -eq "BackupsSuspended" }

# resume backup
$pol = Get-AzRecoveryServicesBackupProtectionPolicy -VaultId $suspendVault.ID -Name "DefaultPolicy"
Enable-AzRecoveryServicesBackupProtection -Item $item[0] -Policy $pol -VaultId $suspendVault.ID

$item = Get-AzRecoveryServicesBackupItem -VaultId $suspendVault.ID -BackupManagementType AzureVM -WorkloadType AzureVM
Assert-True { $item[0].ProtectionState -eq "Protected" }
}
finally
{
# revert immutability
$suspendVault = Update-AzRecoveryServicesVault -Name $suspendVaultName -ResourceGroupName $suspendResourceGroupName -ImmutabilityState "Disabled"

# remove new vault
$vault = Get-AzRecoveryServicesVault -ResourceGroupName $resourceGroupName -Name $vaultName
Remove-AzRecoveryServicesVault -Vault $vault
}
}

function Test-AzureVMCRRWithDES
{
$resourceGroupName = "hiagarg"
Expand Down
Loading

0 comments on commit ec0d188

Please sign in to comment.