14
14
15
15
# ######################### Recovery Services Tests #############################
16
16
17
+ function Get-ResourceGroupLocation
18
+ {
19
+ $namespace = " Microsoft.RecoveryServices"
20
+ $type = " vaults"
21
+ $resourceProvider = Get-AzureRmResourceProvider - ProviderNamespace $namespace | where {$_.ResourceTypes [0 ].ResourceTypeName -eq $type }
22
+
23
+ if ($resourceProvider -eq $null )
24
+ {
25
+ return " westus" ;
26
+ }
27
+ else
28
+ {
29
+ return $resourceProvider.Locations [0 ]
30
+ }
31
+ }
32
+
33
+ function Get-RandomSuffix (
34
+ [int ] $size = 8 )
35
+ {
36
+ $variableName = " NamingSuffix"
37
+ if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer ]::Mode -eq [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode ]::Record)
38
+ {
39
+ if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer ]::Variables.ContainsKey($variableName ))
40
+ {
41
+ $suffix = [Microsoft.Azure.Test.HttpRecorder.HttpMockServer ]::Variables[$variableName ]
42
+ }
43
+ else
44
+ {
45
+ $suffix = @ ((New-Guid ).Guid)
46
+
47
+ [Microsoft.Azure.Test.HttpRecorder.HttpMockServer ]::Variables[$variableName ] = $suffix
48
+ }
49
+ }
50
+ else
51
+ {
52
+ $suffix = [Microsoft.Azure.Test.HttpRecorder.HttpMockServer ]::Variables[$variableName ]
53
+ }
54
+
55
+ return $suffix.Substring (0 , $size )
56
+ }
57
+
58
+ function Create-ResourceGroup (
59
+ [string ] $location )
60
+ {
61
+ $name = " PSTestRG" + @ (Get-RandomSuffix )
62
+
63
+ $resourceGroup = Get-AzureRmResourceGroup - Name $name - ErrorAction Ignore
64
+
65
+ if ($resourceGroup -eq $null )
66
+ {
67
+ New-AzureRmResourceGroup - Name $name - Location $location | Out-Null
68
+ }
69
+
70
+ return $name
71
+ }
72
+
73
+ function Cleanup-ResourceGroup (
74
+ [string ] $resourceGroupName )
75
+ {
76
+ $resourceGroup = Get-AzureRmResourceGroup - Name $resourceGroupName - ErrorAction Ignore
77
+
78
+ if ($resourceGroup -ne $null )
79
+ {
80
+ # Cleanup Vaults
81
+ $vaults = Get-AzureRmRecoveryServicesVault - ResourceGroupName $resourceGroupName
82
+ foreach ($vault in $vaults )
83
+ {
84
+ Remove-AzureRmRecoveryServicesVault - Vault $vault
85
+ }
86
+
87
+ # Cleanup RG. This cleans up all VMs and Storage Accounts.
88
+ Remove-AzureRmResourceGroup - Name $resourceGroupName - Force
89
+ }
90
+ }
91
+
17
92
<#
18
93
. SYNOPSIS
19
94
Recovery Services Vault CRUD Tests
20
95
#>
21
- function Test-RecoveryServicesVaultCRUDTests
96
+ function Test-RecoveryServicesVaultCRUD
22
97
{
23
- # Create vault
24
- $vaultCreationResponse = New-AzureRmRecoveryServicesVault - Name rsv1 - ResourceGroupName RsvTestRG - Location westus
25
- Assert-NotNull ($vaultCreationResponse.Name )
26
- Assert-NotNull ($vaultCreationResponse.ID )
27
- Assert-NotNull ($vaultCreationResponse.Type )
28
-
29
- # Enumerate Vaults
30
- $vaults = Get-AzureRmRecoveryServicesVault - Name rsv1 - ResourceGroupName RsvTestRG
31
- Assert-True { $vaults.Count -gt 0 }
32
- Assert-NotNull ($vaults )
33
- foreach ($vault in $vaults )
98
+ $location = Get-ResourceGroupLocation
99
+ $resourceGroupName = Create- ResourceGroup $location
100
+ $name = " PSTestRSV" + @ (Get-RandomSuffix )
101
+
102
+ try
34
103
{
35
- Assert-NotNull ($vault.Name )
36
- Assert-NotNull ($vault.ID )
37
- Assert-NotNull ($vault.Type )
38
- }
104
+ # 1. New-AzureRmRecoveryServicesVault
105
+ $vault1 = New-AzureRmRecoveryServicesVault - Name $name - ResourceGroupName $resourceGroupName - Location $location
106
+
107
+ Assert-NotNull ($vault1.Name )
108
+ Assert-NotNull ($vault1.ID )
109
+ Assert-NotNull ($vault1.Type )
110
+
111
+ # 2. Set-AzureRmRecoveryServicesVaultContext
112
+ Set-AzureRmRecoveryServicesVaultContext - Vault $vault1
113
+
114
+ # 3. Get-AzureRmRecoveryServicesVault
115
+ $vaults = Get-AzureRmRecoveryServicesVault - Name $name - ResourceGroupName $resourceGroupName
116
+
117
+ Assert-NotNull ($vaults )
118
+ Assert-True { $vaults.Count -gt 0 }
119
+ foreach ($vault in $vaults )
120
+ {
121
+ Assert-NotNull ($vault.Name )
122
+ Assert-NotNull ($vault.ID )
123
+ Assert-NotNull ($vault.Type )
124
+ }
39
125
40
- $vaultBackupProperties = Get-AzureRmRecoveryServicesBackupProperty - Vault $vaultCreationResponse
41
- Assert-NotNull ( $vaultBackupProperties.BackupStorageRedundancy )
126
+ # 4. Get-AzureRmRecoveryServicesBackupProperty
127
+ $vaultBackupProperties = Get-AzureRmRecoveryServicesBackupProperty - Vault $vault1
42
128
43
- Set-AzureRmRecoveryServicesBackupProperties - Vault $vaultCreationResponse - BackupStorageRedundancy " LocallyRedundant "
129
+ Assert-NotNull ( $vaultBackupProperties . BackupStorageRedundancy)
44
130
45
- # Get the created vault
46
- $vaultToBeProcessed = Get-AzureRmRecoveryServicesVault - ResourceGroupName RsvTestRG - Name rsv1
47
- Assert-NotNull ($vaultToBeProcessed.Name )
48
- Assert-NotNull ($vaultToBeProcessed.ID )
49
- Assert-NotNull ($vaultToBeProcessed.Type )
131
+ # 5. Set-AzureRmRecoveryServicesBackupProperties
132
+ Set-AzureRmRecoveryServicesBackupProperties - Vault $vault1 - BackupStorageRedundancy LocallyRedundant
50
133
51
- # Remove Vault
52
- Remove-AzureRmRecoveryServicesVault - Vault $vaultToBeProcessed
53
- $vaults = Get-AzureRmRecoveryServicesVault - ResourceGroupName RsvTestRG - Name rsv1
54
- Assert-True { $vaults.Count -eq 0 }
134
+ # 6. Remove-AzureRmRecoveryServicesVault
135
+ Remove-AzureRmRecoveryServicesVault - Vault $vault1
136
+
137
+ $vaults = Get-AzureRmRecoveryServicesVault - ResourceGroupName $resourceGroupName - Name $name
138
+ Assert-True { $vaults.Count -eq 0 }
139
+ }
140
+ finally
141
+ {
142
+ Cleanup- ResourceGroup $resourceGroupName
143
+ }
55
144
}
56
145
57
- function Test-RecoveryServicesVaultCredFileDownloadTest
146
+ function Test-GetRSVaultSettingsFile
58
147
{
59
- # Create vault
60
- $vaultCreationResponse = New-AzureRmRecoveryServicesVault - Name rsv1 - ResourceGroupName RsvTestRG - Location westus
61
- Assert-NotNull ( $vaultCreationResponse .Name )
62
- Assert-NotNull ( $vaultCreationResponse .ID )
63
- Assert-NotNull ( $vaultCreationResponse .Type )
64
-
65
- $drives = Get-PSDrive - PSProvider ' FileSystem '
66
- $folderPath = $drives [ 0 ].Root
67
- $file = Get-AzureRmRecoveryServicesVaultSettingsFile - Vault $vaultCreationResponse - Backup - Path $path
68
- Assert-True { Test-Path $file .FilePath }
69
- $fileContent = Get-Content $file .FilePath
70
- Assert-Contains ( $fileContent , $vaultCreationResponse .Name )
71
- Assert-Contains ( $fileContent , $vaultCreationResponse .ResourceGroupName )
72
- Assert-Contains ( $fileContent , $vaultCreationResponse .Location )
73
-
74
- # Remove Vault
75
- Remove-AzureRmRecoveryServicesVault - Vault $vaultCreationResponse
76
- $vaults = Get-AzureRmRecoveryServicesVault - ResourceGroupName RsvTestRG - Name rsv1
77
- Assert-True { $vaults .Count -eq 0 }
148
+ $location = Get-ResourceGroupLocation
149
+ $resourceGroupName = Create - ResourceGroup $location
150
+ $name = " PSTestRSV " + @ ( Get-RandomSuffix )
151
+
152
+ try
153
+ {
154
+ # 1. New-AzureRmRecoveryServicesVault
155
+ $vault = New-AzureRmRecoveryServicesVault - Name $name - ResourceGroupName $resourceGroupName - Location $location
156
+
157
+ # 2. Get-AzureRmRecoveryServicesVaultSettingsFile
158
+ $file = Get-AzureRmRecoveryServicesVaultSettingsFile - Vault $vault - Backup
159
+
160
+ Assert-NotNull $file
161
+ Assert-NotNull $file .FilePath
162
+ }
163
+ finally
164
+ {
165
+ Cleanup - ResourceGroup $resourceGroupName
166
+ }
78
167
}
0 commit comments