Skip to content

Commit d1233bb

Browse files
committed
Merged changes from dev
1 parent 9843132 commit d1233bb

File tree

4 files changed

+155
-52
lines changed

4 files changed

+155
-52
lines changed

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices.Test/ScenarioTests/RecoveryServicesTests.ps1

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ function Test-StorageMapping
247247

248248
# Enumerate Servers
249249
$servers = Get-AzureSiteRecoveryServer
250-
Assert-True { $servers.Count -gt 0 }
250+
Assert-True { $servers.Count -gt 1 }
251251
Assert-NotNull($servers)
252252
foreach($server in $servers)
253253
{
@@ -256,25 +256,34 @@ function Test-StorageMapping
256256
}
257257

258258
# Enumerate Storages
259-
$storages = Get-AzureSiteRecoveryStorage -Server $servers[0]
260-
Assert-NotNull($storages)
261-
Assert-True { $storages.Count -gt 0 }
262-
foreach($storage in $storages)
259+
$storagesOnPrimary = Get-AzureSiteRecoveryStorage -Server $servers[0]
260+
Assert-NotNull($storagesOnPrimary)
261+
Assert-True { $storagesOnPrimary.Count -gt 0 }
262+
foreach($storage in $storagesOnPrimary)
263+
{
264+
Assert-NotNull($storage.Name)
265+
Assert-NotNull($storage.ID)
266+
}
267+
268+
$storagesOnRecovery = Get-AzureSiteRecoveryStorage -Server $servers[1]
269+
Assert-NotNull($storagesOnRecovery)
270+
Assert-True { $storagesOnRecovery.Count -gt 0 }
271+
foreach($storage in $storagesOnRecovery)
263272
{
264273
Assert-NotNull($storage.Name)
265274
Assert-NotNull($storage.ID)
266275
}
267276

268277
# Enumerate StorageMappings
269-
$storageMappings = Get-AzureSiteRecoveryStorageMapping -PrimaryServer $servers[0] -RecoveryServer $servers[0]
278+
$storageMappings = Get-AzureSiteRecoveryStorageMapping -PrimaryServer $servers[0] -RecoveryServer $servers[1]
270279
Assert-True { $storageMappings.Count -eq 0 }
271280

272281
# Create StorageMapping
273-
$job = New-AzureSiteRecoveryStorageMapping -PrimaryStorage $storages[0] -RecoveryStorage $storages[1]
282+
$job = New-AzureSiteRecoveryStorageMapping -PrimaryStorage $storagesOnPrimary[0] -RecoveryStorage $storagesOnRecovery[0]
274283
WaitForJobCompletion -JobId $job.ID
275284

276285
# Enumerate StorageMappings
277-
$storageMappings = Get-AzureSiteRecoveryStorageMapping -PrimaryServer $servers[0] -RecoveryServer $servers[0]
286+
$storageMappings = Get-AzureSiteRecoveryStorageMapping -PrimaryServer $servers[0] -RecoveryServer $servers[1]
278287
Assert-NotNull($storageMappings)
279288
Assert-True { $storageMappings.Count -eq 1 }
280289
Assert-NotNull($storageMappings[0].PrimaryServerId)
@@ -296,7 +305,7 @@ function Test-StorageUnMapping
296305

297306
# Enumerate Servers
298307
$servers = Get-AzureSiteRecoveryServer
299-
Assert-True { $servers.Count -gt 0 }
308+
Assert-True { $servers.Count -gt 1 }
300309
Assert-NotNull($servers)
301310
foreach($server in $servers)
302311
{
@@ -305,7 +314,7 @@ function Test-StorageUnMapping
305314
}
306315

307316
# Enumerate StorageMappings
308-
$storageMappings = Get-AzureSiteRecoveryStorageMapping -PrimaryServer $servers[0] -RecoveryServer $servers[0]
317+
$storageMappings = Get-AzureSiteRecoveryStorageMapping -PrimaryServer $servers[0] -RecoveryServer $servers[1]
309318
Assert-NotNull($storageMappings)
310319
Assert-True { $storageMappings.Count -eq 1 }
311320
Assert-NotNull($storageMappings[0].PrimaryServerId)
@@ -318,7 +327,7 @@ function Test-StorageUnMapping
318327
WaitForJobCompletion -JobId $job.ID
319328

320329
# Enumerate StorageMappings
321-
$storageMappings = Get-AzureSiteRecoveryStorageMapping -PrimaryServer $servers[0] -RecoveryServer $servers[0]
330+
$storageMappings = Get-AzureSiteRecoveryStorageMapping -PrimaryServer $servers[0] -RecoveryServer $servers[1]
322331
Assert-True { $storageMappings.Count -eq 0 }
323332
}
324333

@@ -335,7 +344,7 @@ function Test-NetworkMapping
335344

336345
# Enumerate Servers
337346
$servers = Get-AzureSiteRecoveryServer
338-
Assert-True { $servers.Count -gt 0 }
347+
Assert-True { $servers.Count -gt 1 }
339348
Assert-NotNull($servers)
340349
foreach($server in $servers)
341350
{
@@ -344,25 +353,34 @@ function Test-NetworkMapping
344353
}
345354

346355
# Enumerate Networks
347-
$networks = Get-AzureSiteRecoveryNetwork -Server $servers[0]
348-
Assert-NotNull($networks)
349-
Assert-True { $networks.Count -gt 0 }
350-
foreach($network in $networks)
356+
$networksOnPrimary = Get-AzureSiteRecoveryNetwork -Server $servers[0]
357+
Assert-NotNull($networksOnPrimary)
358+
Assert-True { $networksOnPrimary.Count -gt 0 }
359+
foreach($network in $networksOnPrimary)
360+
{
361+
Assert-NotNull($network.Name)
362+
Assert-NotNull($network.ID)
363+
}
364+
365+
$networksOnRecovery = Get-AzureSiteRecoveryNetwork -Server $servers[1]
366+
Assert-NotNull($networksOnRecovery)
367+
Assert-True { $networksOnRecovery.Count -gt 0 }
368+
foreach($network in $networksOnRecovery)
351369
{
352370
Assert-NotNull($network.Name)
353371
Assert-NotNull($network.ID)
354372
}
355373

356374
# Enumerate NetworkMappings
357-
$networkMappings = Get-AzureSiteRecoveryNetworkMapping -PrimaryServer $servers[0] -RecoveryServer $servers[0]
375+
$networkMappings = Get-AzureSiteRecoveryNetworkMapping -PrimaryServer $servers[0] -RecoveryServer $servers[1]
358376
Assert-True { $networkMappings.Count -eq 0 }
359377

360378
# Create NetworkMapping
361-
$job = New-AzureSiteRecoveryNetworkMapping -PrimaryNetwork $networks[0] -RecoveryNetwork $networks[1]
379+
$job = New-AzureSiteRecoveryNetworkMapping -PrimaryNetwork $networksOnPrimary[0] -RecoveryNetwork $networksOnRecovery[0]
362380
WaitForJobCompletion -JobId $job.ID
363381

364382
# Enumerate NetworkMappings
365-
$networkMappings = Get-AzureSiteRecoveryNetworkMapping -PrimaryServer $servers[0] -RecoveryServer $servers[0]
383+
$networkMappings = Get-AzureSiteRecoveryNetworkMapping -PrimaryServer $servers[0] -RecoveryServer $servers[1]
366384
Assert-NotNull($networkMappings)
367385
Assert-True { $networkMappings.Count -eq 1 }
368386
Assert-NotNull($networkMappings[0].PrimaryServerId)
@@ -450,7 +468,7 @@ function Test-NetworkUnMapping
450468

451469
# Enumerate Servers
452470
$servers = Get-AzureSiteRecoveryServer
453-
Assert-True { $servers.Count -gt 0 }
471+
Assert-True { $servers.Count -gt 1 }
454472
Assert-NotNull($servers)
455473
foreach($server in $servers)
456474
{
@@ -459,7 +477,7 @@ function Test-NetworkUnMapping
459477
}
460478

461479
# Enumerate NetworkMappings
462-
$networkMappings = Get-AzureSiteRecoveryNetworkMapping -PrimaryServer $servers[0] -RecoveryServer $servers[0]
480+
$networkMappings = Get-AzureSiteRecoveryNetworkMapping -PrimaryServer $servers[0] -RecoveryServer $servers[1]
463481
Assert-NotNull($networkMappings)
464482
Assert-True { $networkMappings.Count -eq 1 }
465483
Assert-NotNull($networkMappings[0].PrimaryServerId)
@@ -474,7 +492,7 @@ function Test-NetworkUnMapping
474492
WaitForJobCompletion -JobId $job.ID
475493

476494
# Enumerate NetworkMappings
477-
$networkMappings = Get-AzureSiteRecoveryNetworkMapping -PrimaryServer $servers[0] -RecoveryServer $servers[0]
495+
$networkMappings = Get-AzureSiteRecoveryNetworkMapping -PrimaryServer $servers[0] -RecoveryServer $servers[1]
478496
Assert-True { $networkMappings.Count -eq 0 }
479497
}
480498

@@ -1142,7 +1160,7 @@ function Test-EnableProtection
11421160
# Validate_EnableProtection_WaitForCanFailover
11431161
if ($Validate_EnableProtection_WaitForCanFailover -eq $true)
11441162
{
1145-
WaitForCanFailover $protectionEntity.ProtectionContainerId $protectionEntity.ID
1163+
WaitForCanFailover $protectionEntity.ProtectionContainerId $protectionEntity.ID 600
11461164
}
11471165

11481166
return;
@@ -1353,20 +1371,24 @@ function Test-SanE2E
13531371
<#
13541372
.SYNOPSIS
13551373
Recovery Services Enable Protection Tests
1374+
Wait for CanFailover state
1375+
Usage:
1376+
WaitForCanFailover pcId peId
1377+
WaitForCanFailover pcId peId secondsToWait
13561378
#>
13571379
function WaitForCanFailover
13581380
{
1359-
param([string] $pcId, [string] $peId)
1360-
$count = 20
1381+
param([string] $pcId, [string] $peId, [Int] $NumOfSecondsToWait = 120)
1382+
1383+
$timeElapse = 0;
1384+
$interval = 5;
13611385
do
13621386
{
1363-
Start-Sleep 5
1387+
Start-Sleep $interval
1388+
$timeElapse = $timeElapse + $interval
13641389
$pes = Get-AzureSiteRecoveryProtectionEntity -ProtectionContainerId $pcId;
13651390

1366-
$count = $count -1;
1367-
1368-
Assert-True { $count -gt 0 } "Job did not reached desired state within 5*$count seconds."
1369-
1391+
Assert-True { $timeElapse -lt $NumOfSecondsToWait } "Job did not reached desired state within $NumOfSecondsToWait seconds."
13701392
} while(-not ($pes[0].CanFailover -eq $true))
13711393
}
13721394

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Service/CreateAzureSiteRecoveryProtectionProfileObject.cs

Lines changed: 75 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System.Management.Automation;
1818
using Microsoft.Azure.Commands.RecoveryServices.SiteRecovery;
1919
using Microsoft.Azure.Portal.RecoveryServices.Models.Common;
20+
using Microsoft.WindowsAzure.Commands.Common.Properties;
2021
using Microsoft.WindowsAzure.Management.SiteRecovery.Models;
2122
using Microsoft.WindowsAzure.Management.Storage.Models;
2223

@@ -29,8 +30,20 @@ namespace Microsoft.Azure.Commands.RecoveryServices
2930
[OutputType(typeof(ASRProtectionProfile))]
3031
public class CreateAzureSiteRecoveryProtectionProfileObject : RecoveryServicesCmdletBase
3132
{
33+
/// <summary>
34+
/// Holds Name (if passed) of the protection profile object.
35+
/// </summary>
36+
private string targetName = string.Empty;
37+
3238
#region Parameters
3339

40+
/// <summary>
41+
/// Gets or sets Name of the Protection Profile.
42+
/// </summary>
43+
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterprise)]
44+
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure)]
45+
public string Name { get; set; }
46+
3447
/// <summary>
3548
/// Gets or sets Replication Provider of the Protection Profile.
3649
/// </summary>
@@ -68,13 +81,6 @@ public class CreateAzureSiteRecoveryProtectionProfileObject : RecoveryServicesCm
6881
[ValidateNotNullOrEmpty]
6982
public string RecoveryAzureStorageAccount { get; set; }
7083

71-
/// <summary>
72-
/// Gets or sets a value indicating whether stored data needs to be encrypted.
73-
/// </summary>
74-
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure)]
75-
[DefaultValue(false)]
76-
public SwitchParameter EncryptStoredData { get; set; }
77-
7884
/// <summary>
7985
/// Gets or sets Replication Frequency of the Protection Profile in seconds.
8086
/// </summary>
@@ -173,6 +179,18 @@ public class CreateAzureSiteRecoveryProtectionProfileObject : RecoveryServicesCm
173179
[ValidateNotNullOrEmpty]
174180
public string RecoveryArrayId { get; set; }
175181

182+
/// <summary>
183+
/// Gets or sets switch parameter. On passing, command does not ask for confirmation.
184+
/// </summary>
185+
[Parameter(Mandatory = false)]
186+
public SwitchParameter Force { get; set; }
187+
188+
/// <summary>
189+
/// Gets or sets a value indicating - should the VM's data in azure storage be encrypted?
190+
/// </summary>
191+
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure)]
192+
[DefaultValue(false)]
193+
public SwitchParameter EncryptStoredData { get; set; }
176194
#endregion Parameters
177195

178196
/// <summary>
@@ -216,26 +234,66 @@ protected override void StopProcessing()
216234
/// </summary>
217235
private void EnterpriseToAzureProtectionProfileObject()
218236
{
219-
if (string.Compare(this.ReplicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase) != 0)
237+
if (string.Compare(
238+
this.ReplicationProvider,
239+
Constants.HyperVReplicaAzure,
240+
StringComparison.OrdinalIgnoreCase) != 0)
220241
{
221242
throw new InvalidOperationException(
222243
string.Format(
223244
Properties.Resources.IncorrectReplicationProvider,
224245
this.ReplicationProvider));
225246
}
226247

227-
// Verify whether the subscription is associated with the account or not.
228-
PSRecoveryServicesClientHelper.ValidateSubscriptionAccountAssociation(this.RecoveryAzureSubscription);
229-
230248
// Verify whether the storage account is associated with the subscription or not.
231-
//// PSRecoveryServicesClientHelper.ValidateStorageAccountAssociation(this.RecoveryAzureStorageAccount);
249+
bool validationSuccessful;
250+
bool locationValid;
251+
RecoveryServicesClient.ValidateStorageAccountAssociation(
252+
this.RecoveryAzureSubscription,
253+
this.RecoveryAzureStorageAccount,
254+
this.GetCurrentValutLocation(),
255+
out validationSuccessful,
256+
out locationValid);
257+
258+
if (!validationSuccessful)
259+
{
260+
this.WriteWarning(string.Format(Properties.Resources.StorageAccountValidationUnsuccessful));
261+
}
262+
263+
if (validationSuccessful && !locationValid)
264+
{
265+
this.WriteWarning(string.Format(Properties.Resources.StorageIsNotInTheSameLocationAsVault));
266+
}
232267

233-
PSRecoveryServicesClientHelper.ValidateReplicationStartTime(this.ReplicationStartTime);
268+
if (!validationSuccessful || !locationValid)
269+
{
270+
this.ConfirmAction(
271+
this.Force.IsPresent,
272+
string.Format(Properties.Resources.ValidationUnsuccessfulWarning, this.targetName),
273+
string.Format(Properties.Resources.NewProtectionProfileObjectWhatIfMessage),
274+
this.targetName,
275+
new Action(this.ProceedToCreateProtectionProfileObject));
276+
}
277+
else
278+
{
279+
this.ProceedToCreateProtectionProfileObject();
280+
}
281+
}
282+
283+
/// <summary>
284+
/// Proceeds to Create an E2A Protection Profile Object after all the validations are done.
285+
/// </summary>
286+
private void ProceedToCreateProtectionProfileObject()
287+
{
288+
PSRecoveryServicesClient.ValidateReplicationStartTime(this.ReplicationStartTime);
234289

235-
ushort replicationFrequencyInSeconds = PSRecoveryServicesClientHelper.ConvertReplicationFrequencyToUshort(this.ReplicationFrequencyInSeconds);
290+
ushort replicationFrequencyInSeconds =
291+
PSRecoveryServicesClient.ConvertReplicationFrequencyToUshort(
292+
this.ReplicationFrequencyInSeconds);
236293

237294
ASRProtectionProfile protectionProfile = new ASRProtectionProfile()
238295
{
296+
Name = this.Name,
239297
ReplicationProvider = this.ReplicationProvider,
240298
HyperVReplicaAzureProviderSettingsObject = new HyperVReplicaAzureProviderSettings()
241299
{
@@ -266,12 +324,13 @@ private void EnterpriseToEnterpriseProtectionProfileObject()
266324
this.ReplicationProvider));
267325
}
268326

269-
PSRecoveryServicesClientHelper.ValidateReplicationStartTime(this.ReplicationStartTime);
327+
PSRecoveryServicesClient.ValidateReplicationStartTime(this.ReplicationStartTime);
270328

271-
ushort replicationFrequencyInSeconds = PSRecoveryServicesClientHelper.ConvertReplicationFrequencyToUshort(this.ReplicationFrequencyInSeconds);
329+
ushort replicationFrequencyInSeconds = PSRecoveryServicesClient.ConvertReplicationFrequencyToUshort(this.ReplicationFrequencyInSeconds);
272330

273331
ASRProtectionProfile protectionProfile = new ASRProtectionProfile()
274332
{
333+
Name = this.Name,
275334
ReplicationProvider = this.ReplicationProvider,
276335
HyperVReplicaAzureProviderSettingsObject = null,
277336
HyperVReplicaProviderSettingsObject = new HyperVReplicaProviderSettings()

0 commit comments

Comments
 (0)