|
| 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 | +Profile with Nested Endpoint |
| 18 | +#> |
| 19 | +function Test-NestedEndpointsCreateUpdate |
| 20 | +{ |
| 21 | + $resourceGroup = TestSetup-CreateResourceGroup |
| 22 | + $childProfileName = getAssetName |
| 23 | + $childProfileRelativeName = getAssetName |
| 24 | + $anotherChildProfileName = getAssetName |
| 25 | + $anotherChildProfileRelativeName = getAssetName |
| 26 | + $parentProfileName = getAssetName |
| 27 | + $parentProfileRelativeName = getAssetName |
| 28 | + |
| 29 | + $createdChildProfile = New-AzureRmTrafficManagerProfile -Name $childProfileName -ResourceGroupName $resourceGroup.ResourceGroupName -RelativeDnsName $childProfileRelativeName -Ttl 50 -TrafficRoutingMethod "Performance" -MonitorProtocol "HTTP" -MonitorPort 80 -MonitorPath "/testpath.asp" |
| 30 | + Assert-NotNull $createdChildProfile.Id |
| 31 | + |
| 32 | + $createdParentProfile = New-AzureRmTrafficManagerProfile -Name $parentProfileName -ResourceGroupName $resourceGroup.ResourceGroupName -RelativeDnsName $parentProfileRelativeName -Ttl 50 -TrafficRoutingMethod "Performance" -MonitorProtocol "HTTP" -MonitorPort 80 -MonitorPath "/testpath.asp" |
| 33 | + $createdParentProfile = Add-AzureRmTrafficManagerEndpointConfig -EndpointName "MyNestedEndpoint" -TrafficManagerProfile $createdParentProfile -Type "NestedEndpoints" -TargetResourceId $createdChildProfile.Id -EndpointStatus "Enabled" -EndpointLocation "North Europe" -MinChildEndpoints 2 |
| 34 | + $updatedParentProfile = Set-AzureRmTrafficManagerProfile -TrafficManagerProfile $createdParentProfile |
| 35 | + |
| 36 | + Assert-NotNull $updatedParentProfile |
| 37 | + Assert-AreEqual 1 $updatedParentProfile.Endpoints.Count |
| 38 | + Assert-AreEqual 2 $updatedParentProfile.Endpoints[0].MinChildEndpoints |
| 39 | + Assert-AreEqual "North Europe" $updatedParentProfile.Endpoints[0].Location |
| 40 | + |
| 41 | + $retrievedParentProfile = Get-AzureRmTrafficManagerProfile -Name $parentProfileName -ResourceGroupName $resourceGroup.ResourceGroupName |
| 42 | + |
| 43 | + Assert-NotNull $retrievedParentProfile |
| 44 | + Assert-AreEqual 1 $retrievedParentProfile.Endpoints.Count |
| 45 | + Assert-AreEqual 2 $retrievedParentProfile.Endpoints[0].MinChildEndpoints |
| 46 | + Assert-AreEqual "North Europe" $retrievedParentProfile.Endpoints[0].Location |
| 47 | + |
| 48 | + $anotherCreatedChildProfile = New-AzureRmTrafficManagerProfile -Name $anotherChildProfileName -ResourceGroupName $resourceGroup.ResourceGroupName -RelativeDnsName $anotherChildProfileRelativeName -Ttl 50 -TrafficRoutingMethod "Performance" -MonitorProtocol "HTTP" -MonitorPort 80 -MonitorPath "/testpath.asp" |
| 49 | + Assert-NotNull $anotherCreatedChildProfile.Id |
| 50 | + |
| 51 | + $anotherNestedEndpoint = New-AzureRmTrafficManagerEndpoint -Name "MySecondNestedEndpoint" -ProfileName $parentProfileName -ResourceGroupName $resourceGroup.ResourceGroupName -Type "NestedEndpoints" -TargetResourceId $anotherCreatedChildProfile.Id -EndpointStatus "Enabled" -EndpointLocation "West Europe" -MinChildEndpoints 3 |
| 52 | + |
| 53 | + Assert-NotNull $anotherNestedEndpoint |
| 54 | + Assert-AreEqual 3 $anotherNestedEndpoint.MinChildEndpoints |
| 55 | + Assert-AreEqual "West Europe" $anotherNestedEndpoint.Location |
| 56 | + |
| 57 | + $retrievedParentProfile = Get-AzureRmTrafficManagerProfile -Name $parentProfileName -ResourceGroupName $resourceGroup.ResourceGroupName |
| 58 | + |
| 59 | + Assert-NotNull $retrievedParentProfile |
| 60 | + Assert-AreEqual 2 $retrievedParentProfile.Endpoints.Count |
| 61 | + Assert-AreEqual 3 $retrievedParentProfile.Endpoints[1].MinChildEndpoints |
| 62 | + Assert-AreEqual "West Europe" $retrievedParentProfile.Endpoints[1].Location |
| 63 | + |
| 64 | + $anotherNestedEndpoint.MinChildEndpoints = 4 |
| 65 | + $anotherNestedEndpoint.Location = "West US" |
| 66 | + |
| 67 | + $anotherNestedEndpoint = Set-AzureRmTrafficManagerEndpoint -TrafficManagerEndpoint $anotherNestedEndpoint |
| 68 | + |
| 69 | + Assert-NotNull $anotherNestedEndpoint |
| 70 | + Assert-AreEqual 4 $anotherNestedEndpoint.MinChildEndpoints |
| 71 | + Assert-AreEqual "West US" $anotherNestedEndpoint.Location |
| 72 | + |
| 73 | + $retrievedParentProfile = Get-AzureRmTrafficManagerProfile -Name $parentProfileName -ResourceGroupName $resourceGroup.ResourceGroupName |
| 74 | + |
| 75 | + Assert-NotNull $retrievedParentProfile |
| 76 | + Assert-AreEqual 2 $retrievedParentProfile.Endpoints.Count |
| 77 | + Assert-AreEqual 4 $retrievedParentProfile.Endpoints[1].MinChildEndpoints |
| 78 | + Assert-AreEqual "West US" $retrievedParentProfile.Endpoints[1].Location |
| 79 | +} |
| 80 | + |
| 81 | +<# |
| 82 | +.SYNOPSIS |
| 83 | +Tests the Get-Put pattern for a profile with a nested endpoint |
| 84 | +#> |
| 85 | +function Test-ProfileWithNestedEndpointsGetPut |
| 86 | +{ |
| 87 | + $resourceGroup = TestSetup-CreateResourceGroup |
| 88 | + $childProfileName = getAssetName |
| 89 | + $childProfileRelativeName = getAssetName |
| 90 | + $parentProfileName = getAssetName |
| 91 | + $parentProfileRelativeName = getAssetName |
| 92 | + |
| 93 | + $createdChildProfile = New-AzureRmTrafficManagerProfile -Name $childProfileName -ResourceGroupName $resourceGroup.ResourceGroupName -RelativeDnsName $childProfileRelativeName -Ttl 30 -TrafficRoutingMethod "Performance" -MonitorProtocol "HTTP" -MonitorPort 80 -MonitorPath "/testchild.asp" |
| 94 | + Assert-NotNull $createdChildProfile.Id |
| 95 | + |
| 96 | + $createdParentProfile = New-AzureRmTrafficManagerProfile -Name $parentProfileName -ResourceGroupName $resourceGroup.ResourceGroupName -RelativeDnsName $parentProfileRelativeName -Ttl 51 -TrafficRoutingMethod "Performance" -MonitorProtocol "HTTPS" -MonitorPort 111 -MonitorPath "/testparent.asp" |
| 97 | + $nestedEndpoint = New-AzureRmTrafficManagerEndpoint -Name "MyNestedEndpoint" -ProfileName $parentProfileName -ResourceGroupName $resourceGroup.ResourceGroupName -Type "NestedEndpoints" -TargetResourceId $createdChildProfile.Id -EndpointStatus "Enabled" -EndpointLocation "West Europe" -MinChildEndpoints 1 |
| 98 | + |
| 99 | + $retrievedParentProfile = Get-AzureRmTrafficManagerProfile -Name $parentProfileName -ResourceGroupName $resourceGroup.ResourceGroupName |
| 100 | + $retrievedParentProfile | Set-AzureRmTrafficManagerProfile |
| 101 | + |
| 102 | + $retrievedParentProfile = Get-AzureRmTrafficManagerProfile -Name $parentProfileName -ResourceGroupName $resourceGroup.ResourceGroupName |
| 103 | + |
| 104 | + Assert-NotNull $retrievedParentProfile |
| 105 | + Assert-AreEqual 51 $retrievedParentProfile.Ttl |
| 106 | + Assert-AreEqual 111 $retrievedParentProfile.MonitorPort |
| 107 | + Assert-AreEqual "HTTPS" $retrievedParentProfile.MonitorProtocol |
| 108 | + Assert-AreEqual "/testparent.asp" $retrievedParentProfile.MonitorPath |
| 109 | + Assert-AreEqual "Performance" $retrievedParentProfile.TrafficRoutingMethod |
| 110 | + |
| 111 | + Assert-AreEqual 1 $retrievedParentProfile.Endpoints.Count |
| 112 | + Assert-AreEqual 1 $retrievedParentProfile.Endpoints[0].MinChildEndpoints |
| 113 | + Assert-AreEqual 1 $retrievedParentProfile.Endpoints[0].Weight |
| 114 | + Assert-AreEqual 1 $retrievedParentProfile.Endpoints[0].Priority |
| 115 | + Assert-AreEqual "Microsoft.Network/trafficManagerProfiles/nestedEndpoints" $retrievedParentProfile.Endpoints[0].Type |
| 116 | + Assert-AreEqual "MyNestedEndpoint" $retrievedParentProfile.Endpoints[0].Name |
| 117 | + Assert-AreEqual "Enabled" $retrievedParentProfile.Endpoints[0].EndpointStatus |
| 118 | + Assert-AreEqual "West Europe" $retrievedParentProfile.Endpoints[0].Location |
| 119 | + Assert-AreEqual $createdChildProfile.Id $retrievedParentProfile.Endpoints[0].TargetResourceId |
| 120 | + Assert-AreEqual $retrievedParentProfile.Name $retrievedParentProfile.Endpoints[0].ProfileName |
| 121 | +} |
0 commit comments