modules/ValidateScenario/ValidateScenario.Tests.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
Describe "ValidateScenario" { BeforeEach { Import-Module ./AzureBasicLoadBalancerUpgrade/modules/ValidateScenario/ValidateScenario.psm1 -Force $options = [System.Text.Json.JsonSerializerOptions]::new() $options.WriteIndented = $true $options.IgnoreReadOnlyProperties = $true $stdLbJson = @' { "ProvisioningState": "Succeeded", "Sku": { "Name": "Basic", "Tier": "Regional" }, "FrontendIpConfigurations": [ { "PrivateIpAddress": "", "PrivateIpAllocationMethod": "Dynamic", "PrivateIpAddressVersion": "IPv4", "ProvisioningState": "Succeeded", "Zones": [], "InboundNatRules": [], "InboundNatPools": [], "OutboundRules": [], "LoadBalancingRules": [ { "Id": "/subscriptions/b2375b5f-8dab-4436-b87c-32bc7fdce5d0/resourceGroups/rg-001-basic-lb-int-single-fe/providers/Microsoft.Network/loadBalancers/lb-basic-01/loadBalancingRules/rule-01" } ], "Subnet": { "AddressPrefix": null, "IpConfigurations": [], "ServiceAssociationLinks": [], "ResourceNavigationLinks": [], "NetworkSecurityGroup": null, "RouteTable": null, "NatGateway": null, "ServiceEndpoints": [], "ServiceEndpointPolicies": [], "Delegations": [], "PrivateEndpoints": [], "ProvisioningState": null, "PrivateEndpointNetworkPolicies": null, "PrivateLinkServiceNetworkPolicies": null, "IpAllocations": [], "Name": null, "Etag": null, "Id": "/subscriptions/b2375b5f-8dab-4436-b87c-32bc7fdce5d0/resourceGroups/rg-001-basic-lb-int-single-fe/providers/Microsoft.Network/virtualNetworks/vnet-01/subnets/subnet-01" }, "PublicIpAddress": null, "PublicIPPrefix": null, "GatewayLoadBalancer": null, "Name": "fe-01", "Etag": "W/\u00224104014d-4a71-45da-b64a-15d835fc861b\u0022", "Id": "/subscriptions/b2375b5f-8dab-4436-b87c-32bc7fdce5d0/resourceGroups/rg-001-basic-lb-int-single-fe/providers/Microsoft.Network/loadBalancers/lb-basic-01/frontendIPConfigurations/fe-01" } ], "BackendAddressPools": [ { "ProvisioningState": "Succeeded", "BackendIpConfigurations": [ { "PrivateIpAddressVersion": null, "LoadBalancerBackendAddressPools": [], "LoadBalancerInboundNatRules": [], "Primary": false, "ApplicationGatewayBackendAddressPools": [], "ApplicationSecurityGroups": [], "VirtualNetworkTaps": [], "PrivateLinkConnectionProperties": null, "GatewayLoadBalancer": null, "PrivateIpAddress": null, "PrivateIpAllocationMethod": null, "Subnet": null, "PublicIpAddress": null, "ProvisioningState": null, "Name": null, "Etag": null, "Id": "/subscriptions/b2375b5f-8dab-4436-b87c-32bc7fdce5d0/resourceGroups/rg-001-basic-lb-int-single-fe/providers/Microsoft.Compute/virtualMachineScaleSets/vmss-01/virtualMachines/0/networkInterfaces/vmss-01-nic-01configuration-0/ipConfigurations/ipconfig1" } ], "LoadBalancerBackendAddresses": [], "LoadBalancingRules": [ { "Id": "/subscriptions/b2375b5f-8dab-4436-b87c-32bc7fdce5d0/resourceGroups/rg-001-basic-lb-int-single-fe/providers/Microsoft.Network/loadBalancers/lb-basic-01/loadBalancingRules/rule-01" } ], "OutboundRule": null, "TunnelInterfaces": [], "Name": "be-01", "Etag": "W/\u00224104014d-4a71-45da-b64a-15d835fc861b\u0022", "Id": "/subscriptions/b2375b5f-8dab-4436-b87c-32bc7fdce5d0/resourceGroups/rg-001-basic-lb-int-single-fe/providers/Microsoft.Network/loadBalancers/lb-basic-01/backendAddressPools/be-01" } ], "LoadBalancingRules": [ { "Protocol": "Tcp", "LoadDistribution": "Default", "FrontendPort": 80, "BackendPort": 80, "IdleTimeoutInMinutes": 4, "EnableFloatingIP": false, "EnableTcpReset": false, "DisableOutboundSNAT": null, "ProvisioningState": "Succeeded", "FrontendIPConfiguration": { "Id": "/subscriptions/b2375b5f-8dab-4436-b87c-32bc7fdce5d0/resourceGroups/rg-001-basic-lb-int-single-fe/providers/Microsoft.Network/loadBalancers/lb-basic-01/frontendIPConfigurations/fe-01" }, "BackendAddressPool": { "Id": "/subscriptions/b2375b5f-8dab-4436-b87c-32bc7fdce5d0/resourceGroups/rg-001-basic-lb-int-single-fe/providers/Microsoft.Network/loadBalancers/lb-basic-01/backendAddressPools/be-01" }, "BackendAddressPools": [ { "Id": "/subscriptions/b2375b5f-8dab-4436-b87c-32bc7fdce5d0/resourceGroups/rg-001-basic-lb-int-single-fe/providers/Microsoft.Network/loadBalancers/lb-basic-01/backendAddressPools/be-01" } ], "Probe": { "Id": "/subscriptions/b2375b5f-8dab-4436-b87c-32bc7fdce5d0/resourceGroups/rg-001-basic-lb-int-single-fe/providers/Microsoft.Network/loadBalancers/lb-basic-01/probes/probe-01" }, "Name": "rule-01", "Etag": "W/\u00224104014d-4a71-45da-b64a-15d835fc861b\u0022", "Id": "/subscriptions/b2375b5f-8dab-4436-b87c-32bc7fdce5d0/resourceGroups/rg-001-basic-lb-int-single-fe/providers/Microsoft.Network/loadBalancers/lb-basic-01/loadBalancingRules/rule-01" } ], "Probes": [ { "Protocol": "Tcp", "Port": 80, "IntervalInSeconds": 5, "NumberOfProbes": 2, "RequestPath": null, "ProvisioningState": "Succeeded", "LoadBalancingRules": [ { "Id": "/subscriptions/b2375b5f-8dab-4436-b87c-32bc7fdce5d0/resourceGroups/rg-001-basic-lb-int-single-fe/providers/Microsoft.Network/loadBalancers/lb-basic-01/loadBalancingRules/rule-01" } ], "Name": "probe-01", "Etag": "W/\u00224104014d-4a71-45da-b64a-15d835fc861b\u0022", "Id": "/subscriptions/b2375b5f-8dab-4436-b87c-32bc7fdce5d0/resourceGroups/rg-001-basic-lb-int-single-fe/providers/Microsoft.Network/loadBalancers/lb-basic-01/probes/probe-01" } ], "InboundNatRules": [], "InboundNatPools": [], "OutboundRules": [], "ExtendedLocation": null, "ResourceGroupName": "rg-001-basic-lb-int-single-fe", "Location": "australiaeast", "ResourceGuid": "5e913af0-76cb-46aa-8ba3-b366f5503bc0", "Type": "Microsoft.Network/loadBalancers", "Tag": {}, "Name": "lb-basic-01", "Etag": "W/\u00224104014d-4a71-45da-b64a-15d835fc861b\u0022", "Id": "/subscriptions/b2375b5f-8dab-4436-b87c-32bc7fdce5d0/resourceGroups/rg-001-basic-lb-int-single-fe/providers/Microsoft.Network/loadBalancers/lb-basic-01" } '@ $BasicLoadBalancer = [System.Text.Json.JsonSerializer]::Deserialize($stdLbJson, [Microsoft.Azure.Commands.Network.Models.PSLoadBalancer]) } Context "Input Parameters" { It "Should fail is an invalid Load Balancer name is supplied" { $errMsg = "Cannot validate argument on parameter 'StdLoadBalancerName'.*" { Test-SupportedMigrationScenario -BasicLoadBalancer $BasicLoadBalancer -StdLoadBalancerName '_' -ErrorAction Stop } | Should -Throw -ExpectedMessage $errMsg } It "Should fail if a Standard Load Balancer is supplied" { $BasicLoadBalancer.Sku.Name = 'Standard' { Test-SupportedMigrationScenario -BasicLoadBalancer $BasicLoadBalancer -StdLoadBalancerName 'std-lb-01' } | Should -Throw -ExpectedMessage "*The load balancer 'lb-basic-01' in resource group 'rg-001-basic-lb-int-single-fe' is SKU 'Standard'. SKU must be Basic!" } } Context "VMSS in BackendPools" { It "Should fail if the backend pool ip configuration does not contain 'VirtualMachineScaleSet'" { $BasicLoadBalancer.BackendAddressPools[0].BackendIpConfigurations[0].Id = "/subscriptions/b2375b5f-8dab-4436-b87c-32bc7fdce5d0/resourceGroups/rg-001-basic-lb-int-single-fe/providers/Microsoft.Compute/banana/vmss-01/virtualMachines/0/networkInterfaces/vmss-01-nic-01configuration-0/ipConfigurations/ipconfig1" { Test-SupportedMigrationScenario -BasicLoadBalancer $BasicLoadBalancer -StdLoadBalancerName 'std-lb-01' -ErrorAction Stop } | Should -Throw -ExpectedMessage "*Basic Load Balancer has backend pools that is not virtualMachineScaleSets, exiting" } } Context "Empty BackendPools" { It "Should fail if the backend pool(s) have no membership" { $BasicLoadBalancer.BackendAddressPools[0].BackendIpConfigurations = @() { Test-SupportedMigrationScenario -BasicLoadBalancer $BasicLoadBalancer -StdLoadBalancerName 'std-lb-01' -ErrorAction Stop } | Should -Throw -ExpectedMessage "*Basic Load Balancer has backend pools have no membership, exiting" } } Context "LoadBalancingRules" { It "Should fail if no LoadBalancingRules exist on the load balancer" { $BasicLoadBalancer.LoadBalancingRules = $null { Test-SupportedMigrationScenario -BasicLoadBalancer $BasicLoadBalancer -StdLoadBalancerName 'std-lb-01' -ErrorAction Stop } | Should -Throw -ExpectedMessage "*Load balancer 'lb-basic-01' has no front end configurations, so there is nothing to migrate!" } } Context "Public Ip Prefix" { It "Should fail if the Public IP has an IPPrefix" { $ipPrefix = [Microsoft.Azure.Commands.Network.Models.PSResourceId]::new() $ipPrefix.Id = "/subscriptions/b2375b5f-8dab-4436-b87c-32bc7fdce5d0/resourceGroups/rg-001-basic-lb-int-single-fe/providers/Microsoft.Compute/banana/vmss-01/virtualMachines/0/networkInterfaces/vmss-01-nic-01configuration-0/ipConfigurations/ipconfig1" $BasicLoadBalancer.FrontendIpConfigurations[0].PublicIPPrefix = $ipPrefix { Test-SupportedMigrationScenario -BasicLoadBalancer $BasicLoadBalancer -StdLoadBalancerName 'std-lb-01' -ErrorAction Stop } | Should -Throw -ExpectedMessage "*FrontEndIPConfiguration*" } } } |