Skip to content

Commit a953e9a

Browse files
v-nestanNemanja
andauthored
Add -AsJob to Remove-AzSqlInstande and -SubnetId to Set-AzSqlInstance (#15578)
* Iteration 1: - Add -AsJob parameter to the Remove-AzSqlInstance - Add the -SubnetId parameter to support the X-subnet update SLO - Updated tests to validate these two changes - Added new recordings - Updated TestSetManagedInstance test to use the new environment, recorded it and removed the skip flag - Updated TestCreateUpdateManagedInstanceWithMinimalTlsVersion test to use the new environment, recorded it and removed the skip flag * Iteration 2: - Updated ChangeLog.md file * Iteration 3: - Updated help markdown for the new parameter in Remove-AzSqlInstance * Iteration 5: - Generated Remote-AzSqlInstance.md uring platyPS * Iteration 6: Updated -SubnetId help message and help markdown file. Co-authored-by: Nemanja <[email protected]>
1 parent 81f7f9d commit a953e9a

File tree

11 files changed

+4104
-4264
lines changed

11 files changed

+4104
-4264
lines changed

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -961,16 +961,27 @@ function Get-DNSNameBasedOnEnvironment ()
961961
.SYNOPSIS
962962
Creates the test environment needed to perform the Sql managed instance CRUD tests
963963
#>
964-
function Create-ManagedInstanceForTest ($resourceGroup, $subnetId)
964+
function Create-ManagedInstanceForTest ($resourceGroup, $subnetId, $vCore)
965965
{
966966
$managedInstanceName = Get-ManagedInstanceName
967967
$credentials = Get-ServerCredential
968-
$vCore = 16
968+
if($vCore -eq $null)
969+
{
970+
$vCore = 16
971+
}
972+
969973
$skuName = "GP_Gen5"
970974

971975
$managedInstance = New-AzSqlInstance -ResourceGroupName $resourceGroup.ResourceGroupName -Name $managedInstanceName `
972976
-Location $resourceGroup.Location -AdministratorCredential $credentials -SubnetId $subnetId `
973-
-Vcore $vCore -SkuName $skuName -AssignIdentity
977+
-Vcore $vCore -SkuName $skuName -AssignIdentity
978+
979+
# The previous command keeps polling until managed instance becomes ready. However, it can happen that the managed instance
980+
# becomes ready but the create operation is still in progress. Because of that, we should wait until the operation is completed.
981+
if([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -eq "Record"){
982+
Start-Sleep -s 30
983+
}
984+
974985

975986
return $managedInstance
976987
}
@@ -1029,14 +1040,14 @@ function Get-InstancePoolTestProperties()
10291040
$instancePoolTestProperties = @{
10301041
resourceGroup = "ps3995"
10311042
name = "myinstancepool1"
1032-
subnetName = "ManagedInsanceSubnet"
1033-
vnetName = "MIVirtualNetwork"
1043+
subnetName = "ManagedInstance"
1044+
vnetName = "vnet-portal-testing"
10341045
tags = $tags
10351046
computeGen = "Gen5"
10361047
edition = "GeneralPurpose"
10371048
location = "westeurope"
10381049
licenseType = "LicenseIncluded"
1039-
vCores = 16
1050+
vCores = 4
10401051
}
10411052
return $instancePoolTestProperties
10421053
}

src/Sql/Sql.Test/ScenarioTests/ManagedInstanceCrudScenarioTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void TestCreateManagedInstance()
4343
RunPowerShellTest("Test-CreateManagedInstance");
4444
}
4545

46-
[Fact(Skip = "Skip due to long setup time for managed instance")]
46+
[Fact]
4747
[Trait(Category.AcceptanceType, Category.CheckIn)]
4848
public void TestSetManagedInstance()
4949
{
@@ -71,7 +71,7 @@ public void TestCreateManagedInstanceWithIdentity()
7171
RunPowerShellTest("Test-CreateManagedInstanceWithIdentity");
7272
}
7373

74-
[Fact(Skip = "Skip due to bug in backend which is currently deploying")]
74+
[Fact]
7575
[Trait(Category.AcceptanceType, Category.CheckIn)]
7676
public void TestCreateUpdateManagedInstanceWithMinimalTlsVersion()
7777
{

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

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,17 @@ function Test-SetManagedInstance
112112
{
113113
# Setup
114114
$rg = Create-ResourceGroupForTest "westeurope"
115-
$vnetName = "vnet-pcresizeandcreate"
115+
$vnetName = "vnet-portal-testing"
116116
$subnetName = "ManagedInstance"
117+
$targetSubnetResourceId = "/subscriptions/62e48210-5e43-423e-889b-c277f3e08c39/resourceGroups/portalrg/providers/Microsoft.Network/virtualNetworks/vnet-portal-testing/subnets/ManagedInstance2"
118+
$vCore = 4
119+
$vnetRgName = "portalrg"
117120

118121
# Setup VNET
119-
$virtualNetwork1 = CreateAndGetVirtualNetworkForManagedInstance $vnetName $subnetName $rg.Location "toki"
122+
$virtualNetwork1 = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $vnetRgName
120123
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName })[0].Id
121124

122-
$managedInstance = Create-ManagedInstanceForTest $rg $subnetId
125+
$managedInstance = Create-ManagedInstanceForTest $rg $subnetId $vCore
123126

124127
try
125128
{
@@ -157,7 +160,7 @@ function Test-SetManagedInstance
157160
# Test Set using InputObject
158161
$credentials = Get-ServerCredential
159162
$licenseType = "BasePrice"
160-
$storageSizeInGB = 64
163+
$storageSizeInGB = 128
161164

162165
$managedInstance3 = Set-AzSqlInstance -InputObject $managedInstance `
163166
-AdministratorPassword $credentials.Password -LicenseType $licenseType -StorageSizeInGB $storageSizeInGB -Force
@@ -172,7 +175,7 @@ function Test-SetManagedInstance
172175
# Test Set using ResourceId
173176
$credentials = Get-ServerCredential
174177
$licenseType = "BasePrice"
175-
$storageSizeInGB = 32
178+
$storageSizeInGB = 256
176179
$publicDataEndpointEnabled = $true
177180
$proxyOverride = "Proxy"
178181

@@ -191,10 +194,8 @@ function Test-SetManagedInstance
191194
# Test edition change using Edition
192195
$credentials = Get-ServerCredential
193196
$edition = "BusinessCritical"
194-
$vCore = 16
195197

196-
$managedInstance6 = Set-AzSqlInstance -ResourceGroupName $rg.ResourceGroupName -Name $managedInstance.ManagedInstanceName -Vcore $vCore `
197-
-Edition $edition -Force
198+
$managedInstance6 = Set-AzSqlInstance -ResourceGroupName $rg.ResourceGroupName -Name $managedInstance.ManagedInstanceName -Edition $edition -Force
198199

199200
Assert-AreEqual $managedInstance6.ManagedInstanceName $managedInstance.ManagedInstanceName
200201
Assert-AreEqual $managedInstance6.AdministratorLogin $managedInstance4.AdministratorLogin
@@ -203,6 +204,17 @@ function Test-SetManagedInstance
203204
Assert-AreEqual $managedInstance6.Sku.Tier $edition
204205
Assert-AreEqual $managedInstance6.Sku.Family $managedInstance4.Sku.Family
205206
Assert-StartsWith ($managedInstance6.ManagedInstanceName + ".") $managedInstance6.FullyQualifiedDomainName
207+
208+
# Test cross-subnet update SLO. Since the feature is still not rolled-out, the operation should fail.
209+
try
210+
{
211+
Set-AzSqlInstance -Name $managedInstance.ManagedInstanceName -ResourceGroupName $rg.ResourceGroupName -SubnetId $targetSubnetResourceId -Force
212+
}
213+
catch
214+
{
215+
$ErrorMessage = $_.Exception.Message
216+
Assert-AreEqual True $ErrorMessage.Contains("Long running operation failed with status 'Failed'. Additional Info:'Subnet resource ID '"+$targetSubnetResourceId+"' is invalid. Please provide a correct resource Id for the target subnet.'")
217+
}
206218
}
207219
finally
208220
{
@@ -270,31 +282,41 @@ function Test-RemoveManagedInstance
270282
{
271283
# Setup
272284
$rg = Create-ResourceGroupForTest "westeurope"
273-
$vnetName = "MIVirtualNetwork"
274-
$subnetName = "ManagedInsanceSubnet"
285+
$vnetRgName = "portalrg"
286+
$vnetName = "vnet-portal-testing"
287+
$subnetName = "ManagedInstance"
288+
$vCore = 4
275289

276290
# Setup VNET
277-
$virtualNetwork1 = CreateAndGetVirtualNetworkForManagedInstance $vnetName $subnetName $rg.Location "v-urmila"
291+
$virtualNetwork1 = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $vnetRgName
278292
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName })[0].Id
279293

280294
try
281295
{
282296
# Test using parameters
283-
$managedInstance1 = Create-ManagedInstanceForTest $rg $subnetId
297+
$managedInstance1 = Create-ManagedInstanceForTest $rg $subnetId $vCore
284298
Remove-AzSqlInstance -ResourceGroupName $rg.ResourceGroupName -Name $managedInstance1.ManagedInstanceName -Force
285-
299+
286300
# Test using InputObject
287-
$managedInstance2 = Create-ManagedInstanceForTest $rg $subnetId
301+
$managedInstance2 = Create-ManagedInstanceForTest $rg $subnetId $vCore
288302
Remove-AzSqlInstance -InputObject $managedInstance2 -Force
289303

290304
# Test using ResourceId
291-
$managedInstance3 = Create-ManagedInstanceForTest $rg $subnetId
305+
$managedInstance3 = Create-ManagedInstanceForTest $rg $subnetId $vCore
292306
Remove-AzSqlInstance -ResourceId $managedInstance3.Id -Force
293307

294308
# Test piping
295-
$managedInstance4 = Create-ManagedInstanceForTest $rg $subnetId
309+
$managedInstance4 = Create-ManagedInstanceForTest $rg $subnetId $vCore
296310
$managedInstance4 | Remove-AzSqlInstance -Force
297311

312+
# Test -AsJob
313+
$managedInstance5 = Create-ManagedInstanceForTest $rg $subnetId $vCore
314+
$job = Remove-AzSqlInstance -ResourceGroupName $rg.ResourceGroupName -Name $managedInstance5.ManagedInstanceName -Force -AsJob
315+
$job | Wait-Job
316+
317+
Assert-AreEqual "Completed" $job.State
318+
Assert-AreEqual "Remove-AzSqlInstance" $job.Command
319+
298320
$all = Get-AzSqlInstance -ResourceGroupName $rg.ResourceGroupName
299321
Assert-AreEqual $all.Count 0
300322
}
@@ -352,10 +374,10 @@ function Test-CreateManagedInstanceWithIdentity
352374
function Test-CreateUpdateManagedInstanceWithMinimalTlsVersion
353375
{
354376
# Setup
355-
$location = "eastus2euap"
356-
$rgName = "DejanDuVnetRG"
357-
$subnetId = "/subscriptions/a8c9a924-06c0-4bde-9788-e7b1370969e1/resourceGroups/AndyPG/providers/Microsoft.Network/virtualNetworks/prepare-cl-nimilj/subnets/default"
358-
$managedInstanceName = "ps123"
377+
$rg = Create-ResourceGroupForTest
378+
$location = "westeurope"
379+
$subnetId = "/subscriptions/62e48210-5e43-423e-889b-c277f3e08c39/resourceGroups/portalrg/providers/Microsoft.Network/virtualNetworks/vnet-portal-testing/subnets/ManagedInstance"
380+
$managedInstanceName = Get-ManagedInstanceName
359381
$version = "12.0"
360382
$credentials = Get-ServerCredential
361383
$licenseType = "BasePrice"
@@ -371,7 +393,7 @@ function Test-CreateUpdateManagedInstanceWithMinimalTlsVersion
371393
try
372394
{
373395
# With SKU name specified
374-
$job = New-AzSqlInstance -ResourceGroupName $rgName -Name $managedInstanceName `
396+
$job = New-AzSqlInstance -ResourceGroupName $rg.ResourceGroupName -Name $managedInstanceName `
375397
-Location $location -AdministratorCredential $credentials -SubnetId $subnetId `
376398
-LicenseType $licenseType -StorageSizeInGB $storageSizeInGB -Vcore $vCore -SkuName $skuName -Collation $collation `
377399
-TimezoneId $timezoneId -PublicDataEndpointEnabled -ProxyOverride $proxyOverride -MinimalTlsVersion $tls1_2 -AsJob
@@ -381,13 +403,19 @@ function Test-CreateUpdateManagedInstanceWithMinimalTlsVersion
381403
Assert-AreEqual $managedInstance1.ManagedInstanceName $managedInstanceName
382404
Assert-AreEqual $managedInstance1.MinimalTlsVersion $tls1_2
383405

384-
$managedInstance2 = Set-AzSqlInstance -MinimalTlsVersion $tls1_1 -ResourceGroupName $rgName -Name "ps123" -Force
406+
# Wait until create managed instance operation is completed.
407+
if([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -eq "Record"){
408+
Start-Sleep -s 30
409+
}
410+
411+
$managedInstance2 = Set-AzSqlInstance -MinimalTlsVersion $tls1_1 -ResourceGroupName $rg.ResourceGroupName -Name $managedInstanceName -Force
385412

386413
Assert-AreEqual $managedInstance2.MinimalTlsVersion $tls1_1
387414
}
388415
finally
389416
{
390-
Remove-AzSqlInstance -ResourceGroupName $rgName -Name $managedInstanceName -Force
417+
Remove-AzSqlInstance -ResourceGroupName $rg.ResourceGroupName -Name $managedInstanceName -Force
418+
Remove-ResourceGroupForTest $rg
391419
}
392420
}
393421

0 commit comments

Comments
 (0)