Skip to content

Commit 6ca1bef

Browse files
committed
Merge pull request #1862 from franktsa/dev
Adding SQL AutoDR support
2 parents 3c8d306 + 7a1b20c commit 6ca1bef

21 files changed

+3907
-4
lines changed

src/ResourceManager/Sql/Commands.Sql.Test/Commands.Sql.Test.csproj

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
</Reference>
7272
<Reference Include="Microsoft.Azure.Management.Sql">
7373
<SpecificVersion>False</SpecificVersion>
74-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.0.43.0-prerelease\lib\net40\Microsoft.Azure.Management.Sql.dll</HintPath>
74+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.0.44.0-prerelease\lib\net40\Microsoft.Azure.Management.Sql.dll</HintPath>
7575
</Reference>
7676
<Reference Include="Microsoft.Azure.Management.Storage">
7777
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Storage.2.4.0-preview\lib\net40\Microsoft.Azure.Management.Storage.dll</HintPath>
@@ -239,6 +239,7 @@
239239
<Compile Include="ScenarioTests\ElasticPoolCrudTests.cs" />
240240
<Compile Include="ScenarioTests\AuditingTests.cs" />
241241
<Compile Include="ScenarioTests\ServerCrudTests.cs" />
242+
<Compile Include="ScenarioTests\ServerDisasterRecoveryConfigurationTests.cs" />
242243
<Compile Include="ScenarioTests\ServerUpgradeTests.cs" />
243244
<Compile Include="ScenarioTests\SqlEvnSetupHelper.cs" />
244245
<Compile Include="ScenarioTests\SqlTestsBase.cs" />
@@ -253,6 +254,7 @@
253254
<Compile Include="UnitTests\AzureSqlDatabaseIndexRecommendationAttributeTests.cs" />
254255
<Compile Include="UnitTests\AzureSqlCapabilityAttributeTests.cs" />
255256
<Compile Include="UnitTests\AzureSqlServerUpgradeAttributeTests.cs" />
257+
<Compile Include="UnitTests\AzureSqlServerDisasterRecoveryConfigurationTests.cs" />
256258
<Compile Include="UnitTests\AzureSqlServiceTierAdvisorAttributeTests.cs" />
257259
<Compile Include="UnitTests\AzureSqlDatabaseBackupAttributeTests.cs" />
258260
<Compile Include="Utilities\UnitTestHelper.cs" />
@@ -301,6 +303,12 @@
301303
<None Include="ScenarioTests\ServerCrudTests.ps1">
302304
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
303305
</None>
306+
<None Include="ScenarioTests\ServerDisasterRecoveryConfigurationTests.ps1">
307+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
308+
</None>
309+
<None Include="ScenarioTests\ServerDisasterRecoveryConfigurationTests.ps1">
310+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
311+
</None>
304312
<None Include="ScenarioTests\DataMaskingTests.ps1">
305313
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
306314
</None>
@@ -514,6 +522,9 @@
514522
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ServerCrudTests\TestServerUpdate.json">
515523
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
516524
</None>
525+
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ServerDisasterRecoveryConfigurationTests\TestServerDisasterRecoveryConfiguration.json">
526+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
527+
</None>
517528
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ServerUpgradeTests\TestServerUpgradeWithUpgradeHint.json">
518529
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
519530
</None>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
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+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.ScenarioTest.SqlTests;
16+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using Xunit;
18+
19+
namespace Microsoft.Azure.Commands.Sql.Test.ScenarioTests
20+
{
21+
public class ServerDisasterRecoveryConfigurationTests : SqlTestsBase
22+
{
23+
[Fact]
24+
[Trait(Category.AcceptanceType, Category.Sql)]
25+
public void TestServerDisasterRecoveryConfiguration()
26+
{
27+
RunPowerShellTest("Test-ServerDisasterRecoveryConfiguration");
28+
}
29+
}
30+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# ----------------------------------------------------------------------------------
2+
#
3+
# Copyright Microsoft Corporation
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+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ----------------------------------------------------------------------------------
14+
15+
<#
16+
.SYNOPSIS
17+
Tests CRUD on disaster recovery configuration
18+
#>
19+
function Test-ServerDisasterRecoveryConfiguration
20+
{
21+
Test-ServerDisasterRecoveryConfigurationInternal
22+
}
23+
24+
<#
25+
.SYNOPSIS
26+
Tests creating 2 servers, a disaster recovery configuration, failing over, then deleting
27+
#>
28+
function Test-ServerDisasterRecoveryConfigurationInternal ($location1 = "North Europe", $location2 = "Southeast Asia")
29+
{
30+
# Setup
31+
$rg1 = Create-ResourceGroupForTest $location1
32+
$rg2 = Create-ResourceGroupForTest $location2
33+
34+
try
35+
{
36+
$server1 = Create-ServerForTest $rg1 "12.0" $location1
37+
$server2 = Create-ServerForTest $rg2 "12.0" $location2
38+
$failoverPolicy = "Off"
39+
$sdrcName = "test-sdrc-alias"
40+
41+
# Create and validate
42+
#
43+
$sdrc = New-AzureRmSqlServerDisasterRecoveryConfiguration -ResourceGroupName $rg1.ResourceGroupName -ServerName $server1.ServerName -VirtualEndpointName $sdrcName -PartnerResourceGroupName $rg2.ResourceGroupName -PartnerServerName $server2.ServerName
44+
45+
GetSdrcCheck $rg1 $server1 $sdrcName $rg2 $server2 $failoverPolicy "Primary"
46+
GetSdrcCheck $rg2 $server2 $sdrcName $rg1 $server1 $failoverPolicy "Secondary"
47+
48+
# Failover and check
49+
#
50+
Set-AzureRmSqlServerDisasterRecoveryConfiguration -ResourceGroupName $rg2.ResourceGroupName -ServerName $server2.ServerName -VirtualEndpointName $sdrcName -Failover
51+
52+
GetSdrcCheck $rg2 $server2 $sdrcName $rg1 $server1 $failoverPolicy "Primary"
53+
GetSdrcCheck $rg1 $server1 $sdrcName $rg2 $server2 $failoverPolicy "Secondary"
54+
55+
# Fail back and check
56+
#
57+
Set-AzureRmSqlServerDisasterRecoveryConfiguration -ResourceGroupName $rg1.ResourceGroupName -ServerName $server1.ServerName -VirtualEndpointName $sdrcName -Failover
58+
59+
GetSdrcCheck $rg1 $server1 $sdrcName $rg2 $server2 $failoverPolicy "Primary"
60+
GetSdrcCheck $rg2 $server2 $sdrcName $rg1 $server1 $failoverPolicy "Secondary"
61+
62+
# Delete
63+
#
64+
Remove-AzureRmSqlServerDisasterRecoveryConfiguration -ResourceGroupName $rg1.ResourceGroupName -ServerName $server1.ServerName -VirtualEndpointName $sdrcName -Force
65+
}
66+
finally
67+
{
68+
Remove-ResourceGroupForTest $rg1
69+
Remove-ResourceGroupForTest $rg2
70+
}
71+
}
72+
73+
function GetSdrcCheck ($resourceGroup, $server, $virtualEndpointName, $partnerResourceGroup, $partnerServer, $failoverPolicy, $role)
74+
{
75+
$sdrcGet = Get-AzureRmSqlServerDisasterRecoveryConfiguration -ResourceGroupName $resourceGroup.ResourceGroupName -ServerName $server.ServerName -VirtualEndpointName $virtualEndpointName
76+
77+
Assert-AreEqual $resourceGroup.ResourceGroupName $sdrcGet.ResourceGroupName
78+
Assert-AreEqual $server.ServerName $sdrcGet.ServerName
79+
Assert-AreEqual $virtualEndpointName $sdrcGet.VirtualEndpointName
80+
Assert-AreEqual $partnerServer.ServerName $sdrcGet.PartnerServerName
81+
Assert-AreEqual $failoverPolicy $sdrcGet.FailoverPolicy
82+
Assert-AreEqual $role $sdrcGet.Role
83+
}

0 commit comments

Comments
 (0)