|
| 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 | +} |
0 commit comments