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