Skip to content

Commit d5299d0

Browse files
toki95jtoroman
andauthored
NEW PR Powershell cmdlets for list/get/cancel managed server operation (#11452)
* Added input object and resource id as parameters. * PS commands for getting and canceling managed server operations * Added input object and resource id as parameters. * Adding entry to Change log * Addressing comments. * Adding file for generting help. * Fixing az sql * Update Stop-AzSqlInstanceOperation.md * Update Get-AzSqlInstanceOperation.md * Update ChangeLog.md * Update ChangeLog.md * Update GetAzureSqlManagedInstanceOperation.cs Co-authored-by: Jovana Toroman <[email protected]>
1 parent 33d86cc commit d5299d0

21 files changed

+22232
-28
lines changed

src/Accounts/Accounts/AzureRmAlias/Mappings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2319,7 +2319,9 @@
23192319
"Set-AzSqlDatabaseServerAuditingPolicy": "Set-AzureRmSqlDatabaseServerAuditingPolicy",
23202320
"Use-AzSqlDatabaseServerAuditingPolicy": "Use-AzureRmSqlDatabaseServerAuditingPolicy",
23212321
"Get-AzSqlDatabaseLongTermRetentionPolicy": "Get-AzureRmSqlDatabaseLongTermRetentionPolicy",
2322-
"Set-AzSqlDatabaseLongTermRetentionPolicy": "Set-AzureRmSqlDatabaseLongTermRetentionPolicy"
2322+
"Set-AzSqlDatabaseLongTermRetentionPolicy": "Set-AzureRmSqlDatabaseLongTermRetentionPolicy",
2323+
"Get-AzSqlInstanceOperation": "Get-AzureRmSqlInstanceOperation",
2324+
"Stop-AzSqlInstanceOperation": "Stop-AzureRmSqlInstanceOperation"
23232325
},
23242326
"Az.Storage": {
23252327
"Get-AzStorageAccount": "Get-AzureRmStorageAccount",

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,15 @@ function Get-VNetName
566566
return getAssetName
567567
}
568568

569+
<#
570+
.SYNOPSIS
571+
Gets valid managed instance operation name
572+
#>
573+
function Get-ManagedInstanceOperationName
574+
{
575+
return getAssetName
576+
}
577+
569578
<#
570579
.SYNOPSIS
571580
Gets test mode - 'Record' or 'Playback'
@@ -929,6 +938,34 @@ function Create-ManagedInstanceForTest ($resourceGroup, $subnetId)
929938
return $managedInstance
930939
}
931940

941+
<#
942+
.SYNOPSIS
943+
Asyn update of hardware generation on Sql managed instance
944+
#>
945+
function Update-ManagedInstanceGenerationForTest ($resourceGroup, $managedInstance)
946+
{
947+
$computeGeneration = "Gen5"
948+
949+
$managedInstance = Set-AzSqlInstance -ResourceGroupName $resourceGroup.ResourceGroupName -Name $managedInstance.ManagedInstanceName `
950+
-ComputeGeneration $computeGeneration -Force -AsJob
951+
952+
return $managedInstance
953+
}
954+
955+
<#
956+
.SYNOPSIS
957+
Sync update of storage on Sql managed instance
958+
#>
959+
function Update-ManagedInstanceStorageForTest ($resourceGroup, $managedInstance)
960+
{
961+
$storageSize = 928
962+
963+
$managedInstance = Set-AzSqlInstance -ResourceGroupName $resourceGroup.ResourceGroupName -Name $managedInstance.ManagedInstanceName `
964+
-StorageSizeInGb $storageSize -Force
965+
966+
return $managedInstance
967+
}
968+
932969
<#
933970
.SYNOPSIS
934971
Creates a managed instance in an instance pool
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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.ServiceManagement.Common.Models;
17+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
18+
using Xunit;
19+
using Xunit.Abstractions;
20+
using RestTestFramework = Microsoft.Rest.ClientRuntime.Azure.TestFramework;
21+
22+
namespace Microsoft.Azure.Commands.Sql.Test.ScenarioTests
23+
{
24+
public class ManagedInstanceOperationScenarioTests : SqlTestsBase
25+
{
26+
protected override void SetupManagementClients(RestTestFramework.MockContext context)
27+
{
28+
var sqlClient = GetSqlClient(context);
29+
var newResourcesClient = GetResourcesClient(context);
30+
var networkClient = GetNetworkClient(context);
31+
Helper.SetupSomeOfManagementClients(sqlClient, newResourcesClient, networkClient);
32+
}
33+
34+
public ManagedInstanceOperationScenarioTests(ITestOutputHelper output) : base(output)
35+
{
36+
////base.resourceTypesToIgnoreApiVersion = new string[] { "Microsoft.Sql/managedInstance/operations" };
37+
}
38+
39+
[Fact]
40+
[Trait(Category.AcceptanceType, Category.CheckIn)]
41+
public void TestGetManagedInstanceOperation()
42+
{
43+
RunPowerShellTest("Test-GetManagedInstanceOperation");
44+
}
45+
46+
[Fact]
47+
[Trait(Category.AcceptanceType, Category.CheckIn)]
48+
public void TestStopManagedInstanceOperation()
49+
{
50+
RunPowerShellTest("Test-StopManagedInstanceOperation");
51+
}
52+
}
53+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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+
# Location to use for provisioning test managed instances
16+
$instanceLocation = "eastus"
17+
18+
<#
19+
.SYNOPSIS
20+
Tests Getting a managedInstance operation
21+
.DESCRIPTION
22+
SmokeTest
23+
#>
24+
function Test-GetManagedInstanceOperation
25+
{
26+
# Setup
27+
$rg = Create-ResourceGroupForTest
28+
$vnetName = "cl_initial"
29+
$subnetName = "CooL"
30+
31+
# Setup VNET
32+
$virtualNetwork1 = CreateAndGetVirtualNetworkForManagedInstance $vnetName $subnetName $rg.Location
33+
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName })[0].Id
34+
35+
# Initiate sync create of managed instance.
36+
$managedInstance = Create-ManagedInstanceForTest $rg $subnetId
37+
38+
try
39+
{
40+
# Get all operations on managed instance.
41+
$all = Get-AzSqlInstanceOperation -ResourceGroupName $rg.ResourceGroupName -ManagedInstanceName $managedInstance.ManagedInstanceName
42+
Assert-AreEqual 1 $all.Count
43+
44+
# Get single operation on managed instance.
45+
$firstOperation = Get-AzSqlInstanceOperation -ResourceGroupName $rg.ResourceGroupName -ManagedInstanceName $managedInstance.ManagedInstanceName -Name ($all | Select-Object -index 0).Name
46+
Assert-AreEqual $firstOperation.OperationFriendlyName "UPDATE MANAGED SERVER"
47+
Assert-AreEqual $firstOperation.PercentComplete 100
48+
Assert-StartsWith $firstOperation.State "Succeeded"
49+
Assert-AreEqual $firstOperation.IsCancellable $false
50+
51+
# Initiate sync update of storage (this operation can not be canceled nor during its execution or after it has finsihed).
52+
$updatedManagedInstance = Update-ManagedInstanceStorageForTest $rg $managedInstance
53+
54+
# Get all operations on managed instance.
55+
$all = Get-AzSqlInstanceOperation -ResourceGroupName $rg.ResourceGroupName -ManagedInstanceName $managedInstance.ManagedInstanceName
56+
while($all.Count -ne 2) { $all = Get-AzSqlInstanceOperation -ResourceGroupName $rg.ResourceGroupName -ManagedInstanceName $managedInstance.ManagedInstanceName }
57+
58+
# Get single operation on managed instance.
59+
$secondOperation = Get-AzSqlInstanceOperation -ResourceGroupName $rg.ResourceGroupName -ManagedInstanceName $managedInstance.ManagedInstanceName -Name ($all | Select-Object -index 1).Name
60+
Assert-AreEqual $secondOperation.OperationFriendlyName "UPDATE MANAGED SERVER"
61+
Assert-AreEqual $secondOperation.PercentComplete 100
62+
Assert-StartsWith $firstOperation.State "Succeeded"
63+
Assert-AreEqual $secondOperation.IsCancellable $false
64+
}
65+
finally
66+
{
67+
Remove-ResourceGroupForTest $rg
68+
}
69+
}
70+
71+
<#
72+
.SYNOPSIS
73+
Tests Removing a managedInstance
74+
.DESCRIPTION
75+
SmokeTest
76+
#>
77+
function Test-StopManagedInstanceOperation
78+
{
79+
# Setup
80+
$rg = Create-ResourceGroupForTest
81+
$vnetName = "cl_initial"
82+
$subnetName = "CooL"
83+
84+
# Setup VNET
85+
$virtualNetwork1 = CreateAndGetVirtualNetworkForManagedInstance $vnetName $subnetName $rg.Location
86+
$subnetId = $virtualNetwork1.Subnets.where({ $_.Name -eq $subnetName })[0].Id
87+
88+
# Initiate sync create of managed instance.
89+
$managedInstance = Create-ManagedInstanceForTest $rg $subnetId
90+
91+
try
92+
{
93+
# Get all operations on managed instance.
94+
$all = Get-AzSqlInstanceOperation -ResourceGroupName $rg.ResourceGroupName -ManagedInstanceName $managedInstance.ManagedInstanceName
95+
Assert-AreEqual 1 $all.Count
96+
97+
# Verify that create operation has finished.
98+
$firstOperation = Get-AzSqlInstanceOperation -ResourceGroupName $rg.ResourceGroupName -ManagedInstanceName $managedInstance.ManagedInstanceName -Name ($all | Select-Object -index 0).Name
99+
Assert-AreEqual $firstOperation.OperationFriendlyName "UPDATE MANAGED SERVER"
100+
Assert-AreEqual $firstOperation.PercentComplete 100
101+
Assert-StartsWith $firstOperation.State "Succeeded"
102+
Assert-AreEqual $firstOperation.IsCancellable $false
103+
104+
# Verify that cancel is not allowed on finished operations.
105+
Assert-Throws { Stop-AzSqlInstanceOperation -ResourceGroupName $rg.ResourceGroupName -ManagedInstanceName $managedInstance.ManagedInstanceName -Name $firstOperation.Name -Force }
106+
107+
# Initiate async update of hardware generation (this operation is cancelable).
108+
$updatedManagedInstance = Update-ManagedInstanceGenerationForTest $rg $managedInstance
109+
110+
# Get all operations on managed instance.
111+
$all = Get-AzSqlInstanceOperation -ResourceGroupName $rg.ResourceGroupName -ManagedInstanceName $managedInstance.ManagedInstanceName
112+
113+
# Wait for second operation to be cancelable, then initate cancel.
114+
while($all.Count -ne 2) { $all = Get-AzSqlInstanceOperation -ResourceGroupName $rg.ResourceGroupName -ManagedInstanceName $managedInstance.ManagedInstanceName }
115+
$secondOperation = $all | Select-Object -index 1
116+
while($secondOperation.IsCancellable -eq $false) { $secondOperation = Get-AzSqlInstanceOperation -ResourceGroupName $rg.ResourceGroupName -ManagedInstanceName $managedInstance.ManagedInstanceName -Name $secondOperation.Name }
117+
Stop-AzSqlInstanceOperation -ResourceGroupName $rg.ResourceGroupName -ManagedInstanceName $managedInstance.ManagedInstanceName -Name $secondOperation.Name -Force
118+
119+
# Wait for second operaiton to be cancelled and verify fields.
120+
while($secondOperation.State -ne "Cancelled") { $secondOperation = Get-AzSqlInstanceOperation -ResourceGroupName $rg.ResourceGroupName -ManagedInstanceName $managedInstance.ManagedInstanceName -Name $secondOperation.Name }
121+
Assert-AreEqual $secondOperation.OperationFriendlyName "UPDATE MANAGED SERVER"
122+
Assert-AreEqual $secondOperation.PercentComplete 100
123+
Assert-AreEqual $secondOperation.IsCancellable $false
124+
}
125+
finally
126+
{
127+
Remove-ResourceGroupForTest $rg
128+
}
129+
}

0 commit comments

Comments
 (0)