PS Support for Migration AvailaibilitySets APIs#29085
PS Support for Migration AvailaibilitySets APIs#29085vidai-msft merged 18 commits intoAzure:mainfrom
Conversation
This agent will create a Powershell PR based on the issue described. It will write tests, make code changes and add changelog.
Update agent name and description for Powershell PR
Agent instructions
Add Compute PR agent instructions
Co-authored-by: haagha <64601174+haagha@users.noreply.github.com>
| Thanks for your contribution! The pull request validation has started. Please revisit this comment for updated status. |
There was a problem hiding this comment.
Pull request overview
This pull request adds five new cmdlets to enable migration of Availability Sets to Flexible Virtual Machine Scale Sets (VMSS Flex) in Azure PowerShell Compute module. This feature is in public preview and requires the subscription to be enabled for the feature flag Microsoft.Compute/MigrateToVmssFlex.
Changes:
- Added five new cmdlets: Test-AzAvailabilitySetMigration, Start-AzAvailabilitySetMigration, Stop-AzAvailabilitySetMigration, Convert-AzAvailabilitySet, and Move-AzVirtualMachineToVmss
- Updated module manifest to export the new cmdlets
- Added PowerShell and C# test scenarios
- Updated ChangeLog.md with feature description
Reviewed changes
Copilot reviewed 15 out of 17 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| Test-AzAvailabilitySetMigration.md | Help documentation for validating Availability Set migration to VMSS |
| Stop-AzAvailabilitySetMigration.md | Help documentation for canceling migration operations |
| Start-AzAvailabilitySetMigration.md | Help documentation for starting Availability Set migration |
| Move-AzVirtualMachineToVmss.md | Help documentation for migrating individual VMs to VMSS |
| Convert-AzAvailabilitySet.md | Help documentation for converting Availability Set to new VMSS |
| MoveAzureVMToVmssCommand.cs | C# implementation of Move-AzVirtualMachineToVmss cmdlet |
| ChangeLog.md | Updated with descriptions of new cmdlets |
| Az.Compute.psd1 | Module manifest updated to export new cmdlets |
| TestAzureAvailabilitySetMigrationCommand.cs | C# implementation of Test-AzAvailabilitySetMigration cmdlet |
| StopAzureAvailabilitySetMigrationCommand.cs | C# implementation of Stop-AzAvailabilitySetMigration cmdlet |
| StartAzureAvailabilitySetMigrationCommand.cs | C# implementation of Start-AzAvailabilitySetMigration cmdlet |
| ConvertAzureAvailabilitySetCommand.cs | C# implementation of Convert-AzAvailabilitySet cmdlet |
| AvailabilitySetTests.ps1 | PowerShell test scenarios for migration cmdlets |
| AvailabilitySetTests.cs | C# test runner for migration tests |
| computePR.agent.md | New agent documentation file for Compute PR workflows |
| Assert-AreEqual $p.StorageProfile.ImageReference.Offer $imgRef.Offer; | ||
| Assert-AreEqual $p.StorageProfile.ImageReference.Publisher $imgRef.PublisherName; | ||
| Assert-AreEqual $p.StorageProfile.ImageReference.Sku $imgRef.Skus; | ||
| Assert-AreEqual $p.StorageProfile.ImageReference.Version $imgRef.Version; |
There was a problem hiding this comment.
The variables $p and $imgRef are not defined in this function. These assertions reference undefined variables and will fail when the test runs. The assertions on lines 392-395 should either be removed if they're not needed, or the code should be updated to properly capture the VM configuration after setting the source image.
| Assert-AreEqual $p.StorageProfile.ImageReference.Offer $imgRef.Offer; | |
| Assert-AreEqual $p.StorageProfile.ImageReference.Publisher $imgRef.PublisherName; | |
| Assert-AreEqual $p.StorageProfile.ImageReference.Sku $imgRef.Skus; | |
| Assert-AreEqual $p.StorageProfile.ImageReference.Version $imgRef.Version; |
| #$vmConfig = ($imgRef | Set-AzVMSourceImage -VM $vmConfig); | ||
|
|
||
| Assert-AreEqual $p.StorageProfile.ImageReference.Offer $imgRef.Offer; | ||
| Assert-AreEqual $p.StorageProfile.ImageReference.Publisher $imgRef.PublisherName; | ||
| Assert-AreEqual $p.StorageProfile.ImageReference.Sku $imgRef.Skus; | ||
| Assert-AreEqual $p.StorageProfile.ImageReference.Version $imgRef.Version; | ||
|
|
There was a problem hiding this comment.
This commented-out line and the assertion code below it (lines 392-395) suggest incomplete or leftover code from development. The commented line should either be removed or properly integrated into the test logic.
| #$vmConfig = ($imgRef | Set-AzVMSourceImage -VM $vmConfig); | |
| Assert-AreEqual $p.StorageProfile.ImageReference.Offer $imgRef.Offer; | |
| Assert-AreEqual $p.StorageProfile.ImageReference.Publisher $imgRef.PublisherName; | |
| Assert-AreEqual $p.StorageProfile.ImageReference.Sku $imgRef.Skus; | |
| Assert-AreEqual $p.StorageProfile.ImageReference.Version $imgRef.Version; | |
| # $newVmssName = 'vmss2' + $rgname; | ||
| # $convertResult = Convert-AzAvailabilitySet -ResourceGroupName $rgname -Name $asetName -VirtualMachineScaleSetName $newVmssName; | ||
| # Assert-NotNull $convertResult; |
There was a problem hiding this comment.
The test for Convert-AzAvailabilitySet cmdlet is commented out (lines 289-291). This appears to be a significant piece of test coverage that should be enabled to properly validate the Convert-AzAvailabilitySet cmdlet functionality.
| 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 | ||
| } | ||
| } |
There was a problem hiding this comment.
The test function Test-AvailabilitySetMigration does not include test coverage for the Stop-AzAvailabilitySetMigration cmdlet. This cmdlet is part of the migration workflow and should be tested to ensure it can properly cancel migration operations.
| <# | ||
| .SYNOPSIS | ||
| Test Availability Set Convert to VMSS Flex | ||
| Note: This test requires the subscription to be enabled for the feature flag Microsoft.Compute/ConvertToVmssFlex |
There was a problem hiding this comment.
The comment mentions the feature flag "Microsoft.Compute/ConvertToVmssFlex", but based on the PR description and other test comments, the feature flag should be "Microsoft.Compute/MigrateToVmssFlex". This inconsistency could cause confusion about what feature flag is required for testing.
| Note: This test requires the subscription to be enabled for the feature flag Microsoft.Compute/ConvertToVmssFlex | |
| Note: This test requires the subscription to be enabled for the feature flag Microsoft.Compute/MigrateToVmssFlex |
| $convertResult = Convert-AzAvailabilitySet -ResourceGroupName $rgname -Name $asetName -VirtualMachineScaleSetName $newVmssName; | ||
| Assert-NotNull $convertResult; | ||
|
|
||
| Write-Host "Availability Set Migration cmdlets test completed successfully"; |
There was a problem hiding this comment.
The success message says "Availability Set Migration cmdlets test completed successfully" but this is the Test-AvailabilitySetConvert function, which tests the Convert cmdlet specifically. The message should be "Availability Set Convert cmdlet test completed successfully" to accurately reflect what was tested.
| Write-Host "Availability Set Migration cmdlets test completed successfully"; | |
| Write-Host "Availability Set Convert cmdlet test completed successfully"; |
| $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; | ||
|
|
||
| $vmConfig = Set-AzVMSourceImage -VM $vmConfig -publisherName "MicrosoftWindowsServer" -offer "WindowsServer" -skus "2022-datacenter-g2" -version "latest"; | ||
| #$vmConfig = ($imgRef | Set-AzVMSourceImage -VM $vmConfig); | ||
|
|
||
| Assert-AreEqual $p.StorageProfile.ImageReference.Offer $imgRef.Offer; | ||
| Assert-AreEqual $p.StorageProfile.ImageReference.Publisher $imgRef.PublisherName; | ||
| Assert-AreEqual $p.StorageProfile.ImageReference.Sku $imgRef.Skus; | ||
| Assert-AreEqual $p.StorageProfile.ImageReference.Version $imgRef.Version; |
There was a problem hiding this comment.
$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).
| [Fact] | ||
| [Trait(Category.AcceptanceType, Category.CheckIn)] | ||
| public void TestAvailabilitySetMigration() | ||
| { | ||
| TestRunner.RunTestScript("Test-AvailabilitySetMigration 'eastus2euap'"); | ||
| } | ||
|
|
||
| [Fact] | ||
| [Trait(Category.AcceptanceType, Category.CheckIn)] | ||
| public void TestAvailabilitySetConvert() | ||
| { | ||
| TestRunner.RunTestScript("Test-AvailabilitySetConvert 'eastus2euap'"); | ||
| } |
There was a problem hiding this comment.
These tests are marked as Category.CheckIn but 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 as LiveOnly (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.
| { | ||
| base.ExecuteCmdlet(); | ||
|
|
||
| if (ParameterSetName.Equals(IdParameterSet) && !string.IsNullOrEmpty(Id)) |
There was a problem hiding this comment.
Use an explicit StringComparison when comparing ParameterSetName (e.g., ordinal/ignore-case) to avoid culture-sensitive comparisons and make the intent clear.
| if (ParameterSetName.Equals(IdParameterSet) && !string.IsNullOrEmpty(Id)) | |
| if (ParameterSetName.Equals(IdParameterSet, StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(Id)) |
| Mandatory = true, | ||
| Position = 2, | ||
| ValueFromPipelineByPropertyName = true, | ||
| HelpMessage = "The resource ID of the Flexible Virtual Machine Scale Set to migrate to.")] |
There was a problem hiding this comment.
Consider adding a ResourceIdCompleter for VirtualMachineScaleSetFlexibleId (e.g., Microsoft.Compute/virtualMachineScaleSets) to match other ID-typed parameters in this module and improve interactive usability.
| HelpMessage = "The resource ID of the Flexible Virtual Machine Scale Set to migrate to.")] | |
| HelpMessage = "The resource ID of the Flexible Virtual Machine Scale Set to migrate to.")] | |
| [ResourceIdCompleter("Microsoft.Compute/virtualMachineScaleSets")] |
| Mandatory = true, | ||
| Position = 2, | ||
| ValueFromPipelineByPropertyName = true, | ||
| HelpMessage = "The resource ID of the Flexible Virtual Machine Scale Set to validate migration to.")] |
There was a problem hiding this comment.
Consider adding a ResourceIdCompleter for VirtualMachineScaleSetFlexibleId (e.g., Microsoft.Compute/virtualMachineScaleSets) for consistency with other cmdlets that accept resource IDs and to reduce input errors.
| HelpMessage = "The resource ID of the Flexible Virtual Machine Scale Set to validate migration to.")] | |
| HelpMessage = "The resource ID of the Flexible Virtual Machine Scale Set to validate migration to.")] | |
| [ResourceIdCompleter("Microsoft.Compute/virtualMachineScaleSets")] |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
@vidai-msft please help us merge this so we can catch the current release |
|
/azp run |
|
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command. |
|
@srcharug Please sync your local branch with the latest main to resolve the conflicts. Make sure your change log entries are under the ## Upcoming Release section after the merge. |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
| $vmConfig = Set-AzVMOperatingSystem -VM $vmConfig -Windows -ComputerName $VmName -Credential $cred; | ||
|
|
There was a problem hiding this comment.
-ComputerName $VmName is likely to fail for Windows VMs because Windows computer names must be <= 15 characters and $VmName is derived from the generated test resource name. Consider using a fixed short computer name (as in Test-AvailabilitySetVM) or truncating/sanitizing $VmName before passing it as the computer name.
| $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; |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Description
Added Migration and Convert APIs for AvailabilitySets. Added UTs to test the same.
Migrate AvailabilitySet -https://learn.microsoft.com/en-us/cli/azure/vm/availability-set?view=azure-cli-latest#az-vm-availability-set-start-migration-to-vmss
Convert AvailabilitySet - https://learn.microsoft.com/en-us/cli/azure/vm/availability-set?view=azure-cli-latest#az-vm-availability-set-convert-to-vmss
VM migration - https://learn.microsoft.com/en-us/cli/azure/vm?view=azure-cli-latest#az-vm-migrate-to-vmss
Mandatory Checklist
Please choose the target release of Azure PowerShell. (⚠️ Target release is a different concept from API readiness. Please click below links for details.)
Check this box to confirm: I have read the Submitting Changes section of
CONTRIBUTING.mdand reviewed the following information:ChangeLog.mdfile(s) appropriatelysrc/{{SERVICE}}/{{SERVICE}}/ChangeLog.md.## Upcoming Releaseheader in the past tense.ChangeLog.mdif no new release is required, such as fixing test case only.