Skip to content

Commit a510e5e

Browse files
Taking review comments. Adding extensive covering end to end scenario.
1 parent 25e4dd5 commit a510e5e

File tree

8 files changed

+3752
-187
lines changed

8 files changed

+3752
-187
lines changed

src/ResourceManager/SiteRecovery/Commands.SiteRecovery.Test/Commands.SiteRecovery.Test.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
</ItemGroup>
131131
<ItemGroup>
132132
<Compile Include="Properties\AssemblyInfo.cs" />
133+
<Compile Include="ScenarioTests\Constants.cs" />
133134
<Compile Include="ScenarioTests\SiteRecoveryTests.cs" />
134135
<Compile Include="ScenarioTests\SiteRecoveryTestsBase.cs" />
135136
</ItemGroup>
@@ -147,6 +148,9 @@
147148
<None Include="SessionRecords\Microsoft.Azure.Commands.SiteRecovery.Test.ScenarioTests.SiteRecoveryTests\FabricTests.json">
148149
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
149150
</None>
151+
<None Include="SessionRecords\Microsoft.Azure.Commands.SiteRecovery.Test.ScenarioTests.SiteRecoveryTests\NewModelE2ETest.json">
152+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
153+
</None>
150154
<None Include="SessionRecords\Microsoft.Azure.Commands.SiteRecovery.Test.ScenarioTests.SiteRecoveryTests\TestAssociateProfile.json">
151155
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
152156
</None>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
16+
using System;
17+
using System.Collections.Generic;
18+
19+
namespace Microsoft.Azure.Commands.SiteRecovery.Test.ScenarioTests
20+
{
21+
public class Constants
22+
{
23+
public const string Default = "Default";
24+
public const string NewModel = "NewModel";
25+
}
26+
}

src/ResourceManager/SiteRecovery/Commands.SiteRecovery.Test/ScenarioTests/SiteRecoveryTests.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,84 +30,91 @@ public SiteRecoveryTests(ITestOutputHelper output)
3030
[Trait(Category.AcceptanceType, Category.CheckIn)]
3131
public void EnumerationTests()
3232
{
33-
this.RunPowerShellTest("Test-SiteRecoveryEnumerationTests -vaultSettingsFilePath \"" + vaultSettingsFilePath + "\"");
33+
this.RunPowerShellTest(Constants.Default, "Test-SiteRecoveryEnumerationTests -vaultSettingsFilePath \"" + vaultSettingsFilePath + "\"");
3434
}
3535

3636
[Fact]
3737
[Trait(Category.AcceptanceType, Category.CheckIn)]
3838
public void TestCreateProfile()
3939
{
40-
this.RunPowerShellTest("Test-SiteRecoveryCreateProfile -vaultSettingsFilePath \"" + vaultSettingsFilePath + "\"");
40+
this.RunPowerShellTest(Constants.Default, "Test-SiteRecoveryCreateProfile -vaultSettingsFilePath \"" + vaultSettingsFilePath + "\"");
4141
}
4242

4343
[Fact]
4444
[Trait(Category.AcceptanceType, Category.CheckIn)]
4545
public void TestDeleteProfile()
4646
{
47-
this.RunPowerShellTest("Test-SiteRecoveryDeleteProfile -vaultSettingsFilePath \"" + vaultSettingsFilePath + "\"");
47+
this.RunPowerShellTest(Constants.Default, "Test-SiteRecoveryDeleteProfile -vaultSettingsFilePath \"" + vaultSettingsFilePath + "\"");
4848
}
4949

5050
[Fact]
5151
[Trait(Category.AcceptanceType, Category.CheckIn)]
5252
public void TestAssociateProfile()
5353
{
54-
this.RunPowerShellTest("Test-SiteRecoveryAssociateProfile -vaultSettingsFilePath \"" + vaultSettingsFilePath + "\"");
54+
this.RunPowerShellTest(Constants.Default, "Test-SiteRecoveryAssociateProfile -vaultSettingsFilePath \"" + vaultSettingsFilePath + "\"");
5555
}
5656

5757
[Fact]
5858
[Trait(Category.AcceptanceType, Category.CheckIn)]
5959
public void TestDissociateProfile()
6060
{
61-
this.RunPowerShellTest("Test-SiteRecoveryDissociateProfile -vaultSettingsFilePath \"" + vaultSettingsFilePath + "\"");
61+
this.RunPowerShellTest(Constants.Default, "Test-SiteRecoveryDissociateProfile -vaultSettingsFilePath \"" + vaultSettingsFilePath + "\"");
6262
}
6363

6464
[Fact]
6565
[Trait(Category.AcceptanceType, Category.CheckIn)]
6666
public void TestEnableDR()
6767
{
68-
this.RunPowerShellTest("Test-SiteRecoveryEnableDR -vaultSettingsFilePath \"" + vaultSettingsFilePath + "\"");
68+
this.RunPowerShellTest(Constants.Default, "Test-SiteRecoveryEnableDR -vaultSettingsFilePath \"" + vaultSettingsFilePath + "\"");
6969
}
7070

7171
[Fact]
7272
[Trait(Category.AcceptanceType, Category.CheckIn)]
7373
public void TestDisableDR()
7474
{
75-
this.RunPowerShellTest("Test-SiteRecoveryDisableDR -vaultSettingsFilePath \"" + vaultSettingsFilePath + "\"");
75+
this.RunPowerShellTest(Constants.Default, "Test-SiteRecoveryDisableDR -vaultSettingsFilePath \"" + vaultSettingsFilePath + "\"");
7676
}
7777

7878
[Fact]
7979
[Trait(Category.AcceptanceType, Category.CheckIn)]
8080
public void TestCreateRP()
8181
{
82-
this.RunPowerShellTest("Test-SiteRecoveryCreateRecoveryPlan -vaultSettingsFilePath \"" + vaultSettingsFilePath + "\"");
82+
this.RunPowerShellTest(Constants.Default, "Test-SiteRecoveryCreateRecoveryPlan -vaultSettingsFilePath \"" + vaultSettingsFilePath + "\"");
8383
}
8484

8585
[Fact]
8686
[Trait(Category.AcceptanceType, Category.CheckIn)]
8787
public void TestEnumerateRP()
8888
{
89-
this.RunPowerShellTest("Test-SiteRecoveryEnumerateRecoveryPlan -vaultSettingsFilePath \"" + vaultSettingsFilePath + "\"");
89+
this.RunPowerShellTest(Constants.Default, "Test-SiteRecoveryEnumerateRecoveryPlan -vaultSettingsFilePath \"" + vaultSettingsFilePath + "\"");
9090
}
9191

9292
[Fact]
9393
[Trait(Category.AcceptanceType, Category.CheckIn)]
9494
public void TestRemoveRP()
9595
{
96-
this.RunPowerShellTest("Test-SiteRecoveryRemoveRecoveryPlan -vaultSettingsFilePath \"" + vaultSettingsFilePath + "\"");
96+
this.RunPowerShellTest(Constants.Default, "Test-SiteRecoveryRemoveRecoveryPlan -vaultSettingsFilePath \"" + vaultSettingsFilePath + "\"");
9797
}
9898

9999
[Fact]
100100
[Trait(Category.AcceptanceType, Category.CheckIn)]
101101
public void VaultCRUDTests()
102102
{
103-
this.RunPowerShellTest("Test-SiteRecoveryVaultCRUDTests");
103+
this.RunPowerShellTest(Constants.Default, "Test-SiteRecoveryVaultCRUDTests");
104104
}
105105

106106
[Fact]
107107
[Trait(Category.AcceptanceType, Category.CheckIn)]
108108
public void FabricTests()
109109
{
110-
this.RunPowerShellTest("Test-SiteRecoveryFabricTest");
110+
this.RunPowerShellTest(Constants.NewModel, "Test-SiteRecoveryFabricTest");
111+
}
112+
113+
[Fact]
114+
[Trait(Category.AcceptanceType, Category.CheckIn)]
115+
public void NewModelE2ETest()
116+
{
117+
this.RunPowerShellTest(Constants.NewModel, "Test-SiteRecoveryNewModelE2ETest");
111118
}
112119
}
113120
}

src/ResourceManager/SiteRecovery/Commands.SiteRecovery.Test/ScenarioTests/SiteRecoveryTests.ps1

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,3 +403,91 @@ function Test-SiteRecoveryFabricTest
403403
$fabric = Get-AzureRmSiteRecoveryFabric | Where-Object {$_.Name -eq "ReleaseFabric"}
404404
Assert-Null($fabric)
405405
}
406+
407+
408+
<#
409+
.SYNOPSIS
410+
Site Recovery New model End to End
411+
#>
412+
function Test-SiteRecoveryNewModelE2ETest
413+
{
414+
$JobQueryWaitTimeInSeconds = 30
415+
416+
# Enumerate vaults and set Azure Site Recovery Vault Settings
417+
$vault = Get-AzureRmSiteRecoveryVault -ResourceGroupName ReleaseResourceGroup -Name ReleaseVault
418+
Assert-NotNull($vault)
419+
Assert-True { $vault.Count -eq 1 }
420+
Assert-NotNull($vault.Name)
421+
Assert-NotNull($vault.ID)
422+
Set-AzureRmSiteRecoveryVaultSettings -ASRVault $vault
423+
424+
# Enumerate Fabrics
425+
$fabrics = Get-AzureRmSiteRecoveryFabric
426+
Assert-True { $fabrics.Count -gt 0 }
427+
Assert-NotNull($fabrics)
428+
foreach($fabric in $fabrics)
429+
{
430+
Assert-NotNull($fabrics.Name)
431+
Assert-NotNull($fabrics.ID)
432+
}
433+
434+
# Enumerate RSPs
435+
$rsps = Get-AzureRmSiteRecoveryFabric | Get-AzureRmSiteRecoveryServicesProvider
436+
Assert-True { $rsps.Count -gt 0 }
437+
Assert-NotNull($rsps)
438+
foreach($rsp in $rsps)
439+
{
440+
Assert-NotNull($rsp.Name)
441+
}
442+
443+
$StorageAccountID = "/subscriptions/19b823e2-d1f3-4805-93d7-401c5d8230d5/resourceGroups/releaseresourcegroup/providers/Microsoft.Storage/storageAccounts/releasestorageav"
444+
445+
# Create Policy
446+
$currentJob = New-AzureRmSiteRecoveryPolicy -Name "PP1" -ReplicationProvider HyperVReplicaAzure -ReplicationFrequencyInSeconds 30 -RecoveryPoints 1 -ApplicationConsistentSnapshotFrequencyInHours 0 -Encryption Disable -RecoveryAzureStorageAccountId $StorageAccountID
447+
$ProtectionProfile = Get-AzureRMSiteRecoveryPolicy -Name "PP1"
448+
Assert-NotNull($ProtectionProfile)
449+
Assert-NotNull($ProtectionProfile.Name)
450+
451+
# Get conatiners
452+
$ProtectionContainers = Get-AzureRmSiteRecoveryFabric | Get-AzureRmSiteRecoveryProtectionContainer
453+
$PrimaryContainer = $ProtectionContainers | where { $_.FriendlyName -eq "hark-123" }
454+
Assert-NotNull($PrimaryContainer)
455+
Assert-NotNull($PrimaryContainer.Name)
456+
457+
# Create new Conatiner mapping
458+
$currentJob = New-AzureRmSiteRecoveryProtectionContainerMapping -Name $("hark123" + "PP1") -Policy $ProtectionProfile -PrimaryProtectionContainer $PrimaryContainer
459+
460+
# Get container mapping
461+
$ProtectionContainerMapping = Get-AzureRmSiteRecoveryProtectionContainerMapping -Name $("hark123" + "PP1") -ProtectionContainer $PrimaryContainer
462+
Assert-NotNull($ProtectionContainerMapping)
463+
Assert-NotNull($ProtectionContainerMapping.Name)
464+
465+
# Get protectable item
466+
$protectable = Get-AzureRmSiteRecoveryProtectableItem -ProtectionContainer $PrimaryContainer -FriendlyName "vm3"
467+
Assert-NotNull($protectable)
468+
Assert-NotNull($protectable.Name)
469+
470+
# New replication protected item
471+
$currentJob = New-AzureRmSiteRecoveryReplicationProtectedItem -ProtectableItem $protectable -Name $protectable.Name -ProtectionContainerMapping $ProtectionContainerMapping -RecoveryAzureStorageAccountId $StorageAccountID
472+
Assert-NotNull($currentJob)
473+
474+
# Get replication protected item
475+
$protected = Get-AzureRmSiteRecoveryReplicationProtectedItem -ProtectionContainer $PrimaryContainer -Name $protectable.Name
476+
Assert-NotNull($protected)
477+
Assert-NotNull($protected.Name)
478+
479+
# Remove protected item
480+
$currentJob = Remove-AzureRmSiteRecoveryReplicationProtectedItem -ReplicationProtectedItem $protected -Force -Confirm:$false
481+
$protected = Get-AzureRmSiteRecoveryReplicationProtectedItem -ProtectionContainer $PrimaryContainer | Where-Object {$_.Name -eq $protectable.Name}
482+
Assert-Null($protected)
483+
484+
# Remove conatiner mapping
485+
$currentJob = Remove-AzureRmSiteRecoveryProtectionContainerMapping -ProtectionContainerMapping $ProtectionContainerMapping
486+
$ProtectionContainerMapping = Get-AzureRmSiteRecoveryProtectionContainerMapping -ProtectionContainer $PrimaryContainer | Where-Object {$_.Name -eq $("hark123" + "PP1")}
487+
Assert-Null($ProtectionContainerMapping)
488+
489+
# Remove Policy
490+
$currentJob = Remove-AzureRMSiteRecoveryPolicy -Policy $ProtectionProfile
491+
$ProtectionProfile = Get-AzureRMSiteRecoveryPolicy | Where-Object {$_.Name -eq "PP1"}
492+
Assert-Null($ProtectionProfile)
493+
}

src/ResourceManager/SiteRecovery/Commands.SiteRecovery.Test/ScenarioTests/SiteRecoveryTestsBase.cs

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ protected SiteRecoveryTestsBase()
8282
helper = new EnvironmentSetupHelper();
8383
}
8484

85-
protected void SetupManagementClients()
85+
protected void SetupManagementClients(String scenario)
8686
{
87-
RecoveryServicesMgmtClient = GetSiteRecoveryVaultManagementClient();
88-
SiteRecoveryMgmtClient = GetSiteRecoveryManagementClient();
87+
RecoveryServicesMgmtClient = GetSiteRecoveryVaultManagementClient(scenario);
88+
SiteRecoveryMgmtClient = GetSiteRecoveryManagementClient(scenario);
8989

9090
helper.SetupManagementClients(RecoveryServicesMgmtClient, SiteRecoveryMgmtClient);
9191
}
9292

93-
protected void RunPowerShellTest(params string[] scripts)
93+
protected void RunPowerShellTest(String scenario, params string[] scripts)
9494
{
9595
Dictionary<string, string> d = new Dictionary<string, string>();
9696
d.Add("Microsoft.Resources", null);
@@ -104,7 +104,7 @@ protected void RunPowerShellTest(params string[] scripts)
104104
{
105105
context.Start(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2));
106106

107-
SetupManagementClients();
107+
SetupManagementClients(scenario);
108108

109109
helper.SetupEnvironment(AzureModule.AzureResourceManager);
110110
helper.SetupModules(AzureModule.AzureResourceManager,
@@ -115,17 +115,17 @@ protected void RunPowerShellTest(params string[] scripts)
115115
}
116116
}
117117

118-
private SiteRecoveryVaultManagementClient GetSiteRecoveryVaultManagementClient()
118+
private SiteRecoveryVaultManagementClient GetSiteRecoveryVaultManagementClient(String scenario)
119119
{
120-
return GetServiceClient<SiteRecoveryVaultManagementClient>();
120+
return GetServiceClient<SiteRecoveryVaultManagementClient>(scenario);
121121
}
122122

123-
private SiteRecoveryManagementClient GetSiteRecoveryManagementClient()
123+
private SiteRecoveryManagementClient GetSiteRecoveryManagementClient(String scenario)
124124
{
125-
return GetServiceClient<SiteRecoveryManagementClient>();
125+
return GetServiceClient<SiteRecoveryManagementClient>(scenario);
126126
}
127127

128-
public T GetServiceClient<T>() where T : class
128+
public T GetServiceClient<T>(String scenario) where T : class
129129
{
130130
var factory = (TestEnvironmentFactory)new CSMTestEnvironmentFactory();
131131
var testEnvironment = factory.GetTestEnvironment();
@@ -134,6 +134,28 @@ public T GetServiceClient<T>() where T : class
134134
var credentials = new SubscriptionCredentialsAdapter(
135135
testEnvironment.AuthorizationContext.TokenCredentials[TokenAudience.Management],
136136
testEnvironment.SubscriptionId);
137+
var resourceNamespace = "";
138+
var resourceType = "";
139+
var resourceName = "";
140+
var resourceGroupName = "";
141+
142+
switch (scenario)
143+
{
144+
case Constants.NewModel:
145+
resourceNamespace = "Microsoft.SiteRecovery";
146+
resourceType = "SiteRecoveryVault";
147+
resourceName = "ReleaseVault";
148+
resourceGroupName = "ReleaseResourceGroup";
149+
break;
150+
151+
default:
152+
resourceNamespace = "Microsoft.SiteRecoveryBVTD2";
153+
resourceType = "SiteRecoveryVault";
154+
resourceName = asrVaultCreds.ResourceName;
155+
resourceGroupName = asrVaultCreds.ResourceGroupName;
156+
break;
157+
158+
};
137159

138160
if (typeof(T) == typeof(SiteRecoveryVaultManagementClient))
139161
{
@@ -142,16 +164,16 @@ public T GetServiceClient<T>() where T : class
142164
if (testEnvironment.UsesCustomUri())
143165
{
144166
client = new SiteRecoveryVaultManagementClient(
145-
"Microsoft.SiteRecoveryBVTD2",
146-
"SiteRecoveryVault",
167+
resourceNamespace,
168+
resourceType,
147169
credentials,
148170
testEnvironment.BaseUri);
149171
}
150172
else
151173
{
152174
client = new SiteRecoveryVaultManagementClient(
153-
"Microsoft.SiteRecovery",
154-
"SiteRecoveryVault",
175+
resourceNamespace,
176+
resourceType,
155177
credentials);
156178
}
157179
return GetRSMServiceClient<T>(factory, client);
@@ -163,21 +185,21 @@ public T GetServiceClient<T>() where T : class
163185
if (testEnvironment.UsesCustomUri())
164186
{
165187
client = new SiteRecoveryManagementClient(
166-
asrVaultCreds.ResourceName,
167-
asrVaultCreds.ResourceGroupName,
168-
"Microsoft.SiteRecoveryBVTD2",
169-
"SiteRecoveryVault",
188+
resourceName,
189+
resourceGroupName,
190+
resourceNamespace,
191+
resourceType,
170192
credentials,
171193
testEnvironment.BaseUri);
172194
}
173195

174196
else
175197
{
176198
client = new SiteRecoveryManagementClient(
177-
asrVaultCreds.ResourceName,
178-
asrVaultCreds.ResourceGroupName,
179-
"Microsoft.SiteRecovery",
180-
"vaults",
199+
resourceName,
200+
resourceGroupName,
201+
resourceNamespace,
202+
resourceType,
181203
credentials);
182204
}
183205

0 commit comments

Comments
 (0)