Skip to content

Commit ed375a3

Browse files
committed
Merge pull request #29 from AsrOneSdk/sanjkuma-dev
Enable DR bug fixes.
2 parents 44de337 + 43fbacf commit ed375a3

File tree

4 files changed

+141
-141
lines changed

4 files changed

+141
-141
lines changed

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

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
$Validate_EnableProtection_JobSucceeded = $true;
2020
$Validate_DisableProtection_JobSucceeded = $true;
21+
2122
$Validate_PFO_JobSucceeded = $true;
2223
$Validate_Commit_PFO_JobSucceeded = $true;
2324
$Validate_Commit_Failback_JobSucceeded = $true;
@@ -33,6 +34,7 @@ $Validate_PFOFailbackRP_JobSucceeded = $true;
3334
$Validate_ProfileDissociation_JobSucceeded = $true;
3435
$Validate_ProfileAssociation_JobSucceeded = $true;
3536

37+
#Test-EnableProtection 'E:\d\E2E_SKVault_Wednesday,January28,2015.VaultCredentials'
3638

3739
<#
3840
.SYNOPSIS
@@ -79,6 +81,7 @@ function Test-E2E_DeleteAndDissociate
7981
if ($Validate_ProfileDissociation_JobSucceeded -eq $true)
8082
{
8183
WaitForJobCompletion -JobId $job.ID
84+
$job = Get-AzureSiteRecoveryJob -Id $job.ID
8285
Assert-True { $job.State -eq "Succeeded" }
8386
}
8487

@@ -90,8 +93,7 @@ function Test-E2E_DeleteAndDissociate
9093
}
9194
}
9295

93-
throw("No PC found for E2E_DeleteAndDissociate");
94-
96+
Assert-NotNull($job) "No PC found for E2E_DeleteAndDissociate"
9597
}
9698

9799

@@ -133,14 +135,15 @@ function Test-E2E_CreateAndAssociate
133135
if ($Validate_ProfileAssociation_JobSucceeded -eq $true)
134136
{
135137
WaitForJobCompletion -JobId $job.ID
138+
$job = Get-AzureSiteRecoveryJob -Id $job.ID
136139
Assert-True { $job.State -eq "Succeeded" }
137140
}
138141

139142
return;
140143
}
141144
}
142145

143-
throw("No PC found for E2E_CreateAndAssociate");
146+
Assert-NotNull($job) "No PC found for E2E_CreateAndAssociate"
144147
}
145148

146149
<#
@@ -565,7 +568,7 @@ function Test-Failback
565568
}
566569
}
567570

568-
throw("No VM found for failback");
571+
Assert-NotNull($job) "No VM found for failback"
569572
}
570573

571574

@@ -614,7 +617,7 @@ function Test-RRAfterFailback
614617
}
615618
}
616619

617-
throw("No VM found for RRAfterFailback");
620+
Assert-NotNull($job) "No VM found for RRAfterFailback";
618621
}
619622

620623

@@ -658,6 +661,12 @@ function Test-RRAfterFailover
658661
Assert-True { $job.State -eq "Succeeded" }
659662
}
660663

664+
# Validate_EnableProtection_WaitForCanFailover
665+
if ($Validate_EnableProtection_WaitForCanFailover -eq $true)
666+
{
667+
WaitForCanFailover $protectionEntity.ProtectionContainerId $protectionEntity.ID
668+
}
669+
661670
return;
662671
}
663672
}
@@ -712,7 +721,7 @@ function Test-CommitPFO
712721
}
713722
}
714723

715-
throw("No VM found for Commit_PFO");
724+
Assert-NotNull($job) "No VM found for Commit_PFO"
716725
}
717726

718727

@@ -761,7 +770,7 @@ function Test-PFO
761770
}
762771
}
763772

764-
throw("No VM found for PFO");
773+
Assert-NotNull($job) "No VM found for PFO"
765774
}
766775

767776
<#
@@ -1033,7 +1042,7 @@ function Test-UFO
10331042
}
10341043
}
10351044

1036-
throw("No VM found for UFO");
1045+
Assert-NotNull($job) "No VM found for UFO"
10371046
}
10381047

10391048

@@ -1090,7 +1099,7 @@ function Test-TFO
10901099
}
10911100
}
10921101

1093-
throw("No VM found for TFO");
1102+
Assert-NotNull($job) "No VM found for TFO"
10941103
}
10951104

10961105
<#
@@ -1124,18 +1133,20 @@ function Test-EnableProtection
11241133
if ($protectionEntity.Protected -eq $false)
11251134
{
11261135
$job = Set-AzureSiteRecoveryProtectionEntity -ProtectionEntity $protectionEntity -Protection "Enable" -Force -ProtectionProfile $protectionContainer.AvailableProtectionProfiles[0] -WaitForCompletion
1136+
Assert-NotNull($job.State)
1137+
Assert-NotNull($job.ID)
11271138

11281139
# Validate_EnableProtection_JobSucceeded
11291140
if ($Validate_EnableProtection_JobSucceeded -eq $true)
11301141
{
11311142
$job = Get-AzureSiteRecoveryJob -Id $job.ID
1132-
Assert-True { $job.State -eq "Succeeded" }
1143+
Assert-True { $job.State -eq "Succeeded" } "Job state is not not Succeeded. $job.State "
11331144
}
11341145

11351146
# Validate_EnableProtection_WaitForCanFailover
11361147
if ($Validate_EnableProtection_WaitForCanFailover -eq $true)
11371148
{
1138-
WaitForCanFailover $protectionEntity.Id
1149+
WaitForCanFailover $protectionEntity.ProtectionContainerId $protectionEntity.ID
11391150
}
11401151

11411152
return;
@@ -1144,7 +1155,7 @@ function Test-EnableProtection
11441155
}
11451156
}
11461157

1147-
throw("No VM found for Enable Protection");
1158+
Assert-NotNull($job) "No VM found for Enable Protection"
11481159
}
11491160

11501161
<#
@@ -1175,16 +1186,18 @@ function Test-DisableProtection
11751186
{
11761187
Assert-NotNull($protectionEntity.Name)
11771188
Assert-NotNull($protectionEntity.ID)
1178-
Write-Host "Checking PE"
1189+
Write-Output "Checking PE"
11791190
$protectionEntity
11801191
if ($protectionEntity.Protected -eq $true)
11811192
{
1182-
Write-Host "Disabling protection for PE: " + $protectionEntity.Name + " (" + $protectionEntity.ID + ")"
1193+
Write-Output "Disabling protection for PE: " + $protectionEntity.Name + " (" + $protectionEntity.ID + ")"
11831194
$job = Set-AzureSiteRecoveryProtectionEntity -ProtectionEntity $protectionEntity -Protection "Disable" -Force -WaitForCompletion
1184-
1195+
Assert-NotNull($job);
1196+
11851197
# Validate_DisableProtection_JobSucceeded
11861198
if ($Validate_DisableProtection_JobSucceeded -eq $true)
11871199
{
1200+
$job = Get-AzureSiteRecoveryJob -Id $job.ID
11881201
Assert-True { $job.State -eq "Succeeded" }
11891202
}
11901203

@@ -1194,7 +1207,7 @@ function Test-DisableProtection
11941207
}
11951208
}
11961209

1197-
throw("No VM found for Disable Protection");
1210+
Assert-NotNull($job) "No VM found for Disable Protection"
11981211
}
11991212

12001213
<#
@@ -1203,23 +1216,18 @@ Recovery Services Enable Protection Tests
12031216
#>
12041217
function WaitForCanFailover
12051218
{
1206-
param([string] $peId)
1219+
param([string] $pcId, [string] $peId)
12071220
$count = 20
12081221
do
12091222
{
12101223
Start-Sleep 5
1211-
$pe = Get-AzureSiteRecoveryProtectionEntity -Id peId;
1212-
if ($count -ne 0)
1213-
{
1214-
$count = $count -1;
1215-
}
1216-
else
1217-
{
1218-
throw("WaitForCanFailover failed.");
1219-
return;
1220-
}
1224+
$pes = Get-AzureSiteRecoveryProtectionEntity -ProtectionContainerId $pcId;
1225+
1226+
$count = $count -1;
1227+
1228+
Assert-True { $count -gt 0 } "Job did not reached desired state within 5*$count seconds."
12211229

1222-
} while( -not ($pe.CanFailover -eq $true))
1230+
} while(-not ($pes[0].CanFailover -eq $true))
12231231
}
12241232

12251233
<#

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,19 +165,29 @@ public override void ExecuteCmdlet()
165165
{
166166
if (this.Protection == Constants.EnableProtection)
167167
{
168+
string profileId = string.Empty;
168169
var input = new EnableProtectionInput();
169170

171+
// Get the replciation provider from profile object otherwise assume its E2E.
172+
// Let the call go without profileId set.
173+
string replicationProvider = Constants.HyperVReplica;
174+
if (this.ProtectionProfile != null)
175+
{
176+
profileId = this.ProtectionProfile.ID;
177+
replicationProvider = this.ProtectionProfile.ReplicationProvider;
178+
}
179+
170180
if (this.ProtectionEntity == null)
171181
{
172182
var pe = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity(
173183
this.ProtectionContainerId,
174184
this.Id);
175185
this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity);
176186

177-
this.ValidateUsageById(this.ProtectionEntity.ReplicationProvider);
187+
this.ValidateUsageById(replicationProvider);
178188
}
179189

180-
if (this.ProtectionProfile.ReplicationProvider == Constants.HyperVReplicaAzure)
190+
if (replicationProvider == Constants.HyperVReplicaAzure)
181191
{
182192
input.ProtectionProfileId = this.ProtectionProfile.ID;
183193
AzureEnableProtectionInput azureInput = new AzureEnableProtectionInput();
@@ -208,10 +218,14 @@ public override void ExecuteCmdlet()
208218

209219
input.ReplicationProviderInput = DataContractUtils.Serialize<AzureEnableProtectionInput>(azureInput);
210220
}
221+
else if (string.IsNullOrWhiteSpace(profileId))
222+
{
223+
input = null;
224+
}
211225
else
212226
{
213227
input.ReplicationProviderInput = string.Empty;
214-
input.ProtectionProfileId = this.ProtectionProfile.ID;
228+
input.ProtectionProfileId = profileId;
215229
}
216230

217231
this.jobResponse =

0 commit comments

Comments
 (0)