Skip to content

Conversation

@srcharug
Copy link
Contributor

@srcharug srcharug commented Jan 20, 2026

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

  • SHOULD update ChangeLog.md file(s) appropriately
    • Update src/{{SERVICE}}/{{SERVICE}}/ChangeLog.md.
      • A snippet outlining the change(s) made in the PR should be written under the ## Upcoming Release header in the past tense.
    • Should not change ChangeLog.md if no new release is required, such as fixing test case only.
  • SHOULD regenerate markdown help files if there is cmdlet API change. Instruction
  • SHOULD have proper test coverage for changes in pull request.
  • SHOULD NOT adjust version of module manually in pull request

@azure-client-tools-bot-prd
Copy link

Thanks for your contribution! The pull request validation has started. Please revisit this comment for updated status.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +392 to +395
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;
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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;

Copilot uses AI. Check for mistakes.
Comment on lines +390 to +396
#$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;

Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
#$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;

Copilot uses AI. Check for mistakes.
Comment on lines +289 to +291
# $newVmssName = 'vmss2' + $rgname;
# $convertResult = Convert-AzAvailabilitySet -ResourceGroupName $rgname -Name $asetName -VirtualMachineScaleSetName $newVmssName;
# Assert-NotNull $convertResult;
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +240 to +300
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
}
}
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
<#
.SYNOPSIS
Test Availability Set Convert to VMSS Flex
Note: This test requires the subscription to be enabled for the feature flag Microsoft.Compute/ConvertToVmssFlex
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
$convertResult = Convert-AzAvailabilitySet -ResourceGroupName $rgname -Name $asetName -VirtualMachineScaleSetName $newVmssName;
Assert-NotNull $convertResult;

Write-Host "Availability Set Migration cmdlets test completed successfully";
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
Write-Host "Availability Set Migration cmdlets test completed successfully";
Write-Host "Availability Set Convert cmdlet test completed successfully";

Copilot uses AI. Check for mistakes.
@isra-fel
Copy link
Member

/azp run

@azure-pipelines
Copy link
Contributor

Azure Pipelines successfully started running 3 pipeline(s).

* Updated Azure.Core from 1.45.0 to 1.47.3
* Added `-EnableAutomaticUpgrade` and `-TreatFailureAsDeploymentFailure` parameters (Bool) to `New-AzVmGalleryApplication` and `New-AzVmssGalleryApplication` cmdlets.
* Added `-EnableAutomaticUpgrade` and `-TreatFailureAsDeploymentFailure` parameters (Switch) to `Add-AzVmGalleryApplication` and `Add-AzVmssGalleryApplication` cmdlets.
* Added new cmdlets for Availability Set to Virtual Machine Scale Set (VMSS) Flex migration (Public Preview)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sync your local branch with the latest main. The position of the change log entries is incorrect.

@github-actions
Copy link

This PR was labeled "needs-revision" because it has unresolved review comments or CI failures.
Please resolve all open review comments and make sure all CI checks are green. Refer to our guide to troubleshoot common CI failures.

haagha
haagha previously approved these changes Jan 22, 2026
Copilot AI review requested due to automatic review settings January 23, 2026 00:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 16 changed files in this pull request and generated 5 comments.

Comment on lines +383 to +395
$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;
Copy link

Copilot AI Jan 23, 2026

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).

Copilot uses AI. Check for mistakes.
Comment on lines +41 to +53
[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'");
}
Copy link

Copilot AI Jan 23, 2026

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.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.

Copilot uses AI. Check for mistakes.
{
base.ExecuteCmdlet();

if (ParameterSetName.Equals(IdParameterSet) && !string.IsNullOrEmpty(Id))
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use an explicit StringComparison when comparing ParameterSetName (e.g., ordinal/ignore-case) to avoid culture-sensitive comparisons and make the intent clear.

Suggested change
if (ParameterSetName.Equals(IdParameterSet) && !string.IsNullOrEmpty(Id))
if (ParameterSetName.Equals(IdParameterSet, StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(Id))

Copilot uses AI. Check for mistakes.
Mandatory = true,
Position = 2,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The resource ID of the Flexible Virtual Machine Scale Set to migrate to.")]
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a ResourceIdCompleter for VirtualMachineScaleSetFlexibleId (e.g., Microsoft.Compute/virtualMachineScaleSets) to match other ID-typed parameters in this module and improve interactive usability.

Suggested change
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")]

Copilot uses AI. Check for mistakes.
Mandatory = true,
Position = 2,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The resource ID of the Flexible Virtual Machine Scale Set to validate migration to.")]
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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")]

Copilot uses AI. Check for mistakes.
@isra-fel
Copy link
Member

/azp run

@azure-pipelines
Copy link
Contributor

Azure Pipelines successfully started running 3 pipeline(s).

@srcharug srcharug changed the title Migration ps PS Support for Migration AvailaibilitySets APIs Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants