|
| 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 | +Creats an origin group and set the default origin group on a running endpoint |
| 18 | +#> |
| 19 | +function Test-CreateOriginGroup |
| 20 | +{ |
| 21 | + # Set up required fields |
| 22 | + $subId = (Get-AzContext).Subscription.id |
| 23 | + $resourceGroup = TestSetup-CreateResourceGroup |
| 24 | + $resourceGroupName = $resourceGroup.ResourceGroupName |
| 25 | + $profileName = getAssetName |
| 26 | + |
| 27 | + # Profile specific properties |
| 28 | + $resourceLocation = "Global" |
| 29 | + $profileSku = "Standard_Microsoft" |
| 30 | + |
| 31 | + # Create a Microsoft CDN Profile |
| 32 | + $createdProfile = New-AzCdnProfile -ResourceGroupName $resourceGroupName -ProfileName $profileName -Location $resourceLocation -Sku $profileSku |
| 33 | + |
| 34 | + # Endpoint specific properties |
| 35 | + $endpointName = getAssetName |
| 36 | + $originGroupName = getAssetName |
| 37 | + $originName = getAssetName |
| 38 | + $originHostName = "www.microsoft.com" |
| 39 | + $originGroupResourceId = "/subscriptions/$subId/resourcegroups/$resourceGroupName/providers/Microsoft.Cdn/profiles/$profileName/endpoints/$endpointName/origingroups/$originGroupName" |
| 40 | + $defaultOriginGroup = $originGroupResourceId |
| 41 | + |
| 42 | + # 1st origin group properties |
| 43 | + $probeInterval = 240 |
| 44 | + $probePath = "/health.aspx" |
| 45 | + $probeProtocol = "Https" |
| 46 | + $probeRequestType = "GET" |
| 47 | + $originId = "/subscriptions/$subId/resourcegroups/$resourceGroupName/providers/Microsoft.Cdn/profiles/$profileName/endpoints/$endpointName/origins/$originName" |
| 48 | + |
| 49 | + # Create CDN endpoint, 1st origin group, and establish the default origin group |
| 50 | + $createdEndpoint = New-AzCdnEndpoint -ResourceGroupName $resourceGroupName -ProfileName $profileName -EndpointName $endpointName -Location $resourceLocation -OriginName $originName -OriginHostName $originHostName -OriginGroupName $originGroupName -DefaultOriginGroup $defaultOriginGroup -OriginGroupProbeIntervalInSeconds $probeInterval -OriginGroupProbePath $probePath -OriginGroupProbeProtocol $probeProtocol -OriginGroupProbeRequestType $probeRequestType -OriginId $originId |
| 51 | + |
| 52 | + # 2nd origin group properties |
| 53 | + $originGroupName2 = getAssetName |
| 54 | + $probeInterval2 = 120 |
| 55 | + $probePath2 = "/check-health.aspx" |
| 56 | + $probeProtocol2 = "Http" |
| 57 | + $probeRequestType2 = "HEAD" |
| 58 | + |
| 59 | + # create 2nd origin group |
| 60 | + $createdOriginGroup = New-AzCdnOriginGroup -ResourceGroupName $resourceGroupName -ProfileName $profileName -EndpointName $endpointName -OriginGroupName $originGroupName2 -OriginId $originId -ProbeIntervalInSeconds $probeInterval2 -ProbePath $probePath2 -ProbeProtocol $probeProtocol2 -ProbeRequestType $probeRequestType2 |
| 61 | + |
| 62 | + # Test the default origin group on the endpoint |
| 63 | + Assert-AreEqual $defaultOriginGroup $createdEndpoint.DefaultOriginGroup.Id |
| 64 | + |
| 65 | + # Test the properties on the 2nd origin group |
| 66 | + Assert-AreEqual $originGroupName2 $createdOriginGroup.Name |
| 67 | + Assert-AreEqual $probeInterval2 $createdOriginGroup.ProbeIntervalInSeconds |
| 68 | + Assert-AreEqual $probePath2 $createdOriginGroup.ProbePath |
| 69 | + Assert-AreEqual $probeProtocol2 $createdOriginGroup.ProbeProtocol |
| 70 | + Assert-AreEqual $probeRequestType2 $createdOriginGroup.ProbeRequestType |
| 71 | + Assert-AreEqual $originId $createdOriginGroup.Origins[0].Id |
| 72 | + |
| 73 | + Remove-AzResourceGroup -Name $resourceGroup.ResourceGroupName -Force |
| 74 | +} |
| 75 | + |
| 76 | +<# |
| 77 | +.SYNOPSIS |
| 78 | +Gets and sets an origin group with a running endpoint |
| 79 | +#> |
| 80 | +function Test-GetSetOriginGroup |
| 81 | +{ |
| 82 | + # Set up required fields |
| 83 | + $subId = (Get-AzContext).Subscription.id |
| 84 | + $resourceGroup = TestSetup-CreateResourceGroup |
| 85 | + $resourceGroupName = $resourceGroup.ResourceGroupName |
| 86 | + $profileName = getAssetName |
| 87 | + |
| 88 | + # Profile specific properties |
| 89 | + $resourceLocation = "Global" |
| 90 | + $profileSku = "Standard_Microsoft" |
| 91 | + |
| 92 | + # Create a Microsoft CDN Profile |
| 93 | + $createdProfile = New-AzCdnProfile -ResourceGroupName $resourceGroupName -ProfileName $profileName -Location $resourceLocation -Sku $profileSku |
| 94 | + |
| 95 | + # Endpoint specific properties |
| 96 | + $endpointName = getAssetName |
| 97 | + $originGroupName = getAssetName |
| 98 | + $originName = getAssetName |
| 99 | + $originHostName = "www.microsoft.com" |
| 100 | + $originGroupResourceId = "/subscriptions/$subId/resourcegroups/$resourceGroupName/providers/Microsoft.Cdn/profiles/$profileName/endpoints/$endpointName/origingroups/$originGroupName" |
| 101 | + $defaultOriginGroup = $originGroupResourceId |
| 102 | + |
| 103 | + # Origin id for the origin group |
| 104 | + $originId = "/subscriptions/$subId/resourcegroups/$resourceGroupName/providers/Microsoft.Cdn/profiles/$profileName/endpoints/$endpointName/origins/$originName" |
| 105 | + |
| 106 | + # Create CDN endpoint, origin group, and establish the default origin group |
| 107 | + $createdEndpoint = New-AzCdnEndpoint -ResourceGroupName $resourceGroupName -ProfileName $profileName -EndpointName $endpointName -Location $resourceLocation -OriginName $originName -OriginHostName $originHostName -OriginGroupName $originGroupName -DefaultOriginGroup $defaultOriginGroup -OriginId $originId |
| 108 | + |
| 109 | + # Get the origin group |
| 110 | + $originGroup = Get-AzCdnOriginGroup -ResourceGroupName $resourceGroupName -ProfileName $profileName -EndpointName $endpointName -OriginGroupName $originGroupName |
| 111 | + |
| 112 | + # Test the unmodified origin group |
| 113 | + Assert-AreEqual $originGroupResourceId $originGroup.Id |
| 114 | + Assert-AreEqual 0 $originGroup.ProbeIntervalInSeconds |
| 115 | + Assert-Null $originGroup.ProbePath |
| 116 | + Assert-Null $originGroup.ProbeProtocol |
| 117 | + Assert-Null $originGroup.ProbeRequestType |
| 118 | + |
| 119 | + # Set new values on the origin group |
| 120 | + $probeInterval = 120 |
| 121 | + $probePath = "/health-status.aspx" |
| 122 | + $probeProtocol = "Https" |
| 123 | + $probeRequestType = "GET" |
| 124 | + |
| 125 | + # Update properties on origin group |
| 126 | + $updatedOriginGroup = Set-AzCdnOriginGroup -ResourceGroupName $resourceGroupName -ProfileName $profileName -EndpointName $endpointName -OriginGroupName $originGroupName -OriginId $originId -ProbeIntervalInSeconds $probeInterval -ProbePath $probePath -ProbeProtocol $probeProtocol -ProbeRequestType $probeRequestType |
| 127 | + |
| 128 | + # Test modified origin group |
| 129 | + Assert-AreEqual $probeInterval $updatedOriginGroup.ProbeIntervalInSeconds |
| 130 | + Assert-AreEqual $probePath $updatedOriginGroup.ProbePath |
| 131 | + Assert-AreEqual $probeProtocol $updatedOriginGroup.ProbeProtocol |
| 132 | + Assert-AreEqual $probeRequestType $updatedOriginGroup.ProbeRequestType |
| 133 | + |
| 134 | + Remove-AzResourceGroup -Name $resourceGroup.ResourceGroupName -Force |
| 135 | +} |
| 136 | + |
| 137 | +<# |
| 138 | +.SYNOPSIS |
| 139 | +Creates and removes an origin group with a running endpoint |
| 140 | +#> |
| 141 | +function Test-RemoveOriginGroup |
| 142 | +{ |
| 143 | + # Set up required fields |
| 144 | + $subId = (Get-AzContext).Subscription.id |
| 145 | + $resourceGroup = TestSetup-CreateResourceGroup |
| 146 | + $resourceGroupName = $resourceGroup.ResourceGroupName |
| 147 | + $profileName = getAssetName |
| 148 | + |
| 149 | + # Profile specific properties |
| 150 | + $resourceLocation = "Global" |
| 151 | + $profileSku = "Standard_Microsoft" |
| 152 | + |
| 153 | + # Create a Microsoft CDN Profile |
| 154 | + $createdProfile = New-AzCdnProfile -ResourceGroupName $resourceGroupName -ProfileName $profileName -Location $resourceLocation -Sku $profileSku |
| 155 | + |
| 156 | + # Endpoint specific properties |
| 157 | + $endpointName = getAssetName |
| 158 | + $originGroupName = getAssetName |
| 159 | + $originName = getAssetName |
| 160 | + $originHostName = "www.microsoft.com" |
| 161 | + $originGroupResourceId = "/subscriptions/$subId/resourcegroups/$resourceGroupName/providers/Microsoft.Cdn/profiles/$profileName/endpoints/$endpointName/origingroups/$originGroupName" |
| 162 | + $defaultOriginGroup = $originGroupResourceId |
| 163 | + |
| 164 | + # Origin id for the origin group |
| 165 | + $originId = "/subscriptions/$subId/resourcegroups/$resourceGroupName/providers/Microsoft.Cdn/profiles/$profileName/endpoints/$endpointName/origins/$originName" |
| 166 | + |
| 167 | + # Create CDN endpoint, origin group, and establish the default origin group |
| 168 | + $createdEndpoint = New-AzCdnEndpoint -ResourceGroupName $resourceGroupName -ProfileName $profileName -EndpointName $endpointName -Location $resourceLocation -OriginName $originName -OriginHostName $originHostName -OriginGroupName $originGroupName -DefaultOriginGroup $defaultOriginGroup -OriginId $originId |
| 169 | + |
| 170 | + # 2nd origin group properties |
| 171 | + $originGroupName2 = getAssetName |
| 172 | + $probeInterval2 = 120 |
| 173 | + $probePath2 = "/check-health.aspx" |
| 174 | + $probeProtocol2 = "Http" |
| 175 | + $probeRequestType2 = "HEAD" |
| 176 | + $originGroupResourceId2 = "/subscriptions/$subId/resourcegroups/$resourceGroupName/providers/Microsoft.Cdn/profiles/$profileName/endpoints/$endpointName/origingroups/$originGroupName2" |
| 177 | + |
| 178 | + # create 2nd origin group |
| 179 | + $createdOriginGroup = New-AzCdnOriginGroup -ResourceGroupName $resourceGroupName -ProfileName $profileName -EndpointName $endpointName -OriginGroupName $originGroupName2 -OriginId $originId -ProbeIntervalInSeconds $probeInterval2 -ProbePath $probePath2 -ProbeProtocol $probeProtocol2 -ProbeRequestType $probeRequestType2 |
| 180 | + |
| 181 | + # Remove the 2nd origin group |
| 182 | + Remove-AzCdnOriginGroup -ResourceId $originGroupResourceId2 |
| 183 | + |
| 184 | + # Update a property on the already deleted origin group |
| 185 | + $probeIntervalUpdate = 60 |
| 186 | + |
| 187 | + # Test origin group was removed correctly |
| 188 | + Assert-ThrowsContains { Get-AzCdnOriginGroup -ResourceId $originGroupResourceId2 } "NotFound" |
| 189 | + Assert-ThrowsContains { Set-AzCdnOriginGroup -ResourceGroupName $resourceGroupName -ProfileName $profileName -EndpointName $endpointName -OriginGroupName $originGroupName2 -OriginId $originId -ProbeIntervalInSeconds $probeIntervalUpdate } "NotFound" |
| 190 | + |
| 191 | + Remove-AzResourceGroup -Name $resourceGroup.ResourceGroupName -Force |
| 192 | +} |
0 commit comments