Skip to content

Commit e009e76

Browse files
raresmihaiRares-Mihai Babuta
andauthored
Add support for Automatic Zone Rebalancing Policy in VMSS cmdlets (#27678)
Co-authored-by: Rares-Mihai Babuta <[email protected]>
1 parent 8797ec4 commit e009e76

File tree

9 files changed

+1795
-37
lines changed

9 files changed

+1795
-37
lines changed

src/Compute/Compute.Test/ScenarioTests/VirtualMachineScaleSetTests.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,16 @@ public void TestVirtualMachineScaleSetSkuProfilePrioritized()
440440

441441
[Fact]
442442
[Trait(Category.AcceptanceType, Category.CheckIn)]
443-
public void TestResiliencyPolicyVMSS()
443+
public void TestResilientVMCreateDelete()
444444
{
445-
TestRunner.RunTestScript("Test-ResiliencyPolicyVMSS");
445+
TestRunner.RunTestScript("Test-ResilientVMCreateDelete");
446+
}
447+
448+
[Fact]
449+
[Trait(Category.AcceptanceType, Category.CheckIn)]
450+
public void TestRebalancingPolicyVMSS()
451+
{
452+
TestRunner.RunTestScript("Test-AutomaticZoneRebalancingPolicy");
446453
}
447454

448455
[Fact]

src/Compute/Compute.Test/ScenarioTests/VirtualMachineScaleSetTests.ps1

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5581,7 +5581,7 @@ function Test-VirtualMachineScaleSetSkuProfilePrioritized
55815581
Update the Resiliency policies of VMSS using Update-Azvmss
55825582
Test ResilientVMCreationPolicy and ResilientVMDeletionPolicy
55835583
#>
5584-
function Test-ResiliencyPolicyVMSS
5584+
function Test-ResilientVMCreateDelete
55855585
{
55865586
# Setup
55875587
$rgname = Get-ComputeTestResourceName
@@ -5617,8 +5617,107 @@ function Test-ResiliencyPolicyVMSS
56175617
Assert-False { $updatedVmss.ResiliencyPolicy.ResilientVMCreationPolicy.Enabled };
56185618
# check ResilientVMDeletionPolicy
56195619
Assert-False { $updatedVmss.ResiliencyPolicy.ResilientVMDeletionPolicy.Enabled };
5620+
}
5621+
finally
5622+
{
5623+
# Cleanup
5624+
Clean-ResourceGroup $rgname
5625+
}
5626+
}
5627+
5628+
<#
5629+
.SYNOPSIS
5630+
Create a VMSS using New-Azvmssconfig
5631+
Update the Resiliency policies of VMSS using Update-Azvmss
5632+
Test AutomaticZoneRebalancingPolicy
5633+
#>
5634+
function Test-AutomaticZoneRebalancingPolicy
5635+
{
5636+
# Setup
5637+
$rgname = Get-ComputeTestResourceName
5638+
5639+
try
5640+
{
5641+
$loc = "eastus2euap"
5642+
$vmssName = "rebalancingVMSS"
5643+
$vnetName = "rebalancingVnet"
5644+
$subnetName = "rebalancingSubnet"
5645+
$rebalanceStrategy = "Recreate"
5646+
$rebalanceBehavior = "CreateBeforeDelete"
5647+
$zones = @("1", "2", "3")
5648+
5649+
# Create resource group
5650+
New-AzResourceGroup -Name $rgname -Location $loc -Force
5651+
5652+
# Create VNet and Subnet
5653+
$subnetConfig = New-AzVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix "10.0.0.0/24" -DefaultOutboundAccess $false
5654+
$vnet = New-AzVirtualNetwork -Name $vnetName `
5655+
-ResourceGroupName $rgname `
5656+
-Location $loc `
5657+
-AddressPrefix "10.0.0.0/16" `
5658+
-Subnet $subnetConfig
5659+
5660+
# Get subnet object
5661+
$subnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname | Get-AzVirtualNetworkSubnetConfig -Name $subnetName
5662+
5663+
# Build VMSS config
5664+
$vmssConfig = New-AzVmssConfig `
5665+
-Location $loc `
5666+
-SkuCapacity 0 `
5667+
-SkuName "Standard_D2s_v3" `
5668+
-UpgradePolicyMode "Automatic" `
5669+
-Zone $zones `
5670+
-EnableAutomaticZoneRebalance `
5671+
-AutomaticZoneRebalanceStrategy $rebalanceStrategy `
5672+
-AutomaticZoneRebalanceBehavior $rebalanceBehavior `
5673+
-SharedGalleryImageId "/SharedGalleries/WindowsServer.1P.Canary/images/2022-DATACENTER-AZURE-EDITION/versions/latest" `
5674+
-SecurityType "TrustedLaunch"
5675+
5676+
# Configure IP and NIC
5677+
$ipCfg = New-AzVmssIpConfig -Name "ipconfig1" -SubnetId $subnet.Id
5678+
$vmssConfig = Add-AzVmssNetworkInterfaceConfiguration -VirtualMachineScaleSet $vmssConfig `
5679+
-Name "nicconfig1" -Primary $true -IPConfiguration $ipCfg
5680+
5681+
# Configure OS
5682+
$adminUsername = Get-ComputeTestResourceName;
5683+
$adminPassword = $PLACEHOLDER;
5684+
$vmssConfig = Set-AzVmssOSProfile -VirtualMachineScaleSet $vmssConfig `
5685+
-ComputerNamePrefix "test" `
5686+
-AdminUsername $adminUsername `
5687+
-AdminPassword $adminPassword
5688+
5689+
# Configure the HealthExtension required for enabling the AutomaticZoneRebalancingPolicy
5690+
$publicConfig = @{
5691+
"protocol" = "http";
5692+
"port" = 80;
5693+
"requestPath" = "/health";
5694+
}
5695+
$vmssConfig = Add-AzVmssExtension -VirtualMachineScaleSet $vmssConfig `
5696+
-Name "ApplicationHealthExtension" `
5697+
-Publisher "Microsoft.ManagedServices" `
5698+
-Type "ApplicationHealthLinux" `
5699+
-TypeHandlerVersion "1.0" `
5700+
-Setting $publicConfig `
5701+
-AutoUpgradeMinorVersion $true
5702+
5703+
# Assert the AutomaticZoneRebalancingPolicy from the vmssConfig
5704+
Assert-True { $vmssConfig.ResiliencyPolicy.AutomaticZoneRebalancingPolicy.Enabled };
5705+
Assert-AreEqual $vmssConfig.ResiliencyPolicy.AutomaticZoneRebalancingPolicy.RebalanceStrategy $rebalanceStrategy
5706+
Assert-AreEqual $vmssConfig.ResiliencyPolicy.AutomaticZoneRebalancingPolicy.RebalanceBehavior $rebalanceBehavior
5707+
5708+
# Create the vmss using the config
5709+
$vmssResult = New-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName -VirtualMachineScaleSet $vmssConfig;
5710+
5711+
# Assert the AutomaticZoneRebalancingPolicy from the vmssResult
5712+
Assert-True { $vmssResult.ResiliencyPolicy.AutomaticZoneRebalancingPolicy.Enabled };
5713+
Assert-AreEqual $vmssResult.ResiliencyPolicy.AutomaticZoneRebalancingPolicy.RebalanceStrategy $rebalanceStrategy
5714+
Assert-AreEqual $vmssResult.ResiliencyPolicy.AutomaticZoneRebalancingPolicy.RebalanceBehavior $rebalanceBehavior
56205715

5716+
# Update vmss
5717+
$vmssUpdate = Update-AzVmss -ResourceGroupName $rgname -Name $vmssName -EnableAutomaticZoneRebalance $false
56215718

5719+
# Assert the AutomaticZoneRebalancingPolicy is now disabled
5720+
Assert-False { $vmssUpdate.ResiliencyPolicy.AutomaticZoneRebalancingPolicy.Enabled };
56225721
}
56235722
finally
56245723
{

0 commit comments

Comments
 (0)