Skip to content

Commit 3f5966d

Browse files
committed
Reinstate and record ServerUpgradeTests.
The tests are modified so that they work with V12 server. Get commands will continue to work, Start/Stop commands will fail.
1 parent a32a6e0 commit 3f5966d

File tree

6 files changed

+68020
-0
lines changed

6 files changed

+68020
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@
215215
<Compile Include="ScenarioTests\RecommendedActionTests.cs" />
216216
<Compile Include="ScenarioTests\DatabaseBackupStretchTests.cs" />
217217
<Compile Include="ScenarioTests\DatabaseCrudStretchTests.cs" />
218+
<Compile Include="ScenarioTests\ServerUpgradeTests.cs" />
218219
<Compile Include="ScenarioTests\ThreatDetectionClassicStorageTests.cs" />
219220
<Compile Include="ScenarioTests\ThreatDetectionTests.cs" />
220221
<Compile Include="ScenarioTests\DatabaseActivationTests.cs" />
@@ -243,6 +244,9 @@
243244
<None Include="ScenarioTests\DatabaseCrudStretchTests.ps1">
244245
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
245246
</None>
247+
<None Include="ScenarioTests\ServerUpgradeTests.ps1">
248+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
249+
</None>
246250
<None Include="ScenarioTests\ThreatDetectionClassicStorageTests.ps1">
247251
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
248252
</None>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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.Azure.ServiceManagemenet.Common.Models;
17+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
18+
using Xunit;
19+
using Xunit.Abstractions;
20+
21+
namespace Microsoft.Azure.Commands.Sql.Test.ScenarioTests
22+
{
23+
public class ServerUpgradeTests : SqlTestsBase
24+
{
25+
public ServerUpgradeTests(ITestOutputHelper output) : base(output)
26+
{
27+
}
28+
29+
[Fact]
30+
[Trait(Category.AcceptanceType, Category.CheckIn)]
31+
public void TestServerUpgradeWithUpgradeHint()
32+
{
33+
RunPowerShellTest("Test-ServerUpgradeWithUpgradeHint");
34+
}
35+
36+
[Fact]
37+
[Trait(Category.AcceptanceType, Category.CheckIn)]
38+
public void TestServerUpgradeAndCancel()
39+
{
40+
RunPowerShellTest("Test-ServerUpgradeAndCancel");
41+
}
42+
43+
[Fact]
44+
[Trait(Category.AcceptanceType, Category.CheckIn)]
45+
public void TestServerUpgradeNegative()
46+
{
47+
RunPowerShellTest("Test-ServerUpgradeNegative");
48+
}
49+
}
50+
}
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
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 upgrading a server with result from upgrade hint cmdlet
18+
#>
19+
function Test-ServerUpgradeWithUpgradeHint
20+
{
21+
# Setup
22+
$server = Create-ServerForServerUpgradeTest
23+
24+
# Create a basic database
25+
$databaseName = Get-DatabaseName
26+
$database = New-AzureRmSqlDatabase -ResourceGroupName $server.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName -Edition Basic -MaxSizeBytes 1GB
27+
Assert-AreEqual $database.DatabaseName $databaseName
28+
29+
try
30+
{
31+
$upgrade = Get-AzureRmSqlServerUpgrade -ResourceGroupName $server.ResourceGroupName -ServerName $server.ServerName
32+
33+
$mapping = Get-AzureRmSqlServerUpgradeHint -ResourceGroupName $server.ResourceGroupName -ServerName $server.ServerName
34+
35+
Assert-Throws { Start-AzureRmSqlServerUpgrade -ResourceGroupName $server.ResourceGroupName -ServerName $server.ServerName -ServerVersion 12.0 -ScheduleUpgradeAfterUtcDateTime ((Get-Date).AddMinutes(1).ToUniversalTime()) -DatabaseCollection $mapping.Databases -ElasticPoolCollection $hint.ElasticPools }
36+
37+
while ($true)
38+
{
39+
$upgrade = Get-AzureRmSqlServerUpgrade -ResourceGroupName $server.ResourceGroupName -ServerName $server.ServerName
40+
if ($upgrade.Status -eq "Completed")
41+
{
42+
# Upgrade is successful
43+
$server = Get-AzureRmSqlServer -ResourceGroupName $server.ResourceGroupName -ServerName $server.ServerName
44+
Assert-AreEqual $server.ServerVersion "12.0"
45+
break
46+
}
47+
elseif ($upgrade.Status -eq "Stopped")
48+
{
49+
# Upgrade failed
50+
$server = Get-AzureRmSqlServer -ResourceGroupName $server.ResourceGroupName -ServerName $server.ServerName
51+
Assert-AreEqual $server.ServerVersion "2.0"
52+
break
53+
}
54+
Wait-Seconds 10
55+
}
56+
}
57+
finally
58+
{
59+
Remove-AzureRmResourceGroup -Name $server.ResourceGroupName -Force
60+
}
61+
}
62+
63+
<#
64+
.SYNOPSIS
65+
Tests upgrading a server and then cancel the upgrade
66+
#>
67+
function Test-ServerUpgradeAndCancel
68+
{
69+
# Setup
70+
$server = Create-ServerForServerUpgradeTest
71+
72+
try
73+
{
74+
Assert-Throws { Start-AzureRmSqlServerUpgrade -ResourceGroupName $server.ResourceGroupName -ServerName $server.ServerName -ServerVersion 12.0 }
75+
76+
$upgrade = Get-AzureRmSqlServerUpgrade -ResourceGroupName $server.ResourceGroupName -ServerName $server.ServerName
77+
# Assert-AreEqual $upgrade.Status "Queued" # If the server was version 2.0 and Start had succeeded
78+
Assert-AreEqual $upgrade.Status "Completed"
79+
80+
Assert-Throws { Stop-AzureRmSqlServerUpgrade -ResourceGroupName $server.ResourceGroupName -ServerName $server.ServerName -Force }
81+
82+
$upgrade = Get-AzureRmSqlServerUpgrade -ResourceGroupName $server.ResourceGroupName -ServerName $server.ServerName
83+
# Assert-AreEqual $upgrade.Status "Cancelling" # If the server was version 2.0 and Stop had succeeded
84+
Assert-AreEqual $upgrade.Status "Completed"
85+
86+
# Below would be if the server was version 2.0 and Stop had succeeded
87+
# while ($true)
88+
# {
89+
# $upgrade = Get-AzureRmSqlServerUpgrade -ResourceGroupName $server.ResourceGroupName -ServerName $server.ServerName
90+
# # if ($upgrade.Status -eq "Stopped")
91+
# if ($upgrade.Status -eq "Completed")
92+
# {
93+
# break
94+
# }
95+
# Wait-Seconds 10
96+
# }
97+
98+
# Upgrade is cancelled
99+
# $server = Get-AzureRmSqlServer -ResourceGroupName $server.ResourceGroupName -ServerName $server.ServerName
100+
# Assert-AreEqual $server.ServerVersion "2.0"
101+
}
102+
finally
103+
{
104+
Remove-AzureRmResourceGroup -Name $server.ResourceGroupName -Force
105+
}
106+
}
107+
108+
<#
109+
.SYNOPSIS
110+
Tests upgrading a server with invalid parameters
111+
#>
112+
function Test-ServerUpgradeNegative
113+
{
114+
# Setup
115+
$server = Create-ServerForServerUpgradeTest
116+
117+
# Create a basic database
118+
$databaseName = Get-DatabaseName
119+
$database = New-AzureRmSqlDatabase -ResourceGroupName $server.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName -Edition Basic -MaxSizeBytes 1GB
120+
Assert-AreEqual $database.DatabaseName $databaseName
121+
122+
try
123+
{
124+
Assert-Throws { Start-AzureRmSqlServerUpgrade -ResourceGroupName $server.ResourceGroupName -ServerName $server.ServerName }
125+
Assert-Throws { Start-AzureRmSqlServerUpgrade -ResourceGroupName $server.ResourceGroupName -ServerName $server.ServerName -ServerVersion 13.0}
126+
Assert-Throws { Start-AzureRmSqlServerUpgrade -ResourceGroupName $server.ResourceGroupName -ServerName $server.ServerName -ScheduleUpgradeAfterUtcDateTime ((Get-Date).ToUniversalTime())}
127+
128+
$recommendedDatabase = New-Object -TypeName Microsoft.Azure.Management.Sql.LegacySdk.Models.RecommendedDatabaseProperties
129+
$recommendedDatabase.Name = databaseName
130+
$recommendedDatabase.TargetEdition = "InvalidEdition"
131+
$recommendedDatabase.TargetServiceLevelObjective = "S0"
132+
Assert-Throws { Start-AzureRmSqlServerUpgrade -ResourceGroupName $server.ResourceGroupName -ServerName $server.ServerName -DatabaseCollection ($recommendedDatabase)}
133+
134+
$recommendedDatabase.TargetEdition = "Premium"
135+
$recommendedDatabase.TargetServiceLevelObjective = "S0"
136+
Assert-Throws { Start-AzureRmSqlServerUpgrade -ResourceGroupName $server.ResourceGroupName -ServerName $server.ServerName -DatabaseCollection ($recommendedDatabase)}
137+
}
138+
finally
139+
{
140+
Remove-AzureRmResourceGroup -Name $server.ResourceGroupName -Force
141+
}
142+
}
143+
144+
<#
145+
.SYNOPSIS
146+
Creates a resource group and server for server upgrade tests
147+
#>
148+
function Create-ServerForServerUpgradeTest()
149+
{
150+
$location = "West US"
151+
$rgName = Get-ResourceGroupName
152+
153+
$rg = New-AzureRmResourceGroup -Name $rgName -Location $location
154+
155+
$serverName = Get-ServerName
156+
$version = "12.0"
157+
$serverLogin = "testusername"
158+
$serverPassword = "t357ingP@s5w0rd!"
159+
$credentials = New-Object System.Management.Automation.PSCredential($serverLogin, ($serverPassword | ConvertTo-SecureString -asPlainText -Force))
160+
161+
$server = New-AzureRmSql`Server -ResourceGroupName $rgName -ServerName $serverName -Location $location -ServerVersion $version -SqlAdministratorCredentials $credentials
162+
return $server
163+
}

0 commit comments

Comments
 (0)