Skip to content

Commit 4de85e9

Browse files
mbrat2005Copilot
andauthored
Catch avset check v2.5.37 (#156)
* Move to Sort-Object -Unique (case insensitive). Added error handling to AVSet query * v2.5.37 * Update AzureBasicLoadBalancerUpgrade/module/AzureBasicLoadBalancerUpgrade/modules/ValidateScenario/ValidateScenario.psm1 Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent 26a4f28 commit 4de85e9

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

AzureBasicLoadBalancerUpgrade/module/AzureBasicLoadBalancerUpgrade/AzureBasicLoadBalancerUpgrade.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = 'AzureBasicLoadBalancerUpgrade'
1313

1414
# Version number of this module.
15-
ModuleVersion = '2.5.36'
15+
ModuleVersion = '2.5.37'
1616

1717
# Supported PSEditions
1818
# CompatiblePSEditions = @()
@@ -107,7 +107,7 @@
107107
# IconUri = ''
108108

109109
# ReleaseNotes of this module
110-
ReleaseNotes = 'Fix multi-LB scenario validation to handle inconsistent casing on availability set IDs - Windows Powershell compatibility.'
110+
ReleaseNotes = 'Added error handling to Availability Set query. Moved to Sort-Object -Unique (case insensitive) in validation.'
111111

112112
# Prerelease string of this module
113113
# Prerelease = 'beta'

AzureBasicLoadBalancerUpgrade/module/AzureBasicLoadBalancerUpgrade/modules/ValidateScenario/ValidateScenario.psm1

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function _GetScenarioBackendType {
5454
}
5555
}
5656

57-
If (($backendMemberTypes | Sort-Object | Get-Unique).count -gt 1) {
57+
If (($backendMemberTypes | Sort-Object -Unique).count -gt 1) {
5858
log -ErrorAction Stop -Message "[Test-SupportedMigrationScenario] Basic Load Balancer backend pools can contain only VMs or VMSSes, contains: '$($backendMemberTypes -join ',')'" -Severity 'Error'
5959
return
6060
}
@@ -268,7 +268,7 @@ Function Test-SupportedMigrationScenario {
268268

269269
try {
270270
$nicBackendPoolMembershipsIds = @()
271-
$nicBackendPoolMembershipsIds += $vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations.ipCOnfigurations.LoadBalancerBackendAddressPools.id | Sort-Object | Get-Unique
271+
$nicBackendPoolMembershipsIds += $vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations.ipCOnfigurations.LoadBalancerBackendAddressPools.id | Sort-Object -Unique
272272
$differentMembership = Compare-Object $nicBackendPoolMembershipsIds $basicLBBackendIds
273273
}
274274
catch {
@@ -532,7 +532,7 @@ Function Test-SupportedMigrationScenario {
532532
try {
533533
$nicBackendPoolMembershipsIds = @()
534534

535-
$nicBackendPoolMembershipsIds += $basicLBVMNics.IpConfigurations.loadBalancerBackendAddressPools.id | Sort-Object | Get-Unique
535+
$nicBackendPoolMembershipsIds += $basicLBVMNics.IpConfigurations.loadBalancerBackendAddressPools.id | Sort-Object -Unique
536536

537537
If ([string]::IsNullOrEmpty($basicLBBackendIds)) {
538538
# handle LBs with no backend pools
@@ -659,9 +659,17 @@ Function Test-SupportedMigrationScenario {
659659
$availabilitySetReference = $basicLBVMs | Where-Object { $_.AvailabilitySetReference -ne $null } | Select-Object -ExpandProperty AvailabilitySetReference
660660

661661
If (![string]::IsNullOrEmpty($availabilitySetReference)) {
662-
$availabilitySetVMs = $availabilitySetReference | Get-Unique | Get-AzResource | Get-AzAvailabilitySet | Select-Object -expand VirtualMachinesReferences | Select-Object -ExpandProperty Id
663-
$availabilitySetVMs = $availabilitySetVMs | Sort-Object | Get-Unique
664-
$extraAvailabilitySetVMs = $availabilitySetVMs | Where-Object { $_ -notin $basicLBVMs.Id } | Sort-Object | Get-Unique
662+
log -Message "[Test-SupportedMigrationScenario] Getting Availability Sets and associated VMs" -Severity Verbose
663+
try {
664+
$availabilitySetVMs = $availabilitySetReference | Get-Unique | Get-AzResource | Get-AzAvailabilitySet | Select-Object -expand VirtualMachinesReferences | Select-Object -ExpandProperty Id
665+
}
666+
catch {
667+
$message = "[Test-SupportedMigrationScenario] Error retrieving Availability Set VMs: $($_.Exception.Message)"
668+
log -Message $message -Severity 'Error' -terminateOnError
669+
}
670+
671+
$availabilitySetVMs = $availabilitySetVMs | Sort-Object -Unique
672+
$extraAvailabilitySetVMs = $availabilitySetVMs | Where-Object { $_ -notin $basicLBVMs.Id } | Sort-Object -Unique
665673

666674
If ($extraAvailabilitySetVMs) {
667675
$message = "[Test-SupportedMigrationScenario] VMs ('$($extraAvailabilitySetVMs -join ';')') belong(s) to an Availability Set but is not associated with the LB. There are other members of the same Availability Set which are part of the load balancer backend pools, NAT pools, or associated with NAT Rules. This is not supported for migration. To work around this, create a new backend pool on the basic LB which is not associated with a load balancing rule and add the extra VMs to it temporarily, then retry migration."
@@ -728,7 +736,7 @@ Function Test-SupportedMultiLBScenario {
728736

729737
# check that all backend pool members are VMs or VMSSes
730738
log -Message "[Test-SupportedMultiLBScenario] Checking that all backend pool members are VMs or VMSSes"
731-
$backendMemberTypes = ($multiLBConfig.scenario.BackendType | Sort-Object | Get-Unique)
739+
$backendMemberTypes = ($multiLBConfig.scenario.BackendType | Sort-Object -Unique)
732740

733741
If ($backendMemberTypes.count -gt 1) {
734742
log -ErrorAction Stop -Severity 'Error' -Message "[Test-SupportedMultiLBScenario] Basic Load Balancer backend pools can contain only VMs or VMSSes, contains: '$($backendMemberTypes -join ',')'"
@@ -772,7 +780,7 @@ Function Test-SupportedMultiLBScenario {
772780
$basicLBBackends += $config.BasicLoadBalancer.BackendAddressPools.BackendIpConfigurations.id | ForEach-Object { $_.split('/virtualMachines/')[0] }
773781
}
774782

775-
$groupedBackends = $basicLBBackends | ForEach-Object { $_.id.ToLower() } | Sort-Object | Get-Unique
783+
$groupedBackends = $basicLBBackends | ForEach-Object { $_.id.ToLower() } | Sort-Object -Unique
776784

777785

778786
If ($groupedBackends.Count -gt 1) {

0 commit comments

Comments
 (0)