Skip to content

Commit f8b304f

Browse files
authored
Merge pull request Azure#2465 from sw145/dev-shicwu
Supporting Stretch Edition Database in PowerShell
2 parents 60ada7a + ee36cdd commit f8b304f

File tree

13 files changed

+8553
-2
lines changed

13 files changed

+8553
-2
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,20 @@
195195
<DesignTime>True</DesignTime>
196196
<DependentUpon>Resources.resx</DependentUpon>
197197
</Compile>
198+
<Compile Include="ScenarioTests\DatabaseBackupStretchTests.cs" />
199+
<Compile Include="ScenarioTests\DatabaseCrudStretchTests.cs" />
198200
<Compile Include="ScenarioTests\ThreatDetectionTests.cs" />
199201
<Compile Include="ScenarioTests\DatabaseActivationTests.cs" />
200202
<Compile Include="ScenarioTests\DatabaseBackupTests.cs" />
201203
<Compile Include="ScenarioTests\DatabaseReplicationTests.cs" />
202204
<Compile Include="ScenarioTests\DatabaseCrudTests.cs" />
203205
<Compile Include="ScenarioTests\DataMaskingTests.cs" />
206+
<None Include="ScenarioTests\DatabaseBackupStretchTests.ps1">
207+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
208+
</None>
209+
<None Include="ScenarioTests\DatabaseCrudStretchTests.ps1">
210+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
211+
</None>
204212
<None Include="ScenarioTests\ThreatDetectionTests.ps1">
205213
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
206214
</None>
@@ -419,6 +427,9 @@
419427
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.DatabaseActivationTests\TestDatabasePauseResumePiped.json">
420428
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
421429
</None>
430+
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.DatabaseBackupStretchTests\TestStretchDatabaseListRestorePoints.json">
431+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
432+
</None>
422433
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.DatabaseBackupTests\TestListDatabaseRestorePoints.json">
423434
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
424435
</None>
@@ -440,6 +451,18 @@
440451
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.DatabaseBackupTests\TestDatabaseBackupLongTermRetentionPolicy.json">
441452
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
442453
</None>
454+
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.DatabaseCrudStretchTests\TestStretchDatabaseCreate.json">
455+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
456+
</None>
457+
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.DatabaseCrudStretchTests\TestStretchDatabaseGet.json">
458+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
459+
</None>
460+
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.DatabaseCrudStretchTests\TestStretchDatabaseRemove.json">
461+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
462+
</None>
463+
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.DatabaseCrudStretchTests\TestStretchDatabaseUpdate.json">
464+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
465+
</None>
443466
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.DatabaseCrudTests\TestDatabaseCreate.json">
444467
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
445468
</None>

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/Common.ps1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,35 @@ function Get-ElasticPoolName
182182
return getAssetName
183183
}
184184

185+
<#
186+
.SYNOPSIS
187+
Gets the location for a provider, if not found return East US
188+
#>
189+
function Get-ProviderLocation($provider)
190+
{
191+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
192+
{
193+
$namespace = $provider.Split("/")[0]
194+
if($provider.Contains("/"))
195+
{
196+
$type = $provider.Substring($namespace.Length + 1)
197+
$location = Get-AzureRmResourceProvider -ProviderNamespace $namespace | where {$_.ResourceTypes[0].ResourceTypeName -eq $type}
198+
199+
if ($location -eq $null)
200+
{
201+
return "East US"
202+
} else
203+
{
204+
return $location.Locations[0]
205+
}
206+
}
207+
208+
return "East US"
209+
}
210+
211+
return "East US"
212+
}
213+
185214
<#
186215
.SYNOPSIS
187216
Creates a resource group for tests
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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.Mocks;
16+
using Microsoft.Azure.Commands.ScenarioTest.SqlTests;
17+
using Microsoft.Azure.ServiceManagemenet.Common.Models;
18+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
19+
using Xunit;
20+
using Xunit.Abstractions;
21+
22+
namespace Microsoft.Azure.Commands.Sql.Test.ScenarioTests
23+
{
24+
public class DatabaseBackupStretchTests : SqlTestsBase
25+
{
26+
/// <summary>
27+
/// Follow the way how AuditingTests setup their manangement clients
28+
/// Only overide SetupManagementClients() here because stretch database
29+
/// tests in this test suite now use V2 version of storage client
30+
/// </summary>
31+
protected override void SetupManagementClients()
32+
{
33+
var sqlCSMClient = GetSqlClient();
34+
var storageClient = GetStorageV2Client();
35+
36+
// TODO, Remove the MockDeploymentFactory call when the test is re-recorded
37+
//
38+
var resourcesClient = MockDeploymentClientFactory.GetResourceClient(GetResourcesClient());
39+
var authorizationClient = GetAuthorizationManagementClient();
40+
helper.SetupSomeOfManagementClients(sqlCSMClient, storageClient, resourcesClient,
41+
authorizationClient);
42+
}
43+
44+
public DatabaseBackupStretchTests(ITestOutputHelper output)
45+
{
46+
XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
47+
}
48+
49+
[Fact]
50+
[Trait(Category.AcceptanceType, Category.CheckIn)]
51+
public void TestStretchDatabaseListRestorePoints()
52+
{
53+
RunPowerShellTest("Test-ListStretchDatabaseRestorePoints");
54+
}
55+
}
56+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
Test getting restore points from stretch databases
18+
#>
19+
function Test-ListStretchDatabaseRestorePoints
20+
{
21+
# Setup
22+
$location = Get-ProviderLocation "Microsoft.Sql/servers"
23+
$serverVersion = "12.0";
24+
$rg = Create-ResourceGroupForTest $location
25+
26+
try
27+
{
28+
$server = Create-ServerForTest $rg $serverVersion $location
29+
30+
# Create stretch database with all parameters.
31+
$databaseName = Get-DatabaseName
32+
$stretchdb = New-AzureRmSqlDatabase -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $databaseName `
33+
-Edition Stretch -RequestedServiceObjectiveName DS100
34+
35+
# Get restore points from stretch database.
36+
$restorePoints = Get-AzureRmSqlDatabaseRestorePoints -ResourceGroupName $rg.ResourceGroupName -ServerName $server.ServerName -DatabaseName $stretchdb.DatabaseName
37+
Assert-Null $restorePoints # Since the stretch database has just been created, it should not have any discrete restore points.
38+
}
39+
finally
40+
{
41+
Remove-ResourceGroupForTest $rg
42+
}
43+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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.Mocks;
16+
using Microsoft.Azure.Commands.ScenarioTest.SqlTests;
17+
using Microsoft.Azure.ServiceManagemenet.Common.Models;
18+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
19+
using Xunit;
20+
using Xunit.Abstractions;
21+
22+
namespace Microsoft.Azure.Commands.Sql.Test.ScenarioTests
23+
{
24+
public class DatabaseCrudStretchTests : SqlTestsBase
25+
{
26+
/// <summary>
27+
/// Follow the way how AuditingTests setup their manangement clients
28+
/// Only overide SetupManagementClients() here because stretch database
29+
/// tests in this test suite now use V2 version of storage client
30+
/// </summary>
31+
protected override void SetupManagementClients()
32+
{
33+
var sqlCSMClient = GetSqlClient();
34+
var storageClient = GetStorageV2Client();
35+
36+
// TODO, Remove the MockDeploymentFactory call when the test is re-recorded
37+
//
38+
var resourcesClient = MockDeploymentClientFactory.GetResourceClient(GetResourcesClient());
39+
var authorizationClient = GetAuthorizationManagementClient();
40+
helper.SetupSomeOfManagementClients(sqlCSMClient, storageClient, resourcesClient,
41+
authorizationClient);
42+
}
43+
44+
public DatabaseCrudStretchTests(ITestOutputHelper output)
45+
{
46+
XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
47+
}
48+
49+
[Fact]
50+
[Trait(Category.AcceptanceType, Category.CheckIn)]
51+
public void TestStretchDatabaseCreate()
52+
{
53+
RunPowerShellTest("Test-CreateStretchDatabase");
54+
}
55+
56+
[Fact]
57+
[Trait(Category.AcceptanceType, Category.CheckIn)]
58+
public void TestStretchDatabaseUpdate()
59+
{
60+
RunPowerShellTest("Test-UpdateStretchDatabase");
61+
}
62+
63+
[Fact]
64+
[Trait(Category.AcceptanceType, Category.CheckIn)]
65+
public void TestStretchDatabaseGet()
66+
{
67+
RunPowerShellTest("Test-GetStretchDatabase");
68+
}
69+
70+
[Fact]
71+
[Trait(Category.AcceptanceType, Category.CheckIn)]
72+
public void TestStretchDatabaseRemove()
73+
{
74+
RunPowerShellTest("Test-RemoveStretchDatabase");
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)