Skip to content

Commit 8d5cd68

Browse files
authored
Merge pull request Azure#10982 from ranishan/AgListnerCmdlet
Add cmdlets for Availability Group Listener resource of SqlVirtualMachine
2 parents d1ba239 + fe38248 commit 8d5cd68

30 files changed

+23314
-7
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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.SqlVirtualMachine.Test.ScenarioTests;
16+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using Xunit;
18+
using Xunit.Abstractions;
19+
20+
namespace Microsoft.Azure.Commands.AvailabilityGroupListener.Test.ScenarioTests
21+
{
22+
[Collection("SqlVirtualMachineTests")]
23+
public class AvailabilityGroupListenerTests : SqlVirtualMachineTestsBase
24+
{
25+
public AvailabilityGroupListenerTests(ITestOutputHelper output) : base(output)
26+
{
27+
}
28+
29+
[Fact]
30+
[Trait(Category.AcceptanceType, Category.CheckIn)]
31+
public void TestAvailabilityGroupListenerCreate()
32+
{
33+
RunPowerShellTest("Test-CreateAvailabilityGroupListener");
34+
}
35+
36+
[Fact]
37+
[Trait(Category.AcceptanceType, Category.CheckIn)]
38+
public void TestAvailabilityGroupListenerGet()
39+
{
40+
RunPowerShellTest("Test-GetAvailabilityGroupListener");
41+
}
42+
43+
[Fact]
44+
[Trait(Category.AcceptanceType, Category.CheckIn)]
45+
public void TestAvailabilityGroupListenerUpdate()
46+
{
47+
RunPowerShellTest("Test-UpdateAvailabilityGroupListener");
48+
}
49+
50+
[Fact]
51+
[Trait(Category.AcceptanceType, Category.CheckIn)]
52+
public void TestAvailabilityGroupListenerRemove()
53+
{
54+
RunPowerShellTest("Test-RemoveAvailabilityGroupListener");
55+
}
56+
}
57+
}
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
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+
<#
16+
.SYNOPSIS
17+
Create tests for Availability Group Listener
18+
#>
19+
function Test-CreateAvailabilityGroupListener
20+
{
21+
# Setup
22+
$previousErrorActionPreferenceValue = $ErrorActionPreference
23+
$ErrorActionPreference = "SilentlyContinue"
24+
$loadBalancer = Get-LoadBalancerResourceId
25+
$subnetId = Get-SubnetId
26+
$probePort = Get-ProbePort
27+
$sqlVMIds = Get-SqlVirtualMachineId
28+
$name = Get-AGListenerName
29+
$rgName = Get-AGListenerResourceGroup
30+
$groupName = Get-AgListenerGroupName
31+
$ipAddress = Get-IpAddress
32+
$port = Get-DefaultPort
33+
$agName = Get-AgName
34+
35+
try
36+
{
37+
# Create Sql VM with parameters
38+
$listener = New-AzAvailabilityGroupListener -AvailabilityGroupName $agName -LoadBalancerResourceId $loadBalancer -SubnetId $subnetId `
39+
-ProbePort $probePort -SqlVirtualMachineId $sqlVMIds -Name $name -ResourceGroupName $rgName -SqlVMGroupName $groupName -IpAddress $ipAddress
40+
Assert-NotNull $listener
41+
Assert-AreEqual $listener.Name $name
42+
Assert-AreEqual $listener.Port $port
43+
}
44+
finally
45+
{
46+
Remove-AzAvailabilityGroupListener -ResourceGroupName $rgName -SqlVMGroupName $groupName -Name $name
47+
$ErrorActionPreference = $previousErrorActionPreferenceValue
48+
}
49+
}
50+
51+
<#
52+
.SYNOPSIS
53+
Get\list tests for Availability Group Listener
54+
#>
55+
function Test-GetAvailabilityGroupListener
56+
{
57+
#Setup
58+
$previousErrorActionPreferenceValue = $ErrorActionPreference
59+
$ErrorActionPreference = "SilentlyContinue"
60+
$loadBalancer = Get-LoadBalancerResourceId
61+
$subnetId = Get-SubnetId
62+
$probePort = Get-ProbePort
63+
$sqlVMIds = Get-SqlVirtualMachineId
64+
$name = Get-AGListenerName
65+
$rgName = Get-AGListenerResourceGroup
66+
$groupName = Get-AgListenerGroupName
67+
$ipAddress = Get-IpAddress
68+
$port = Get-DefaultPort
69+
$agName = Get-AgName
70+
71+
try
72+
{
73+
$listener1 = New-AzAvailabilityGroupListener -AvailabilityGroupName $agName -LoadBalancerResourceId $loadBalancer -SubnetId $subnetId `
74+
-ProbePort $probePort -SqlVirtualMachineId $sqlVMIds -Name $name -ResourceGroupName $rgName -SqlVMGroupName $groupName -IpAddress $ipAddress
75+
$listener2 = Get-AzAvailabilityGroupListener -Name $name -ResourceGroupName $rgName -SqlVMGroupName $groupName
76+
Assert-NotNull $listener1
77+
Assert-NotNull $listener1
78+
Assert-AreEqual $listener1.Name $listener2.Name
79+
Assert-AreEqual $listener1.AvailabilityGroupName $listener2.AvailabilityGroupName
80+
Assert-AreEqual $listener1.Port $listener2.Port
81+
Assert-AreEqual $listener1.GroupName $listener2.GroupName
82+
}
83+
finally
84+
{
85+
Remove-AzAvailabilityGroupListener -ResourceGroupName $rgName -SqlVMGroupName $groupName -Name $name
86+
$ErrorActionPreference = $previousErrorActionPreferenceValue
87+
}
88+
}
89+
90+
<#
91+
.SYNOPSIS
92+
Update tests for Availability Group Listener
93+
#>
94+
function Test-UpdateAvailabilityGroupListener
95+
{
96+
#Setup
97+
$previousErrorActionPreferenceValue = $ErrorActionPreference
98+
$ErrorActionPreference = "SilentlyContinue"
99+
$loadBalancer = Get-LoadBalancerResourceId
100+
$subnetId = Get-SubnetId
101+
$probePort = Get-ProbePort
102+
$sqlVMIds = Get-SqlVirtualMachineId
103+
$name = Get-AGListenerName
104+
$rgName = Get-AGListenerResourceGroup
105+
$groupName = Get-AgListenerGroupName
106+
$ipAddress = Get-IpAddress
107+
$port = Get-DefaultPort
108+
$agName = Get-AgName
109+
110+
try
111+
{
112+
$listener1 = New-AzAvailabilityGroupListener -AvailabilityGroupName $agName -LoadBalancerResourceId $loadBalancer -SubnetId $subnetId `
113+
-ProbePort $probePort -SqlVirtualMachineId $sqlVMIds -Name $name -ResourceGroupName $rgName -SqlVMGroupName $groupName -IpAddress $ipAddress
114+
$listener1 = Get-AzAvailabilityGroupListener -ResourceId $listener1.ResourceId
115+
$listener2 = Update-AzAvailabilityGroupListener -Name $name -ResourceGroupName $rgName -SqlVMGroupName $groupName -SqlVirtualMachineId $sqlVMIds
116+
Assert-NotNull $listener1
117+
Assert-NotNull $listener1
118+
Assert-AreEqual $listener1.Name $listener2.Name
119+
Assert-AreEqual $listener1.AvailabilityGroupName $listener2.AvailabilityGroupName
120+
Assert-AreEqual $listener1.Port $listener2.Port
121+
Assert-AreEqual $listener1.GroupName $listener2.GroupName
122+
Assert-AreEqual $listener1.LoadBalancerConfigurations[0].SqlVirtualMachineInstances.count $listener2.LoadBalancerConfigurations[0].SqlVirtualMachineInstances.count
123+
}
124+
finally
125+
{
126+
Remove-AzAvailabilityGroupListener -ResourceGroupName $rgName -SqlVMGroupName $groupName -Name $name
127+
$ErrorActionPreference = $previousErrorActionPreferenceValue
128+
}
129+
}
130+
131+
<#
132+
.SYNOPSIS
133+
Remove tests for Availability Group Listener
134+
#>
135+
function Test-RemoveAvailabilityGroupListener
136+
{
137+
#Setup
138+
$previousErrorActionPreferenceValue = $ErrorActionPreference
139+
$ErrorActionPreference = "SilentlyContinue"
140+
$loadBalancer = Get-LoadBalancerResourceId
141+
$subnetId = Get-SubnetId
142+
$probePort = Get-ProbePort
143+
$sqlVMIds = Get-SqlVirtualMachineId
144+
$name = Get-AGListenerName
145+
$rgName = Get-AGListenerResourceGroup
146+
$groupName = Get-AgListenerGroupName
147+
$ipAddress = Get-IpAddress
148+
$port = Get-DefaultPort
149+
$agName = Get-AgName
150+
151+
try
152+
{
153+
$listener1 = New-AzAvailabilityGroupListener -AvailabilityGroupName $agName -LoadBalancerResourceId $loadBalancer -SubnetId $subnetId `
154+
-ProbePort $probePort -SqlVirtualMachineId $sqlVMIds -Name $name -ResourceGroupName $rgName -SqlVMGroupName $groupName -IpAddress $ipAddress
155+
Assert-NotNull $listener1
156+
157+
$listener1 = Remove-AzAvailabilityGroupListener -ResourceGroupName $rgName -SqlVMGroupName $groupName -Name $name
158+
$listenerList = Get-AzAvailabilityGroupListener -ResourceGroupName $rgName -SqlVMGroupName $groupName
159+
Assert-False {$listener1.Name -in $listenerList.Name}
160+
}
161+
finally
162+
{
163+
$ErrorActionPreference = $previousErrorActionPreferenceValue
164+
}
165+
}

src/SqlVirtualMachine/SqlVirtualMachine.Test/ScenarioTests/Common.ps1

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,62 @@ function Get-StorageaccountNameForTest()
150150
return $nr
151151
}
152152

153+
# Functions to get resources for Availability Group Listener
154+
# Currently there is not function to create Setup
155+
156+
function Get-LoadBalancerResourceId()
157+
{
158+
$loadBalancerResourceId = "/subscriptions/0009fc4d-e310-4e40-8e63-c48a23e9cdc1/resourceGroups/karthik-wcus2/providers/Microsoft.Network/loadBalancers/rlnaonlb4"
159+
return $loadBalancerResourceId
160+
}
161+
162+
function Get-SubnetId()
163+
{
164+
$subnetId = "/subscriptions/0009fc4d-e310-4e40-8e63-c48a23e9cdc1/resourceGroups/karthik-wcus2/providers/Microsoft.Network/virtualNetworks/DecTest-vnet/subnets/DecTest-subnet"
165+
return $subnetId
166+
}
167+
168+
function Get-ProbePort()
169+
{
170+
return 59999
171+
}
172+
173+
function Get-SqlVirtualMachineId()
174+
{
175+
$sqlVirtualMachineIds = "/subscriptions/0009fc4d-e310-4e40-8e63-c48a23e9cdc1/resourceGroups/rlnalwayson/providers/Microsoft.SqlVirtualMachine/SqlVirtualMachines/rlnvmag2","/subscriptions/0009fc4d-e310-4e40-8e63-c48a23e9cdc1/resourceGroups/rlnalwayson/providers/Microsoft.SqlVirtualMachine/SqlVirtualMachines/rlnagvm1"
176+
return $sqlVirtualMachineIds
177+
}
178+
179+
function Get-AGListenerName
180+
{
181+
return "rlnaonagl11"
182+
}
183+
184+
function Get-AGListenerResourceGroup
185+
{
186+
return "rlnAlwaysOn"
187+
}
188+
189+
function Get-AgListenerGroupName
190+
{
191+
return "rlnaonsqlgr2"
192+
}
193+
194+
function Get-IpAddress
195+
{
196+
return "10.0.0.31"
197+
}
198+
199+
function Get-DefaultPort()
200+
{
201+
return 1433
202+
}
203+
204+
function Get-AgName()
205+
{
206+
return "rlnaonag"
207+
}
208+
153209
<#
154210
.SYNOPSIS
155211
Checks that the sql virtual machines provided are equal

0 commit comments

Comments
 (0)