Skip to content

Commit 27b73d3

Browse files
authored
Merge pull request #9750 from emgu-ms/failoverPowershellChanges
Failover database and elastic pool new powershell cmdlets
2 parents 9343403 + 9ca06b3 commit 27b73d3

23 files changed

+16605
-25
lines changed

src/Sql/Sql.LegacySdk/Sql.LegacySdk.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</PropertyGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" PrivateAssets="all"/>
16+
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" PrivateAssets="all" />
1717
</ItemGroup>
1818

1919
</Project>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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 RestTestFramework = Microsoft.Rest.ClientRuntime.Azure.TestFramework;
18+
using Xunit;
19+
using Xunit.Abstractions;
20+
21+
namespace Microsoft.Azure.Commands.Sql.Test.ScenarioTests
22+
{
23+
public class FailoverTests : SqlTestsBase
24+
{
25+
public FailoverTests(ITestOutputHelper output) : base(output)
26+
{
27+
}
28+
29+
[Fact]
30+
[Trait(Category.AcceptanceType, Category.CheckIn)]
31+
public void TestFailoverDatabase()
32+
{
33+
RunPowerShellTest("Test-FailoverDatabase");
34+
}
35+
36+
[Fact]
37+
[Trait(Category.AcceptanceType, Category.CheckIn)]
38+
public void TestFailoverDatabasePassThru()
39+
{
40+
RunPowerShellTest("Test-FailoverDatabasePassThru");
41+
}
42+
43+
[Fact]
44+
[Trait(Category.AcceptanceType, Category.CheckIn)]
45+
public void TestFailoverDatabaseWithDatabasePiping()
46+
{
47+
RunPowerShellTest("Test-FailoverDatabaseWithDatabasePiping");
48+
}
49+
50+
[Fact]
51+
[Trait(Category.AcceptanceType, Category.CheckIn)]
52+
public void TestFailoverDatabaseWithServerPiping()
53+
{
54+
RunPowerShellTest("Test-FailoverDatabaseWithServerPiping");
55+
}
56+
57+
[Fact]
58+
[Trait(Category.AcceptanceType, Category.CheckIn)]
59+
public void TestFailoverElasticPool()
60+
{
61+
RunPowerShellTest("Test-FailoverElasticPool");
62+
}
63+
64+
[Fact]
65+
[Trait(Category.AcceptanceType, Category.CheckIn)]
66+
public void TestFailoverElasticPoolPassThru()
67+
{
68+
RunPowerShellTest("Test-FailoverElasticPoolPassThru");
69+
}
70+
71+
[Fact]
72+
[Trait(Category.AcceptanceType, Category.CheckIn)]
73+
public void TestFailoverElasticPoolWithPoolPiping()
74+
{
75+
RunPowerShellTest("Test-FailoverElasticPoolWithPoolPiping");
76+
}
77+
}
78+
}
Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
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 database failover. Issues command with both -AsJob and without extra parameters
18+
19+
Also tests failing over twice to verify first failover went through which causes second failover to hit a recent failover
20+
exception (aka too many failovers in the given period of time).
21+
#>
22+
function Test-FailoverDatabase
23+
{
24+
# Setup
25+
$location = Get-Location "Microsoft.Sql" "operations" "Southeast Asia"
26+
$rg = Create-ResourceGroupForTest $location
27+
$server = Create-ServerForTest $rg $location
28+
29+
try
30+
{
31+
# Create database
32+
$databaseName = Get-DatabaseName
33+
New-AzSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName
34+
35+
# Failover database with -AsJob
36+
$job = Invoke-AzSqlDatabaseFailover -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName -AsJob
37+
$job | Wait-Job
38+
39+
# Failover database with no extra switch parameters. Tests for exception to verify the first failover went through correctly as this second
40+
# failover will cause a recent failover exception
41+
try {
42+
Invoke-AzSqlDatabaseFailover -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName
43+
} catch {
44+
$ErrorMessage = $_.Exception.Message
45+
Assert-AreEqual True $ErrorMessage.Contains("There was a recent failover on the database or pool")
46+
}
47+
}
48+
finally
49+
{
50+
Remove-ResourceGroupForTest $rg
51+
}
52+
}
53+
54+
<#
55+
.SYNOPSIS
56+
Tests database failover with passthru
57+
#>
58+
function Test-FailoverDatabasePassThru
59+
{
60+
# Setup
61+
$location = Get-Location "Microsoft.Sql" "operations" "Southeast Asia"
62+
$rg = Create-ResourceGroupForTest $location
63+
$server = Create-ServerForTest $rg $location
64+
65+
try
66+
{
67+
# Create database
68+
$databaseName = Get-DatabaseName
69+
New-AzSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName
70+
71+
# Failover database with -PassThru
72+
$output = Invoke-AzSqlDatabaseFailover -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName -PassThru
73+
Assert-True { $output }
74+
}
75+
finally
76+
{
77+
Remove-ResourceGroupForTest $rg
78+
}
79+
}
80+
81+
<#
82+
.SYNOPSIS
83+
Tests database failover using piping for database.
84+
#>
85+
function Test-FailoverDatabaseWithDatabasePiping
86+
{
87+
# Setup
88+
$location = Get-Location "Microsoft.Sql" "operations" "Southeast Asia"
89+
$rg = Create-ResourceGroupForTest $location
90+
$server = Create-ServerForTest $rg $location
91+
92+
try
93+
{
94+
# Create database
95+
$databaseName = Get-DatabaseName
96+
New-AzSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName
97+
98+
# Failover database using piping for database
99+
Get-AzSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName | Invoke-AzSqlDatabaseFailover
100+
}
101+
finally
102+
{
103+
Remove-ResourceGroupForTest $rg
104+
}
105+
}
106+
107+
<#
108+
.SYNOPSIS
109+
Tests database failover using piping for server.
110+
#>
111+
function Test-FailoverDatabaseWithServerPiping
112+
{
113+
# Setup
114+
$location = Get-Location "Microsoft.Sql" "operations" "Southeast Asia"
115+
$rg = Create-ResourceGroupForTest $location
116+
$server = Create-ServerForTest $rg $location
117+
118+
try
119+
{
120+
# Create database
121+
$databaseName = Get-DatabaseName
122+
New-AzSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName
123+
124+
# Failover database using piping for server
125+
Get-AzSqlServer -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName | Invoke-AzSqlDatabaseFailover -DatabaseName $databaseName
126+
}
127+
finally
128+
{
129+
Remove-ResourceGroupForTest $rg
130+
}
131+
}
132+
133+
<#
134+
.SYNOPSIS
135+
Tests elastic pool failover. Issues command with both -AsJob and without extra parameters
136+
137+
Also tests failing over twice to verify first failover went through which causes second failover to hit a recent failover
138+
exception (aka too many failovers in the given period of time).
139+
#>
140+
function Test-FailoverElasticPool
141+
{
142+
# Setup
143+
$location = Get-Location "Microsoft.Sql" "operations" "Southeast Asia"
144+
$rg = Create-ResourceGroupForTest $location
145+
$server = Create-ServerForTest $rg $location
146+
147+
try
148+
{
149+
# Create elastic pool
150+
$poolName = Get-ElasticPoolName
151+
New-AzSqlElasticPool -ServerName $server.ServerName -ResourceGroupName $rg.ResourceGroupName -ElasticPoolName $poolName
152+
153+
# Create database in elastic pool
154+
$databaseName = Get-DatabaseName
155+
New-AzSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName -ElasticPoolName $poolName
156+
157+
# Failover elastic pool with -AsJob
158+
$job = Invoke-AzSqlElasticPoolFailover -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -ElasticPoolName $poolName -AsJob
159+
$job | Wait-Job
160+
161+
# Failover elastic pool with no extra switch parameters. Tests for exception to verify the first failover went through correctly as this second
162+
# failover will cause a recent failover exception
163+
try {
164+
Invoke-AzSqlElasticPoolFailover -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -ElasticPoolName $poolName
165+
} catch {
166+
$ErrorMessage = $_.Exception.Message
167+
Assert-AreEqual True $ErrorMessage.Contains("There was a recent failover on the elastic pool")
168+
}
169+
}
170+
finally
171+
{
172+
Remove-ResourceGroupForTest $rg
173+
}
174+
}
175+
176+
<#
177+
.SYNOPSIS
178+
Tests elastic pool failover with passthru
179+
#>
180+
function Test-FailoverElasticPoolPassThru
181+
{
182+
# Setup
183+
$location = Get-Location "Microsoft.Sql" "operations" "Southeast Asia"
184+
$rg = Create-ResourceGroupForTest $location
185+
$server = Create-ServerForTest $rg $location
186+
187+
try
188+
{
189+
# Create elastic pool
190+
$poolName = Get-ElasticPoolName
191+
New-AzSqlElasticPool -ServerName $server.ServerName -ResourceGroupName $rg.ResourceGroupName -ElasticPoolName $poolName
192+
193+
# Create database in elastic pool
194+
$databaseName = Get-DatabaseName
195+
New-AzSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName -ElasticPoolName $poolName
196+
197+
# Failover elastic pool with -PassThru
198+
$output = Invoke-AzSqlElasticPoolFailover -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -ElasticPoolName $poolName -PassThru
199+
Assert-True { $output }
200+
}
201+
finally
202+
{
203+
Remove-ResourceGroupForTest $rg
204+
}
205+
}
206+
207+
<#
208+
.SYNOPSIS
209+
Tests elastic pool failover using piping for pool.
210+
#>
211+
function Test-FailoverElasticPoolWithPoolPiping
212+
{
213+
# Setup
214+
$location = Get-Location "Microsoft.Sql" "operations" "Southeast Asia"
215+
$rg = Create-ResourceGroupForTest $location
216+
$server = Create-ServerForTest $rg $location
217+
218+
try
219+
{
220+
# Create elastic pool
221+
$poolName = Get-ElasticPoolName
222+
New-AzSqlElasticPool -ServerName $server.ServerName -ResourceGroupName $rg.ResourceGroupName -ElasticPoolName $poolName
223+
224+
# Create database in elastic pool
225+
$databaseName = Get-DatabaseName
226+
New-AzSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName -ElasticPoolName $poolName
227+
228+
# Failover elastic pool using piping for pool
229+
Get-AzSqlElasticPool -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -ElasticPoolName $poolName | Invoke-AzSqlElasticPoolFailover
230+
}
231+
finally
232+
{
233+
Remove-ResourceGroupForTest $rg
234+
}
235+
}

src/Sql/Sql.Test/SessionRecords/Microsoft.Azure.Commands.Sql.Test.ScenarioTests.FailoverTests/TestFailoverDatabase.json

Lines changed: 2195 additions & 0 deletions
Large diffs are not rendered by default.

src/Sql/Sql.Test/SessionRecords/Microsoft.Azure.Commands.Sql.Test.ScenarioTests.FailoverTests/TestFailoverDatabasePassThru.json

Lines changed: 2009 additions & 0 deletions
Large diffs are not rendered by default.

src/Sql/Sql.Test/SessionRecords/Microsoft.Azure.Commands.Sql.Test.ScenarioTests.FailoverTests/TestFailoverDatabaseWithDatabasePiping.json

Lines changed: 1952 additions & 0 deletions
Large diffs are not rendered by default.

src/Sql/Sql.Test/SessionRecords/Microsoft.Azure.Commands.Sql.Test.ScenarioTests.FailoverTests/TestFailoverDatabaseWithServerPiping.json

Lines changed: 2120 additions & 0 deletions
Large diffs are not rendered by default.

src/Sql/Sql.Test/SessionRecords/Microsoft.Azure.Commands.Sql.Test.ScenarioTests.FailoverTests/TestFailoverElasticPool.json

Lines changed: 2574 additions & 0 deletions
Large diffs are not rendered by default.

src/Sql/Sql.Test/SessionRecords/Microsoft.Azure.Commands.Sql.Test.ScenarioTests.FailoverTests/TestFailoverElasticPoolPassThru.json

Lines changed: 2499 additions & 0 deletions
Large diffs are not rendered by default.

src/Sql/Sql.Test/SessionRecords/Microsoft.Azure.Commands.Sql.Test.ScenarioTests.FailoverTests/TestFailoverElasticPoolWithPoolPiping.json

Lines changed: 2211 additions & 0 deletions
Large diffs are not rendered by default.

src/Sql/Sql/Az.Sql.psd1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ CmdletsToExport = 'Get-AzSqlDatabaseTransparentDataEncryption',
233233
'Remove-AzSqlServerAudit', 'Remove-AzSqlDatabaseAudit',
234234
'Get-AzSqlInstancePool', 'Set-AzSqlInstancePool',
235235
'New-AzSqlInstancePool', 'Remove-AzSqlInstancePool',
236-
'Get-AzSqlInstancePoolUsage'
236+
'Get-AzSqlInstancePoolUsage',
237+
'Invoke-AzSqlDatabaseFailover',
238+
'Invoke-AzSqlElasticPoolFailover'
237239

238240
# Variables to export from this module
239241
# VariablesToExport = @()

src/Sql/Sql/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* Add Azure Sql Instance pool usages cmdlets
2323
* Update Azure Sql Managed instance cmdlets to support instance pools
2424
* Fixed miscellaneous typos across module
25+
* Add failover database and elastic pool new cmdlets.
2526
* Add optional resource group parameter to Get-DatabaseLongTermRetentionBackup and Remove-DatabaseLongTermRetentionBackup cmdlets
2627

2728
## Version 1.13.1

0 commit comments

Comments
 (0)