-
Notifications
You must be signed in to change notification settings - Fork 4.2k
PS Support for Migration AvailaibilitySets APIs #29085
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
56bf91e
6916d82
8b7b761
21a28ca
c866aa3
0815f74
2595424
c5f2be4
095010d
e96e305
5656aef
a2df751
106253c
52ff159
11f7dfe
d0ecf88
0da6e0b
620ad88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -231,3 +231,169 @@ function Test-AvailabilitySetVM | |||||||||||||
| Clean-ResourceGroup $rgname | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| <# | ||||||||||||||
| .SYNOPSIS | ||||||||||||||
| Test Availability Set Migration to VMSS Flex | ||||||||||||||
| Note: This test requires the subscription to be enabled for the feature flag Microsoft.Compute/MigrateToVmssFlex | ||||||||||||||
| #> | ||||||||||||||
| function Test-AvailabilitySetMigration | ||||||||||||||
| { | ||||||||||||||
| param ($loc) | ||||||||||||||
| # Setup | ||||||||||||||
| $rgname = Get-ComputeTestResourceName | ||||||||||||||
|
|
||||||||||||||
| try | ||||||||||||||
| { | ||||||||||||||
| # Common | ||||||||||||||
| if ($loc -eq $null) | ||||||||||||||
| { | ||||||||||||||
| $loc = Get-ComputeVMLocation; | ||||||||||||||
| } | ||||||||||||||
| New-AzResourceGroup -Name $rgname -Location $loc -Force; | ||||||||||||||
|
|
||||||||||||||
| # Create Availability Set | ||||||||||||||
| $asetName = 'aset' + $rgname; | ||||||||||||||
| New-AzAvailabilitySet -ResourceGroupName $rgname -Name $asetName -Location $loc -Sku 'Aligned' -PlatformFaultDomainCount 2 -PlatformUpdateDomainCount 7; | ||||||||||||||
| $aset = Get-AzAvailabilitySet -ResourceGroupName $rgname -Name $asetName; | ||||||||||||||
| Assert-NotNull $aset; | ||||||||||||||
|
|
||||||||||||||
| # Create a VM in the Availability Set | ||||||||||||||
| $vmname = 'vm' + $rgname; | ||||||||||||||
| $vm = New-TestVmInAvailabilitySet -ResourceGroupName $rgname -Location $loc -AvailabilitySetId $aset.Id -VmName $vmname; | ||||||||||||||
| $a = $vm | Out-String; | ||||||||||||||
| Write-Verbose("Get-AzVM output:"); | ||||||||||||||
| Write-Verbose($a); | ||||||||||||||
| Assert-NotNull $a | ||||||||||||||
|
|
||||||||||||||
| # Create a Flexible VMSS for migration target | ||||||||||||||
| $vmssName = 'vmss' + $rgname; | ||||||||||||||
| $vmssConfig = New-AzVmssConfig -Location $loc -OrchestrationMode 'Flexible' -PlatformFaultDomainCount 2 -SinglePlacementGroup $false; | ||||||||||||||
| $vmss = New-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName -VirtualMachineScaleSet $vmssConfig; | ||||||||||||||
| Assert-NotNull $vmss; | ||||||||||||||
| $vmssId = $vmss.Id; | ||||||||||||||
|
|
||||||||||||||
| # Test Validate Migration cmdlet | ||||||||||||||
| $validateResult = Test-AzAvailabilitySetMigration -ResourceGroupName $rgname -Name $asetName -VirtualMachineScaleSetFlexibleId $vmssId; | ||||||||||||||
| Assert-NotNull $validateResult; | ||||||||||||||
|
|
||||||||||||||
| # Test StartMigration cmdlet | ||||||||||||||
| $migrationResult = Start-AzAvailabilitySetMigration -ResourceGroupName $rgname -Name $asetName -VirtualMachineScaleSetFlexibleId $vmssId; | ||||||||||||||
| Assert-NotNull $migrationResult; | ||||||||||||||
|
|
||||||||||||||
| # Migrate VM to VMSS Flex | ||||||||||||||
| $migratedVM = Move-AzVirtualMachineToVmss -Id $vm.Id | ||||||||||||||
| Assert-NotNull $migratedVM; | ||||||||||||||
|
|
||||||||||||||
| # Test Convert cmdlet (creates a new VMSS) | ||||||||||||||
| # $newVmssName = 'vmss2' + $rgname; | ||||||||||||||
| # $convertResult = Convert-AzAvailabilitySet -ResourceGroupName $rgname -Name $asetName -VirtualMachineScaleSetName $newVmssName; | ||||||||||||||
| # Assert-NotNull $convertResult; | ||||||||||||||
|
|
||||||||||||||
| Write-Host "Availability Set Migration cmdlets test completed successfully"; | ||||||||||||||
| } | ||||||||||||||
| finally | ||||||||||||||
| { | ||||||||||||||
| # Cleanup | ||||||||||||||
| Clean-ResourceGroup $rgname | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| <# | ||||||||||||||
| .SYNOPSIS | ||||||||||||||
| Test Availability Set Convert to VMSS Flex | ||||||||||||||
| Note: This test requires the subscription to be enabled for the feature flag Microsoft.Compute/ConvertToVmssFlex | ||||||||||||||
| #> | ||||||||||||||
| function Test-AvailabilitySetConvert | ||||||||||||||
| { | ||||||||||||||
| param ($loc) | ||||||||||||||
| # Setup | ||||||||||||||
| $rgname = Get-ComputeTestResourceName | ||||||||||||||
|
|
||||||||||||||
| try | ||||||||||||||
| { | ||||||||||||||
| # Common | ||||||||||||||
| if ($loc -eq $null) | ||||||||||||||
| { | ||||||||||||||
| $loc = Get-ComputeVMLocation; | ||||||||||||||
| } | ||||||||||||||
| New-AzResourceGroup -Name $rgname -Location $loc -Force; | ||||||||||||||
|
|
||||||||||||||
| # Create Availability Set | ||||||||||||||
| $asetName = 'aset' + $rgname; | ||||||||||||||
| New-AzAvailabilitySet -ResourceGroupName $rgname -Name $asetName -Location $loc -Sku 'Aligned' -PlatformFaultDomainCount 2 -PlatformUpdateDomainCount 5; | ||||||||||||||
| $aset = Get-AzAvailabilitySet -ResourceGroupName $rgname -Name $asetName; | ||||||||||||||
| Assert-NotNull $aset; | ||||||||||||||
|
|
||||||||||||||
| # Create a VM in the Availability Set | ||||||||||||||
| $vmname = 'vm' + $rgname; | ||||||||||||||
| $vm = New-TestVmInAvailabilitySet -ResourceGroupName $rgname -Location $loc -AvailabilitySetId $aset.Id -VmName $vmname; | ||||||||||||||
| $a = $vm | Out-String; | ||||||||||||||
| Write-Verbose("Get-AzVM output:"); | ||||||||||||||
| Write-Verbose($a); | ||||||||||||||
| Assert-NotNull $a | ||||||||||||||
|
|
||||||||||||||
| # Test Convert cmdlet (creates a new VMSS) | ||||||||||||||
| $newVmssName = 'vmss2' + $rgname; | ||||||||||||||
| $convertResult = Convert-AzAvailabilitySet -ResourceGroupName $rgname -Name $asetName -VirtualMachineScaleSetName $newVmssName; | ||||||||||||||
| Assert-NotNull $convertResult; | ||||||||||||||
|
|
||||||||||||||
| Write-Host "Availability Set Migration cmdlets test completed successfully"; | ||||||||||||||
| } | ||||||||||||||
| finally | ||||||||||||||
| { | ||||||||||||||
| # Cleanup | ||||||||||||||
| Clean-ResourceGroup $rgname | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| # Helper: Create a VM in the specified availability set | ||||||||||||||
| function New-TestVmInAvailabilitySet { | ||||||||||||||
| param( | ||||||||||||||
| [Parameter(Mandatory = $true)] | ||||||||||||||
| [string] $ResourceGroupName, | ||||||||||||||
| [Parameter(Mandatory = $true)] | ||||||||||||||
| [string] $Location, | ||||||||||||||
| [Parameter(Mandatory = $true)] | ||||||||||||||
| [string] $AvailabilitySetId, | ||||||||||||||
| [Parameter(Mandatory = $true)] | ||||||||||||||
| [string] $VmName | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| # VM config assigned to Availability Set | ||||||||||||||
| $vmSize = 'Standard_DS1_v2'; | ||||||||||||||
| $vmConfig = New-AzVMConfig -VMName $VmName -VMSize $vmSize -AvailabilitySetId $AvailabilitySetId; | ||||||||||||||
|
|
||||||||||||||
| # Network | ||||||||||||||
| $subnet = New-AzVirtualNetworkSubnetConfig -Name ("subnet" + $VmName) -AddressPrefix "10.0.0.0/24"; | ||||||||||||||
| $vnet = New-AzVirtualNetwork -Force -Name ("vnet" + $VmName) -ResourceGroupName $ResourceGroupName -Location $Location -AddressPrefix "10.0.0.0/16" -Subnet $subnet; | ||||||||||||||
| $vnet = Get-AzVirtualNetwork -Name ("vnet" + $VmName) -ResourceGroupName $ResourceGroupName; | ||||||||||||||
| $subnetId = $vnet.Subnets[0].Id; | ||||||||||||||
|
|
||||||||||||||
| $pubip = New-AzPublicIpAddress -Force -Name ("pubip" + $VmName) -ResourceGroupName $ResourceGroupName -Location $Location -AllocationMethod Static -DomainNameLabel ("pubip" + $VmName); | ||||||||||||||
| $pubip = Get-AzPublicIpAddress -Name ("pubip" + $VmName) -ResourceGroupName $ResourceGroupName; | ||||||||||||||
|
|
||||||||||||||
| $nic = New-AzNetworkInterface -Force -Name ("nic" + $VmName) -ResourceGroupName $ResourceGroupName -Location $Location -SubnetId $subnetId -PublicIpAddressId $pubip.Id; | ||||||||||||||
| $nic = Get-AzNetworkInterface -Name ("nic" + $VmName) -ResourceGroupName $ResourceGroupName; | ||||||||||||||
|
|
||||||||||||||
| $vmConfig = Add-AzVMNetworkInterface -VM $vmConfig -Id $nic.Id; | ||||||||||||||
| Assert-AreEqual $vmConfig.NetworkProfile.NetworkInterfaces.Count 1; | ||||||||||||||
|
|
||||||||||||||
| # Minimal OS setup (test-only) | ||||||||||||||
| $user = "User$($VmName.Substring(0,4))"; | ||||||||||||||
| $password = $PLACEHOLDER; | ||||||||||||||
| $securePassword = ConvertTo-SecureString $password -AsPlainText -Force; | ||||||||||||||
| $cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword); | ||||||||||||||
| $vmConfig = Set-AzVMOperatingSystem -VM $vmConfig -Windows -ComputerName $VmName -Credential $cred; | ||||||||||||||
|
|
||||||||||||||
|
Comment on lines
+387
to
+388
|
||||||||||||||
| $vmConfig = Set-AzVMOperatingSystem -VM $vmConfig -Windows -ComputerName $VmName -Credential $cred; | |
| # Windows computer names must be 15 characters or fewer | |
| $computerName = if ($VmName.Length -gt 15) { $VmName.Substring(0, 15) } else { $VmName } | |
| $vmConfig = Set-AzVMOperatingSystem -VM $vmConfig -Windows -ComputerName $computerName -Credential $cred; |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$p and $imgRef are referenced but never defined in this function (and $imgRef is explicitly commented out), which will cause the scenario tests to fail at runtime. Remove these assertions or rewrite them to assert against $vmConfig.StorageProfile.ImageReference (or define $imgRef and set $p appropriately). Also ensure $PLACEHOLDER is defined/initialized in-scope for the test run (or replaced with the standard test credential source used in this repo).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests are marked as
Category.CheckInbut the scripts explicitly require a subscription feature flag to be enabled; this is likely to make check-in CI flaky/fail in environments where the flag isn’t enabled. Consider categorizing them asLiveOnly(or the repo’s equivalent non-check-in category), and/or add a deterministic skip path in the script when the required feature flag isn’t available.