Skip to content

Commit 8f091da

Browse files
authored
Merge pull request Azure#9203 from jaredmoo/instanceSizeOptional
Make New-AzSqlInstance -StorageSizeInGB parameter optional
2 parents c410675 + fc4c698 commit 8f091da

File tree

11 files changed

+12648
-3415
lines changed

11 files changed

+12648
-3415
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function Create-BasicManagedTestEnvironmentWithParams ($params, $location)
204204
$vnetName = "cl_initial"
205205
$subnetName = "Cool"
206206
$virtualNetwork1 = CreateAndGetVirtualNetworkForManagedInstance $vnetName $subnetName
207-
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName }).Id
207+
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName })[0].Id
208208
$credentials = Get-ServerCredential
209209
$licenseType = "BasePrice"
210210
$storageSizeInGB = 32
@@ -214,7 +214,7 @@ function Create-BasicManagedTestEnvironmentWithParams ($params, $location)
214214

215215
$managedInstance = New-AzureRmSqlInstance -ResourceGroupName $params.rgname -Name $params.serverName `
216216
-Location $location -AdministratorCredential $credentials -SubnetId $subnetId `
217-
-LicenseType $licenseType -StorageSizeInGB $storageSizeInGB -Vcore $vCore -SkuName $skuName
217+
-Vcore $vCore -SkuName $skuName
218218

219219
New-AzureRmSqlInstanceDatabase -ResourceGroupName $params.rgname -InstanceName $params.serverName -Name $params.databaseName -Collation $collation
220220
}
@@ -700,21 +700,24 @@ function Create-ManagedInstanceForTest ($resourceGroup, $subnetId)
700700
{
701701
$managedInstanceName = Get-ManagedInstanceName
702702
$credentials = Get-ServerCredential
703-
$licenseType = "BasePrice"
704-
$storageSizeInGB = 32
705703
$vCore = 16
706704
$skuName = "GP_Gen4"
707705

708706
$managedInstance = New-AzSqlInstance -ResourceGroupName $resourceGroup.ResourceGroupName -Name $managedInstanceName `
709707
-Location $resourceGroup.Location -AdministratorCredential $credentials -SubnetId $subnetId `
710-
-LicenseType $licenseType -StorageSizeInGB $storageSizeInGB -Vcore $vCore -SkuName $skuName
708+
-Vcore $vCore -SkuName $skuName
711709

712710
return $managedInstance
713711
}
714712

715713
<#
716714
.SYNOPSIS
717715
Create a virtual network
716+
717+
If resource group $resourceGroupName does not exist, then please create it before running the test.
718+
We deliberately do not create it, because if we did then ResourceGroupCleaner (inside MockContext) would delete it
719+
at the end of the test, which prevents us from reusing the subnet and therefore massively slows down
720+
managed instance scenario tests.
718721
#>
719722
function CreateAndGetVirtualNetworkForManagedInstance ($vnetName, $subnetName, $location = "westcentralus", $resourceGroupName = "cl_one")
720723
{

src/Sql/Sql.Test/ScenarioTests/ManagedDatabaseBackupTests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function Test-ManagedLiveDatabaseShortTermRetentionPolicy
2525

2626
# Setup VNET
2727
$virtualNetwork1 = CreateAndGetVirtualNetworkForManagedInstance $vnetName $subnetName $rg.Location
28-
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName }).Id
28+
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName })[0].Id
2929

3030
$managedInstance = Create-ManagedInstanceForTest $rg $subnetId
3131

@@ -97,7 +97,7 @@ function Test-ManagedDeletedDatabaseShortTermRetentionPolicy
9797

9898
# Setup VNET
9999
$virtualNetwork1 = CreateAndGetVirtualNetworkForManagedInstance $vnetName $subnetName $rg.Location
100-
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName }).Id
100+
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName })[0].Id
101101

102102
$managedInstance = Create-ManagedInstanceForTest $rg $subnetId
103103

src/Sql/Sql.Test/ScenarioTests/ManagedDatabaseCrudScenarioTests.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function Test-CreateManagedDatabase
2525

2626
# Setup VNET
2727
$virtualNetwork1 = CreateAndGetVirtualNetworkForManagedInstance $vnetName $subnetName $rg.Location
28-
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName }).Id
28+
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName })[0].Id
2929

3030
$managedInstance = Create-ManagedInstanceForTest $rg $subnetId
3131

@@ -75,7 +75,7 @@ function Test-GetManagedDatabase
7575

7676
# Setup VNET
7777
$virtualNetwork1 = CreateAndGetVirtualNetworkForManagedInstance $vnetName $subnetName $rg.Location
78-
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName }).Id
78+
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName })[0].Id
7979

8080
$managedInstance = Create-ManagedInstanceForTest $rg $subnetId
8181

@@ -130,7 +130,7 @@ function Test-RemoveManagedDatabase
130130

131131
# Setup VNET
132132
$virtualNetwork1 = CreateAndGetVirtualNetworkForManagedInstance $vnetName $subnetName $rg.Location
133-
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName }).Id
133+
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName })[0].Id
134134

135135
$managedInstance = Create-ManagedInstanceForTest $rg $subnetId
136136

@@ -200,7 +200,7 @@ function Test-RestoreManagedDatabase
200200

201201
# Setup VNET
202202
$virtualNetwork1 = CreateAndGetVirtualNetworkForManagedInstance $vnetName $subnetName $rg.Location
203-
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName }).Id
203+
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName })[0].Id
204204

205205
$managedInstance = Create-ManagedInstanceForTest $rg $subnetId
206206
$managedInstance2 = Create-ManagedInstanceForTest $rg2 $subnetId

src/Sql/Sql.Test/ScenarioTests/ManagedInstanceCrudScenarioTests.ps1

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
# limitations under the License.
1313
# ----------------------------------------------------------------------------------
1414

15+
# Location to use for provisioning test managed instances
16+
$instanceLocation = "eastus"
17+
1518
<#
1619
.SYNOPSIS
1720
Tests creating a managed instance
@@ -37,9 +40,9 @@ function Test-CreateManagedInstance
3740
$proxyOverride = "Proxy"
3841
try
3942
{
40-
# Setup VNET
43+
# Setup VNET
4144
$virtualNetwork1 = CreateAndGetVirtualNetworkForManagedInstance $vnetName $subnetName $rg.Location "newprovisioningtest"
42-
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName }).Id
45+
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName })[0].Id
4346

4447
# With SKU name specified
4548
$job = New-AzSqlInstance -ResourceGroupName $rg.ResourceGroupName -Name $managedInstanceName `
@@ -109,9 +112,9 @@ function Test-SetManagedInstance
109112
$vnetName = "vnet-newprovisioningtest3"
110113
$subnetName = "ManagedInstance"
111114

112-
# Setup VNET
115+
# Setup VNET
113116
$virtualNetwork1 = CreateAndGetVirtualNetworkForManagedInstance $vnetName $subnetName $rg.Location "newprovisioningtest"
114-
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName }).Id
117+
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName })[0].Id
115118

116119
$managedInstance = Create-ManagedInstanceForTest $rg $subnetId
117120

@@ -125,14 +128,14 @@ function Test-SetManagedInstance
125128

126129
$managedInstance1 = Set-AzSqlInstance -ResourceGroupName $rg.ResourceGroupName -Name $managedInstance.ManagedInstanceName `
127130
-AdministratorPassword $credentials.Password -LicenseType $licenseType -StorageSizeInGB $storageSizeInGB -Vcore $vCore -Force
128-
131+
129132
Assert-AreEqual $managedInstance1.ManagedInstanceName $managedInstance.ManagedInstanceName
130133
Assert-AreEqual $managedInstance1.AdministratorLogin $managedInstance.AdministratorLogin
131134
Assert-AreEqual $managedInstance1.LicenseType $licenseType
132135
Assert-AreEqual $managedInstance1.VCores $vCore
133136
Assert-AreEqual $managedInstance1.StorageSizeInGB $storageSizeInGB
134137
Assert-StartsWith ($managedInstance1.ManagedInstanceName + ".") $managedInstance1.FullyQualifiedDomainName
135-
138+
136139
# Test using piping
137140
$credentials = Get-ServerCredential
138141

@@ -158,7 +161,7 @@ function Test-SetManagedInstance
158161

159162
$managedInstance3 = Set-AzSqlInstance -InputObject $managedInstance `
160163
-AdministratorPassword $credentials.Password -LicenseType $licenseType -StorageSizeInGB $storageSizeInGB -Vcore $vCore -Force
161-
164+
162165
Assert-AreEqual $managedInstance3.ManagedInstanceName $managedInstance.ManagedInstanceName
163166
Assert-AreEqual $managedInstance3.AdministratorLogin $managedInstance.AdministratorLogin
164167
Assert-AreEqual $managedInstance3.LicenseType $licenseType
@@ -177,7 +180,7 @@ function Test-SetManagedInstance
177180
$managedInstance4 = Set-AzSqlInstance -ResourceId $managedInstance.Id `
178181
-AdministratorPassword $credentials.Password -LicenseType $licenseType -StorageSizeInGB $storageSizeInGB -Vcore $vCore `
179182
-PublicDataEndpointEnabled $publicDataEndpointEnabled -ProxyOverride $proxyOverride -Force
180-
183+
181184
Assert-AreEqual $managedInstance4.ManagedInstanceName $managedInstance.ManagedInstanceName
182185
Assert-AreEqual $managedInstance4.AdministratorLogin $managedInstance.AdministratorLogin
183186
Assert-AreEqual $managedInstance4.LicenseType $licenseType
@@ -202,14 +205,14 @@ function Test-SetManagedInstance
202205
function Test-GetManagedInstance
203206
{
204207
# Setup
205-
$rg = Create-ResourceGroupForTest
206-
$rg1 = Create-ResourceGroupForTest
208+
$rg = Create-ResourceGroupForTest $instanceLocation
209+
$rg1 = Create-ResourceGroupForTest $instanceLocation
207210
$vnetName = "cl_initial"
208211
$subnetName = "CooL"
209212

210-
# Setup VNET
211-
$virtualNetwork1 = CreateAndGetVirtualNetworkForManagedInstance $vnetName $subnetName $rg.Location
212-
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName }).Id
213+
# Setup VNET
214+
$virtualNetwork1 = CreateAndGetVirtualNetworkForManagedInstance $vnetName $subnetName $rg.Location "powershell_mi"
215+
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName })[0].Id
213216

214217
$managedInstance1 = Create-ManagedInstanceForTest $rg $subnetId
215218
$managedInstance2 = Create-ManagedInstanceForTest $rg1 $subnetId
@@ -225,7 +228,7 @@ function Test-GetManagedInstance
225228
Assert-AreEqual $managedInstance1.LicenseType $resp1.LicenseType
226229
Assert-AreEqual $managedInstance1.VCores $resp1.VCores
227230
Assert-AreEqual $managedInstance1.StorageSizeInGB $resp1.StorageSizeInGB
228-
231+
229232
$all = Get-AzSqlInstance -ResourceGroupName $rg.ResourceGroupName -Name *
230233
Assert-AreEqual 1 $all.Count
231234

@@ -252,20 +255,20 @@ function Test-GetManagedInstance
252255
function Test-RemoveManagedInstance
253256
{
254257
# Setup
255-
$rg = Create-ResourceGroupForTest
258+
$rg = Create-ResourceGroupForTest $instanceLocation
256259
$vnetName = "cl_initial"
257260
$subnetName = "CooL"
258261

259-
# Setup VNET
260-
$virtualNetwork1 = CreateAndGetVirtualNetworkForManagedInstance $vnetName $subnetName $rg.Location
261-
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName }).Id
262+
# Setup VNET
263+
$virtualNetwork1 = CreateAndGetVirtualNetworkForManagedInstance $vnetName $subnetName $rg.Location "powershell_mi"
264+
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName })[0].Id
262265

263266
try
264267
{
265268
# Test using parameters
266269
$managedInstance1 = Create-ManagedInstanceForTest $rg $subnetId
267270
Remove-AzSqlInstance -ResourceGroupName $rg.ResourceGroupName -Name $managedInstance1.ManagedInstanceName -Force
268-
271+
269272
# Test using InputObject
270273
$managedInstance2 = Create-ManagedInstanceForTest $rg $subnetId
271274
Remove-AzSqlInstance -InputObject $managedInstance2 -Force
@@ -298,9 +301,9 @@ function Test-CreateManagedInstanceWithIdentity
298301
$vnetName = "cl_initial"
299302
$subnetName = "CooL"
300303

301-
# Setup VNET
304+
# Setup VNET
302305
$virtualNetwork1 = CreateAndGetVirtualNetworkForManagedInstance $vnetName $subnetName $rg.Location
303-
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName }).Id
306+
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName })[0].Id
304307

305308
$managedInstanceName = Get-ManagedInstanceName
306309
$version = "12.0"

src/Sql/Sql.Test/ScenarioTests/VulnerabilityAssessmentMiTests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function Test-VulnerabilityAssessmentManagedInstanceSettingsTest
2525
$vnetName = "cl_initial"
2626
$subnetName = "Cool"
2727
$virtualNetwork1 = CreateAndGetVirtualNetworkForManagedInstance $vnetName $subnetName
28-
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName }).Id
28+
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName })[0].Id
2929
$credentials = Get-ServerCredential
3030
$licenseType = "BasePrice"
3131
$storageSizeInGB = 32

0 commit comments

Comments
 (0)