@@ -1117,4 +1117,190 @@ function Test-LoadBalancer-NicAssociationDuringCreate
1117
1117
# Cleanup
1118
1118
Clean - ResourceGroup $rgname
1119
1119
}
1120
+ }
1121
+
1122
+ <#
1123
+ . SYNOPSIS
1124
+ Tests creating new internal Load balancer and CRUD inbound nat pools on the load balancer
1125
+ #>
1126
+ function Test-LoadBalancerInboundNatPoolConfigCRUD-InternalLB
1127
+ {
1128
+ # Setup
1129
+ $rgname = Get-ResourceGroupName
1130
+ $vnetName = Get-ResourceName
1131
+ $subnetName = Get-ResourceName
1132
+ $publicIpName = Get-ResourceName
1133
+ $domainNameLabel = Get-ResourceName
1134
+ $lbName = Get-ResourceName
1135
+ $frontendName = Get-ResourceName
1136
+ $rglocation = " West US"
1137
+ $resourceTypeParent = " Microsoft.Network/loadBalancers"
1138
+ $location = " West US"
1139
+
1140
+ try
1141
+ {
1142
+ # Create the resource group
1143
+ $resourceGroup = New-AzureRmResourceGroup - Name $rgname - Location $rglocation - Tags @ {Name = " testtag" ; Value = " testval" }
1144
+
1145
+ # Create the Virtual Network
1146
+ $subnet = New-AzureRmVirtualNetworkSubnetConfig - Name $subnetName - AddressPrefix 10.0 .1.0 / 24
1147
+ $vnet = New-AzureRmvirtualNetwork - Name $vnetName - ResourceGroupName $rgname - Location $location - AddressPrefix 10.0 .0.0 / 16 - Subnet $subnet
1148
+
1149
+ # Create the publicip
1150
+ $publicip = New-AzureRmPublicIpAddress - ResourceGroupName $rgname - name $publicIpName - location $location - AllocationMethod Dynamic - DomainNameLabel $domainNameLabel
1151
+
1152
+ $frontend = New-AzureRmLoadBalancerFrontendIpConfig - Name $frontendName - SubnetId $vnet.Subnets [0 ].Id
1153
+ New-AzureRmLoadBalancer - Name $lbName - ResourceGroupName $rgname - Location $location - FrontendIpConfiguration $frontend
1154
+
1155
+ $lb = Get-AzureRmLoadBalancer - Name $lbName - ResourceGroupName $rgname
1156
+
1157
+ # Test InboundNatPool cmdlets
1158
+ $inboundNatPoolName = Get-ResourceName
1159
+ $lb = Get-AzureRmLoadBalancer - Name $lbName - ResourceGroupName $rgname
1160
+ $lb = $lb | Add-AzureRmLoadBalancerInboundNatPoolConfig - Name $inboundNatPoolName - FrontendIPConfigurationId $lb.FrontendIPConfigurations [0 ].Id - Protocol Tcp - FrontendPortRangeStart 3360 - FrontendPortRangeEnd 3362 - BackendPort 3370 | Set-AzureRmLoadBalancer
1161
+
1162
+ Assert-AreEqual 1 @ ($lb.InboundNatPools ).Count
1163
+ Assert-AreEqual $inboundNatPoolName $lb.InboundNatPools [0 ].Name
1164
+ Assert-AreEqual 3360 $lb.InboundNatPools [0 ].FrontendPortRangeStart
1165
+ Assert-AreEqual 3362 $lb.InboundNatPools [0 ].FrontendPortRangeEnd
1166
+ Assert-AreEqual 3370 $lb.InboundNatPools [0 ].BackendPort
1167
+ Assert-AreEqual Tcp $lb.InboundNatPools [0 ].Protocol
1168
+
1169
+ $inboundNatPoolName2 = Get-ResourceName
1170
+ $lb = Get-AzureRmLoadBalancer - Name $lbName - ResourceGroupName $rgname | Add-AzureRmLoadBalancerInboundNatPoolConfig - Name $inboundNatPoolName2 - FrontendIPConfigurationId $lb.FrontendIPConfigurations [0 ].Id - Protocol Udp - FrontendPortRangeStart 3366 - FrontendPortRangeEnd 3368 - BackendPort 3376 | Set-AzureRmLoadBalancer
1171
+
1172
+ Assert-AreEqual 2 @ ($lb.InboundNatPools ).Count
1173
+ Assert-AreEqual $inboundNatPoolName2 $lb.InboundNatPools [1 ].Name
1174
+ Assert-AreEqual 3366 $lb.InboundNatPools [1 ].FrontendPortRangeStart
1175
+ Assert-AreEqual 3368 $lb.InboundNatPools [1 ].FrontendPortRangeEnd
1176
+ Assert-AreEqual 3376 $lb.InboundNatPools [1 ].BackendPort
1177
+ Assert-AreEqual Udp $lb.InboundNatPools [1 ].Protocol
1178
+
1179
+ $lb = Get-AzureRmLoadBalancer - Name $lbName - ResourceGroupName $rgname | Set-AzureRmLoadBalancerInboundNatPoolConfig - Name $inboundNatPoolName2 - FrontendIPConfigurationId $lb.FrontendIPConfigurations [0 ].Id - Protocol Tcp - FrontendPortRangeStart 3363 - FrontendPortRangeEnd 3364 - BackendPort 3373 | Set-AzureRmLoadBalancer
1180
+ Assert-AreEqual 2 @ ($lb.InboundNatPools ).Count
1181
+ Assert-AreEqual $inboundNatPoolName2 $lb.InboundNatPools [1 ].Name
1182
+ Assert-AreEqual 3363 $lb.InboundNatPools [1 ].FrontendPortRangeStart
1183
+ Assert-AreEqual 3364 $lb.InboundNatPools [1 ].FrontendPortRangeEnd
1184
+ Assert-AreEqual 3373 $lb.InboundNatPools [1 ].BackendPort
1185
+ Assert-AreEqual Tcp $lb.InboundNatPools [1 ].Protocol
1186
+
1187
+
1188
+ $inboundNatPoolConfig = Get-AzureRmLoadBalancer - Name $lbName - ResourceGroupName $rgname | Get-AzureRmLoadBalancerInboundNatPoolConfig - Name $inboundNatPoolName2
1189
+ $inboundNatPoolConfigList = Get-AzureRmLoadBalancer - Name $lbName - ResourceGroupName $rgname | Get-AzureRmLoadBalancerInboundNatPoolConfig
1190
+ Assert-AreEqual 2 @ ($inboundNatPoolConfigList ).Count
1191
+ Assert-AreEqual $inboundNatPoolName $inboundNatPoolConfigList [0 ].Name
1192
+ Assert-AreEqual $inboundNatPoolName2 $inboundNatPoolConfigList [1 ].Name
1193
+ Assert-AreEqual $inboundNatPoolConfig.Name $inboundNatPoolConfigList [1 ].Name
1194
+
1195
+ $lb = Get-AzureRmLoadBalancer - Name $lbName - ResourceGroupName $rgname | Remove-AzureRmLoadBalancerInboundNatPoolConfig - Name $inboundNatPoolName2 | Set-AzureRmLoadBalancer
1196
+ Assert-AreEqual 1 @ ($lb.InboundNatPools ).Count
1197
+ Assert-AreEqual $inboundNatPoolName $lb.InboundNatPools [0 ].Name
1198
+
1199
+ # Delete
1200
+ $deleteLb = $lb | Remove-AzureRmLoadBalancer - PassThru - Force
1201
+ Assert-AreEqual true $deleteLb
1202
+
1203
+ $list = Get-AzureRmLoadBalancer - ResourceGroupName $rgname
1204
+ Assert-AreEqual 0 @ ($list ).Count
1205
+ }
1206
+ finally
1207
+ {
1208
+ # Cleanup
1209
+ Clean - ResourceGroup $rgname
1210
+ }
1211
+ }
1212
+
1213
+ <#
1214
+ . SYNOPSIS
1215
+ Tests creating new public Load balancer and CRUD inbound nat pools on the load balancer
1216
+ #>
1217
+ function Test-LoadBalancerInboundNatPoolConfigCRUD-PublicLB
1218
+ {
1219
+ # Setup
1220
+ $rgname = Get-ResourceGroupName
1221
+ $vnetName = Get-ResourceName
1222
+ $subnetName = Get-ResourceName
1223
+ $publicIpName = Get-ResourceName
1224
+ $domainNameLabel = Get-ResourceName
1225
+ $lbName = Get-ResourceName
1226
+ $frontendName = Get-ResourceName
1227
+ $inboundNatPoolName = Get-ResourceName
1228
+ $rglocation = " West US"
1229
+ $resourceTypeParent = " Microsoft.Network/loadBalancers"
1230
+ $location = " West US"
1231
+
1232
+ try
1233
+ {
1234
+ # Create the resource group
1235
+ $resourceGroup = New-AzureRmResourceGroup - Name $rgname - Location $rglocation - Tags @ {Name = " testtag" ; Value = " testval" }
1236
+
1237
+ # Create the publicip
1238
+ $publicip = New-AzureRmPublicIpAddress - ResourceGroupName $rgname - name $publicIpName - location $location - AllocationMethod Dynamic - DomainNameLabel $domainNameLabel
1239
+
1240
+ # Create LoadBalancer with one Inbound NAT Pool
1241
+ $frontend = New-AzureRmLoadBalancerFrontendIpConfig - Name $frontendName - PublicIpAddress $publicip
1242
+ $inboundNatPool = New-AzureRmLoadBalancerInboundNatPoolConfig - Name $inboundNatPoolName - FrontendIPConfigurationId $frontend.Id - Protocol Tcp - FrontendPortRangeStart 3360 - FrontendPortRangeEnd 3362 - BackendPort 3370
1243
+ $actualLb = New-AzureRmLoadBalancer - Name $lbName - ResourceGroupName $rgname - Location $location - FrontendIpConfiguration $frontend - InboundNatPool $inboundNatPool
1244
+
1245
+ $expectedLb = Get-AzureRmLoadBalancer - Name $lbName - ResourceGroupName $rgname
1246
+
1247
+ # LB Verifications
1248
+ Assert-AreEqual $expectedLb.ResourceGroupName $actualLb.ResourceGroupName
1249
+ Assert-AreEqual $expectedLb.Name $actualLb.Name
1250
+ Assert-AreEqual $expectedLb.Location $actualLb.Location
1251
+ Assert-AreEqual " Succeeded" $expectedLb.ProvisioningState
1252
+ Assert-NotNull $expectedLb.ResourceGuid
1253
+ Assert-AreEqual 1 @ ($expectedLb.FrontendIPConfigurations ).Count
1254
+
1255
+ Assert-AreEqual 1 @ ($expectedLb.InboundNatPools ).Count
1256
+ Assert-AreEqual $inboundNatPoolName $expectedLb.InboundNatPools [0 ].Name
1257
+ Assert-AreEqual 3360 $expectedLb.InboundNatPools [0 ].FrontendPortRangeStart
1258
+ Assert-AreEqual 3362 $expectedLb.InboundNatPools [0 ].FrontendPortRangeEnd
1259
+ Assert-AreEqual 3370 $expectedLb.InboundNatPools [0 ].BackendPort
1260
+ Assert-AreEqual Tcp $expectedLb.InboundNatPools [0 ].Protocol
1261
+ Assert-AreEqual $expectedLb.FrontendIPConfigurations [0 ].Id $expectedLb.InboundNatPools [0 ].FrontendIPConfiguration.Id
1262
+
1263
+ # Test InboundNatPool cmdlets
1264
+ $inboundNatPoolName2 = Get-ResourceName
1265
+ $lb = Get-AzureRmLoadBalancer - Name $lbName - ResourceGroupName $rgname
1266
+ $lb = Add-AzureRmLoadBalancerInboundNatPoolConfig - LoadBalancer $lb - Name $inboundNatPoolName2 - FrontendIPConfiguration $lb.FrontendIPConfigurations [0 ] - Protocol Udp - FrontendPortRangeStart 3366 - FrontendPortRangeEnd 3368 - BackendPort 3376 | Set-AzureRmLoadBalancer
1267
+
1268
+ Assert-AreEqual 2 @ ($lb.InboundNatPools ).Count
1269
+ Assert-AreEqual $inboundNatPoolName2 $lb.InboundNatPools [1 ].Name
1270
+ Assert-AreEqual 3366 $lb.InboundNatPools [1 ].FrontendPortRangeStart
1271
+ Assert-AreEqual 3368 $lb.InboundNatPools [1 ].FrontendPortRangeEnd
1272
+ Assert-AreEqual 3376 $lb.InboundNatPools [1 ].BackendPort
1273
+ Assert-AreEqual Udp $lb.InboundNatPools [1 ].Protocol
1274
+
1275
+ $lb = Get-AzureRmLoadBalancer - Name $lbName - ResourceGroupName $rgname | Set-AzureRmLoadBalancerInboundNatPoolConfig - Name $inboundNatPoolName2 - FrontendIPConfigurationId $lb.FrontendIPConfigurations [0 ].Id - Protocol Tcp - FrontendPortRangeStart 3363 - FrontendPortRangeEnd 3364 - BackendPort 3373 | Set-AzureRmLoadBalancer
1276
+ Assert-AreEqual 2 @ ($lb.InboundNatPools ).Count
1277
+ Assert-AreEqual $inboundNatPoolName2 $lb.InboundNatPools [1 ].Name
1278
+ Assert-AreEqual 3363 $lb.InboundNatPools [1 ].FrontendPortRangeStart
1279
+ Assert-AreEqual 3364 $lb.InboundNatPools [1 ].FrontendPortRangeEnd
1280
+ Assert-AreEqual 3373 $lb.InboundNatPools [1 ].BackendPort
1281
+ Assert-AreEqual Tcp $lb.InboundNatPools [1 ].Protocol
1282
+
1283
+ $inboundNatPoolConfig = Get-AzureRmLoadBalancer - Name $lbName - ResourceGroupName $rgname | Get-AzureRmLoadBalancerInboundNatPoolConfig - Name $inboundNatPoolName2
1284
+ $inboundNatPoolConfigList = Get-AzureRmLoadBalancer - Name $lbName - ResourceGroupName $rgname | Get-AzureRmLoadBalancerInboundNatPoolConfig
1285
+ Assert-AreEqual 2 @ ($inboundNatPoolConfigList ).Count
1286
+ Assert-AreEqual $inboundNatPoolName $inboundNatPoolConfigList [0 ].Name
1287
+ Assert-AreEqual $inboundNatPoolName2 $inboundNatPoolConfigList [1 ].Name
1288
+ Assert-AreEqual $inboundNatPoolConfig.Name $inboundNatPoolConfigList [1 ].Name
1289
+
1290
+ $lb = Get-AzureRmLoadBalancer - Name $lbName - ResourceGroupName $rgname | Remove-AzureRmLoadBalancerInboundNatPoolConfig - Name $inboundNatPoolName2 | Set-AzureRmLoadBalancer
1291
+ Assert-AreEqual 1 @ ($lb.InboundNatPools ).Count
1292
+ Assert-AreEqual $inboundNatPoolName $lb.InboundNatPools [0 ].Name
1293
+
1294
+ # Delete LB
1295
+ $deleteLb = Remove-AzureRmLoadBalancer - Name $lbName - ResourceGroupName $rgname - PassThru - Force
1296
+ Assert-AreEqual true $deleteLb
1297
+
1298
+ $list = Get-AzureRmLoadBalancer - ResourceGroupName $rgname
1299
+ Assert-AreEqual 0 @ ($list ).Count
1300
+ }
1301
+ finally
1302
+ {
1303
+ # Cleanup
1304
+ Clean - ResourceGroup $rgname
1305
+ }
1120
1306
}
0 commit comments