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