@@ -99,4 +99,225 @@ function Test-RecoveryServicesProtectionTests
99
99
}
100
100
}
101
101
}
102
- }
102
+ }
103
+
104
+ <#
105
+ . SYNOPSIS
106
+ Recovery Services Storage mapping tests and validation
107
+ #>
108
+ function Test-StorageMapping
109
+ {
110
+ param ([string ] $vaultSettingsFilePath )
111
+
112
+ # Import Azure Site Recovery Vault Settings
113
+ Import-AzureSiteRecoveryVaultSettingsFile $vaultSettingsFilePath
114
+
115
+ # Enumerate Servers
116
+ $servers = Get-AzureSiteRecoveryServer
117
+ Assert-True { $servers.Count -gt 0 }
118
+ Assert-NotNull ($servers )
119
+ foreach ($server in $servers )
120
+ {
121
+ Assert-NotNull ($server.Name )
122
+ Assert-NotNull ($server.ID )
123
+ }
124
+
125
+ # Enumerate Storages
126
+ $storages = Get-AzureSiteRecoveryStorage - Server $servers [0 ]
127
+ Assert-NotNull ($storages )
128
+ Assert-True { $storages.Count -gt 0 }
129
+ foreach ($storage in $storages )
130
+ {
131
+ Assert-NotNull ($storage.Name )
132
+ Assert-NotNull ($storage.ID )
133
+ }
134
+
135
+ # Enumerate StorageMappings
136
+ $storageMappings = Get-AzureSiteRecoveryStorageMapping - PrimaryServer $servers [0 ] - RecoveryServer $servers [0 ]
137
+ Assert-True { $storageMappings.Count -eq 0 }
138
+
139
+ # Create StorageMapping
140
+ $job = New-AzureSiteRecoveryStorageMapping - PrimaryStorage $storages [0 ] - RecoveryStorage $storages [1 ]
141
+ WaitForJobCompletion - JobId $job.ID
142
+
143
+ # Enumerate StorageMappings
144
+ $storageMappings = Get-AzureSiteRecoveryStorageMapping - PrimaryServer $servers [0 ] - RecoveryServer $servers [0 ]
145
+ Assert-NotNull ($storageMappings )
146
+ Assert-True { $storageMappings.Count -eq 1 }
147
+ Assert-NotNull ($storageMappings [0 ].PrimaryServerId)
148
+ Assert-NotNull ($storageMappings [0 ].PrimaryStorageId)
149
+ Assert-NotNull ($storageMappings [0 ].RecoveryServerId)
150
+ Assert-NotNull ($storageMappings [0 ].RecoveryStorageId)
151
+ }
152
+
153
+ <#
154
+ . SYNOPSIS
155
+ Recovery Services Storage unmapping tests and validation
156
+ #>
157
+ function Test-StorageUnMapping
158
+ {
159
+ param ([string ] $vaultSettingsFilePath )
160
+
161
+ # Import Azure Site Recovery Vault Settings
162
+ Import-AzureSiteRecoveryVaultSettingsFile $vaultSettingsFilePath
163
+
164
+ # Enumerate Servers
165
+ $servers = Get-AzureSiteRecoveryServer
166
+ Assert-True { $servers.Count -gt 0 }
167
+ Assert-NotNull ($servers )
168
+ foreach ($server in $servers )
169
+ {
170
+ Assert-NotNull ($server.Name )
171
+ Assert-NotNull ($server.ID )
172
+ }
173
+
174
+ # Enumerate StorageMappings
175
+ $storageMappings = Get-AzureSiteRecoveryStorageMapping - PrimaryServer $servers [0 ] - RecoveryServer $servers [0 ]
176
+ Assert-NotNull ($storageMappings )
177
+ Assert-True { $storageMappings.Count -eq 1 }
178
+ Assert-NotNull ($storageMappings [0 ].PrimaryServerId)
179
+ Assert-NotNull ($storageMappings [0 ].PrimaryStorageId)
180
+ Assert-NotNull ($storageMappings [0 ].RecoveryServerId)
181
+ Assert-NotNull ($storageMappings [0 ].RecoveryStorageId)
182
+
183
+ # Remove StorageMapping
184
+ $job = Remove-AzureSiteRecoveryStorageMapping - StorageMapping $storageMappings [0 ]
185
+ WaitForJobCompletion - JobId $job.ID
186
+
187
+ # Enumerate StorageMappings
188
+ $storageMappings = Get-AzureSiteRecoveryStorageMapping - PrimaryServer $servers [0 ] - RecoveryServer $servers [0 ]
189
+ Assert-True { $storageMappings.Count -eq 0 }
190
+ }
191
+
192
+ <#
193
+ . SYNOPSIS
194
+ Recovery Services Network mapping tests and validation
195
+ #>
196
+ function Test-NetworkMapping
197
+ {
198
+ param ([string ] $vaultSettingsFilePath )
199
+
200
+ # Import Azure Site Recovery Vault Settings
201
+ Import-AzureSiteRecoveryVaultSettingsFile $vaultSettingsFilePath
202
+
203
+ # Enumerate Servers
204
+ $servers = Get-AzureSiteRecoveryServer
205
+ Assert-True { $servers.Count -gt 0 }
206
+ Assert-NotNull ($servers )
207
+ foreach ($server in $servers )
208
+ {
209
+ Assert-NotNull ($server.Name )
210
+ Assert-NotNull ($server.ID )
211
+ }
212
+
213
+ # Enumerate Networks
214
+ $networks = Get-AzureSiteRecoveryNetwork - Server $servers [0 ]
215
+ Assert-NotNull ($networks )
216
+ Assert-True { $networks.Count -gt 0 }
217
+ foreach ($network in $networks )
218
+ {
219
+ Assert-NotNull ($network.Name )
220
+ Assert-NotNull ($network.ID )
221
+ }
222
+
223
+ # Enumerate NetworkMappings
224
+ $networkMappings = Get-AzureSiteRecoveryNetworkMapping - PrimaryServer $servers [0 ] - RecoveryServer $servers [0 ]
225
+ Assert-True { $networkMappings.Count -eq 0 }
226
+
227
+ # Create NetworkMapping
228
+ $job = New-AzureSiteRecoveryNetworkMapping - PrimaryNetwork $networks [0 ] - RecoveryNetwork $networks [1 ]
229
+ WaitForJobCompletion - JobId $job.ID
230
+
231
+ # Enumerate NetworkMappings
232
+ $networkMappings = Get-AzureSiteRecoveryNetworkMapping - PrimaryServer $servers [0 ] - RecoveryServer $servers [0 ]
233
+ Assert-NotNull ($networkMappings )
234
+ Assert-True { $networkMappings.Count -eq 1 }
235
+ Assert-NotNull ($networkMappings [0 ].PrimaryServerId)
236
+ Assert-NotNull ($networkMappings [0 ].PrimaryNetworkId)
237
+ Assert-NotNull ($networkMappings [0 ].PrimaryNetworkName)
238
+ Assert-NotNull ($networkMappings [0 ].RecoveryServerId)
239
+ Assert-NotNull ($networkMappings [0 ].RecoveryNetworkId)
240
+ Assert-NotNull ($networkMappings [0 ].RecoveryNetworkName)
241
+ }
242
+
243
+ <#
244
+ . SYNOPSIS
245
+ Recovery Services Network unmapping tests and validation
246
+ #>
247
+ function Test-NetworkUnMapping
248
+ {
249
+ param ([string ] $vaultSettingsFilePath )
250
+
251
+ # Import Azure Site Recovery Vault Settings
252
+ Import-AzureSiteRecoveryVaultSettingsFile $vaultSettingsFilePath
253
+
254
+ # Enumerate Servers
255
+ $servers = Get-AzureSiteRecoveryServer
256
+ Assert-True { $servers.Count -gt 0 }
257
+ Assert-NotNull ($servers )
258
+ foreach ($server in $servers )
259
+ {
260
+ Assert-NotNull ($server.Name )
261
+ Assert-NotNull ($server.ID )
262
+ }
263
+
264
+ # Enumerate NetworkMappings
265
+ $networkMappings = Get-AzureSiteRecoveryNetworkMapping - PrimaryServer $servers [0 ] - RecoveryServer $servers [0 ]
266
+ Assert-NotNull ($networkMappings )
267
+ Assert-True { $networkMappings.Count -eq 1 }
268
+ Assert-NotNull ($networkMappings [0 ].PrimaryServerId)
269
+ Assert-NotNull ($networkMappings [0 ].PrimaryNetworkId)
270
+ Assert-NotNull ($networkMappings [0 ].PrimaryNetworkName)
271
+ Assert-NotNull ($networkMappings [0 ].RecoveryServerId)
272
+ Assert-NotNull ($networkMappings [0 ].RecoveryNetworkId)
273
+ Assert-NotNull ($networkMappings [0 ].RecoveryNetworkName)
274
+
275
+ # Remove StorageMapping
276
+ $job = Remove-AzureSiteRecoveryNetworkMapping - NetworkMapping $networkMappings [0 ]
277
+ WaitForJobCompletion - JobId $job.ID
278
+
279
+ # Enumerate NetworkMappings
280
+ $networkMappings = Get-AzureSiteRecoveryNetworkMapping - PrimaryServer $servers [0 ] - RecoveryServer $servers [0 ]
281
+ Assert-True { $networkMappings.Count -eq 0 }
282
+ }
283
+
284
+ function WaitForJobCompletion
285
+ {
286
+ param ([string ] $JobId )
287
+
288
+ do
289
+ {
290
+ Start-Sleep 5
291
+ $job = Get-AzureSiteRecoveryJob - Id $JobId ;
292
+ } while ( -not (($job.State -eq " Succeeded" ) -or ($job.State -eq " Failed" ) -or ($job.State -eq " Cancelled" ) -or ($job.State -eq " Suspended" )))
293
+ }
294
+
295
+ <#
296
+ . SYNOPSIS
297
+ Wait for job completion
298
+ #>
299
+ <# function WaitForJobCompletion
300
+ {
301
+ param([string] $JobId, [Int] $numOfSeconds = 150, [String] $StateDescription)
302
+
303
+ $timeElapse = 0
304
+ $interval = 3
305
+ $endStateDescription = @('Completed','Failed')
306
+ while($timeElapse -lt $numOfSeconds)
307
+ {
308
+ Wait-Seconds $interval
309
+ $timeElapse = $timeElapse + $interval
310
+ $job = Get-AzureSiteRecoveryJob -Id $JobId
311
+ if($job.StateDescription -eq StateDescription)
312
+ {
313
+ break
314
+ }
315
+ elseif($endStateDescription -ccontains $job.StateDescription.ToLower())
316
+ {
317
+ Write-Output ("The Job with ID $($job.ID) reached $($job.ccontains) ccontains already.")
318
+ return
319
+ }
320
+ }
321
+ Assert-AreEqual $StateDescription $job.StateDescription "Job did not reach $StateDescription StateDescription within $numOfSeconds seconds."
322
+ }
323
+ #>
0 commit comments