Skip to content

Commit 0b9f9ec

Browse files
authored
Merge pull request #9744 from johnpaulkee/instancePoolsMaster
Add instance pool, instance pool usages cmdlets, and update managed instance cmdlets to support instance pools.
2 parents 7f036ca + af5b8cc commit 0b9f9ec

File tree

62 files changed

+23208
-283
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+23208
-283
lines changed

src/Sql/Sql.Test/ScenarioTests/AdvancedDataSecurityManagedInstanceTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using Microsoft.Azure.Commands.ScenarioTest.SqlTests;
1616
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using System.Collections.Generic;
1718
using Xunit;
1819
using Xunit.Abstractions;
1920
using RestTestFramework = Microsoft.Rest.ClientRuntime.Azure.TestFramework;
@@ -32,6 +33,9 @@ protected override void SetupManagementClients(RestTestFramework.MockContext con
3233

3334
public AdvancedDataSecurityManagedInstanceTests(ITestOutputHelper output) : base(output)
3435
{
36+
base.resourceTypesToIgnoreApiVersion = new string[] {
37+
"Microsoft.Sql/managedInstances"
38+
};
3539
}
3640

3741
[Fact]

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

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ Creates the basic test environment needed to perform the Sql data security tests
201201
function Create-BasicManagedTestEnvironmentWithParams ($params, $location)
202202
{
203203
New-AzureRmResourceGroup -Name $params.rgname -Location $location
204-
205-
# Setup VNET
204+
205+
# Setup VNET
206206
$vnetName = "cl_initial"
207207
$subnetName = "Cool"
208208
$virtualNetwork1 = CreateAndGetVirtualNetworkForManagedInstance $vnetName $subnetName
@@ -235,7 +235,7 @@ function Create-DataMaskingTestEnvironment ($testSuffix)
235235
New-AzSqlServer -ResourceGroupName $params.rgname -ServerName $params.serverName -ServerVersion "12.0" -Location "West Central US" -SqlAdministratorCredentials $credentials
236236
New-AzSqlServerFirewallRule -ResourceGroupName $params.rgname -ServerName $params.serverName -StartIpAddress 0.0.0.0 -EndIpAddress 255.255.255.255 -FirewallRuleName "ddmRule"
237237
New-AzSqlDatabase -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName
238-
238+
239239
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -eq "Record")
240240
{
241241
$fullServerName = $params.serverName + ".database.windows.net"
@@ -358,11 +358,11 @@ function Get-ManagedInstanceForTdeTest ($params)
358358
$rg = Create-ResourceGroupForTest
359359
$vnetName = "cl_initial"
360360
$subnetName = "Cool"
361-
362-
# Setup VNET
361+
362+
# Setup VNET
363363
$virtualNetwork1 = CreateAndGetVirtualNetworkForManagedInstance $vnetName $subnetName $rg.Location
364364
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName })[0].Id
365-
365+
366366
$managedInstance = Create-ManagedInstanceForTest $rg $subnetId
367367
Set-AzKeyVaultAccessPolicy -VaultName $params.vaultName -ObjectId $managedInstance.Identity.PrincipalId -PermissionsToKeys get, list, wrapKey, unwrapKey
368368

@@ -495,7 +495,7 @@ function Get-ProviderLocation($provider)
495495
if ($location -eq $null)
496496
{
497497
return "East US"
498-
}
498+
}
499499
else
500500
{
501501
return $location.Locations[0]
@@ -539,7 +539,7 @@ function Get-ServerCredential
539539
$serverLogin = "testusername"
540540
<#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Test passwords only valid for the duration of the test")]#>
541541
$serverPassword = "t357ingP@s5w0rd!"
542-
$credentials = new-object System.Management.Automation.PSCredential($serverLogin, ($serverPassword | ConvertTo-SecureString -asPlainText -Force))
542+
$credentials = new-object System.Management.Automation.PSCredential($serverLogin, ($serverPassword | ConvertTo-SecureString -asPlainText -Force))
543543
return $credentials
544544
}
545545

@@ -738,6 +738,59 @@ function Create-ManagedInstanceForTest ($resourceGroup, $subnetId)
738738
return $managedInstance
739739
}
740740

741+
<#
742+
.SYNOPSIS
743+
Creates a managed instance in an instance pool
744+
#>
745+
function Create-ManagedInstanceInInstancePoolForTest ($instancePool)
746+
{
747+
$managedInstanceName = Get-ManagedInstanceName
748+
$credentials = Get-ServerCredential
749+
$vCore = 2
750+
$managedInstance = $instancePool | New-AzSqlInstance -Name $managedInstanceName -VCore $vCore -AdministratorCredential $credentials -StorageSizeInGb 32 -PublicDataEndpointEnabled
751+
return $managedInstance
752+
}
753+
754+
function Remove-ManagedInstancesInInstancePool($instancePool)
755+
{
756+
$instancePool | Get-AzSqlInstance | Remove-AzSqlInstance -Force
757+
}
758+
759+
760+
function Get-InstancePoolTestProperties()
761+
{
762+
$tags = @{ instance="Pools" };
763+
$instancePoolTestProperties = @{
764+
resourceGroup = "instancePoolCSSdemo"
765+
name = "cssinstancepool0"
766+
subnetName = "InstancePool"
767+
vnetName = "vnet-cssinstancepool0"
768+
tags = $tags
769+
computeGen = "Gen5"
770+
edition = "GeneralPurpose"
771+
location = "canadacentral"
772+
licenseType = "LicenseIncluded"
773+
vCores = 16
774+
}
775+
return $instancePoolTestProperties
776+
}
777+
778+
<#
779+
.SYNOPSIS
780+
Creates an instance pool for Sql instance pool CRUD tests
781+
#>
782+
function Create-InstancePoolForTest()
783+
{
784+
$props = Get-InstancePoolTestProperties
785+
$virtualNetwork = CreateAndGetVirtualNetworkForManagedInstance $props.vnetName $props.subnetName $props.location $props.resourceGroup
786+
$subnetId = $virtualNetwork.Subnets.where({ $_.Name -eq $props.subnetName })[0].Id
787+
$instancePool = New-AzSqlInstancePool -ResourceGroupName $props.resourceGroup -Name $props.name `
788+
-Location $props.location -SubnetId $subnetId -VCore $props.vCores `
789+
-Edition $props.Edition -ComputeGeneration $props.computeGen `
790+
-LicenseType $props.licenseType -Tag $props.tags
791+
return $instancePool
792+
}
793+
741794
<#
742795
.SYNOPSIS
743796
Create a virtual network

src/Sql/Sql.Test/ScenarioTests/DataClassificationTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public class DataClassificationTests : SqlTestsBase
2323
{
2424
public DataClassificationTests(ITestOutputHelper output) : base(output)
2525
{
26+
base.resourceTypesToIgnoreApiVersion = new string[] {
27+
"Microsoft.Sql/managedInstances"
28+
};
2629
}
2730

2831
protected override void SetupManagementClients(RestTestFramework.MockContext context)
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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+
using Xunit.Abstractions;
19+
using RestTestFramework = Microsoft.Rest.ClientRuntime.Azure.TestFramework;
20+
21+
namespace Microsoft.Azure.Commands.Sql.Test.ScenarioTests
22+
{
23+
public class InstancePoolCrudTests : SqlTestsBase
24+
{
25+
public InstancePoolCrudTests(ITestOutputHelper output) : base(output)
26+
{
27+
}
28+
29+
protected override void SetupManagementClients(RestTestFramework.MockContext context)
30+
{
31+
var sqlClient = GetSqlClient(context);
32+
var newResourcesClient = GetResourcesClient(context);
33+
var networkClient = GetNetworkClient(context);
34+
Helper.SetupSomeOfManagementClients(sqlClient, newResourcesClient, networkClient);
35+
}
36+
37+
#region Instance pool
38+
39+
/// <summary>
40+
/// Tests creation of an instance pool
41+
/// </summary>
42+
[Fact]
43+
[Trait(Category.AcceptanceType, Category.CheckIn)]
44+
public void TestCreateInstancePool()
45+
{
46+
RunPowerShellTest("Test-CreateInstancePool");
47+
}
48+
49+
/// <summary>
50+
/// Tests updating an instance pool
51+
/// </summary>
52+
[Fact]
53+
[Trait(Category.AcceptanceType, Category.CheckIn)]
54+
public void TestUpdateInstancePool()
55+
{
56+
RunPowerShellTest("Test-UpdateInstancePool");
57+
}
58+
59+
/// <summary>
60+
/// Tests getting an instance pool
61+
/// </summary>
62+
[Fact]
63+
[Trait(Category.AcceptanceType, Category.CheckIn)]
64+
public void TestGetInstancePool()
65+
{
66+
RunPowerShellTest("Test-GetInstancePool");
67+
}
68+
69+
[Fact]
70+
[Trait(Category.AcceptanceType, Category.CheckIn)]
71+
public void TestRemoveInstancePool()
72+
{
73+
RunPowerShellTest("Test-RemoveInstancePool");
74+
}
75+
76+
#endregion
77+
78+
#region Managed Instance
79+
80+
/// <summary>
81+
/// Tests creation of a managed instance in an instance pool
82+
/// </summary>
83+
[Fact]
84+
[Trait(Category.AcceptanceType, Category.CheckIn)]
85+
public void TestCreateManagedInstanceInInstancePool()
86+
{
87+
RunPowerShellTest("Test-CreateManagedInstanceInInstancePool");
88+
}
89+
90+
/// <summary>
91+
/// Tests getting all managed instances in an instance pool
92+
/// </summary>
93+
[Fact]
94+
[Trait(Category.AcceptanceType, Category.CheckIn)]
95+
public void TestGetManagedInstanceInInstancePool()
96+
{
97+
RunPowerShellTest("Test-GetManagedInstanceInInstancePool");
98+
}
99+
100+
/// <summary>
101+
/// Tests updating a managed instance in an instance pool
102+
/// </summary>
103+
[Fact]
104+
[Trait(Category.AcceptanceType, Category.CheckIn)]
105+
public void TestUpdateManagedInstanceInInstancePool()
106+
{
107+
RunPowerShellTest("Test-UpdateManagedInstanceInInstancePool");
108+
}
109+
110+
/// <summary>
111+
/// Tests updating a managed instance in an instance pool
112+
/// </summary>
113+
[Fact]
114+
[Trait(Category.AcceptanceType, Category.CheckIn)]
115+
public void TestDeleteManagedInstanceInInstancePool()
116+
{
117+
RunPowerShellTest("Test-DeleteManagedInstanceInInstancePool");
118+
}
119+
120+
#endregion
121+
122+
#region Instance Pool Usages
123+
124+
/// <summary>
125+
/// Tests getting the instance pool usage
126+
/// </summary>
127+
[Fact]
128+
[Trait(Category.AcceptanceType, Category.CheckIn)]
129+
public void TestGetInstancePoolUsage()
130+
{
131+
RunPowerShellTest("Test-GetInstancePoolUsage");
132+
}
133+
134+
#endregion
135+
}
136+
}

0 commit comments

Comments
 (0)