Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Compute/Compute.Test/ScenarioTests/AvailabilitySetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,19 @@ public void TestAvailabilitySetVM()
{
TestRunner.RunTestScript("Test-AvailabilitySetVM");
}

[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'");
}
Comment on lines +41 to +53
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.
}
}
166 changes: 166 additions & 0 deletions src/Compute/Compute.Test/ScenarioTests/AvailabilitySetTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

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

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

Suggested change
$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 uses AI. Check for mistakes.
$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;
Comment on lines +383 to +395
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.

New-AzVM -ResourceGroupName $ResourceGroupName -Location $Location -VM $vmConfig;
return Get-AzVM -ResourceGroupName $ResourceGroupName -Name $VmName;
}
Loading