@@ -2771,7 +2771,6 @@ function Test-VirtualMachineScaleSetSpotRestorePolicy
2771
2771
$rgname = Get-ComputeTestResourceName
2772
2772
try
2773
2773
{
2774
-
2775
2774
# Common
2776
2775
[string ]$loc = " eastus" ;
2777
2776
@@ -3451,6 +3450,256 @@ function Test-VirtualMachineScaleSetGuestAttestation
3451
3450
Assert-AreEqual $extDefaultName $vmssvm.Resources [2 ].Name;
3452
3451
3453
3452
3453
+ }
3454
+ finally
3455
+ {
3456
+ # Cleanup
3457
+ Clean - ResourceGroup $rgname ;
3458
+ }
3459
+ }
3460
+
3461
+ <#
3462
+ . SYNOPSIS
3463
+ A helper function to validate the PriorityMix split between Spot and Regular priority VMs in a VMSS with Flexible OrchestrationMode
3464
+ #>
3465
+ function ValidatePriorityMixSplit ($vmssVMList , $expectedRegularPriorityCount , $expectedSpotPriorityCount )
3466
+ {
3467
+ $regularCountActual = 0 ;
3468
+ $spotCountActual = 0 ;
3469
+
3470
+ # we need to do an individual call on each vm since the Get-AzVmssVM cmdlet returns a limited list of VM properties
3471
+ Foreach ($vm in $vmssVMList )
3472
+ {
3473
+ $vmName = $vm.Name ;
3474
+ $vmResponse = Get-AzVM - ResourceGroupName $rgname - Name $vmName ;
3475
+
3476
+ Assert-NotNull $vmResponse ;
3477
+
3478
+ $vmPriority = $vmResponse.Priority ;
3479
+
3480
+ if ($vmPriority -eq " Regular" ){ $regularCountActual += 1 }
3481
+ elseif ($vmPriority -eq " Spot" ){ $spotCountActual += 1 }
3482
+ }
3483
+
3484
+ Assert-AreEqual $expectedRegularPriorityCount $regularCountActual ;
3485
+ Assert-AreEqual $expectedSpotPriorityCount $spotCountActual ;
3486
+ }
3487
+
3488
+ <#
3489
+ . SYNOPSIS
3490
+ Test Virtual Machine Scale Set PriorityMixPolicy for VMSS with Flexible OrchestrationMode
3491
+ #>
3492
+ function Test-VirtualMachineScaleSetPriorityMixPolicy
3493
+ {
3494
+ # Setup
3495
+ $rgname = Get-ComputeTestResourceName ;
3496
+
3497
+ try
3498
+ {
3499
+ $loc = " eastus" ;
3500
+ $vmssName = " PriMixPol" ;
3501
+ $vmNamePrefix = " VMPriMix" ;
3502
+ $vmssInstanceCount = 2 ;
3503
+ $vmssSku = " Standard_DS1_v2" ;
3504
+
3505
+ New-AzResourceGroup - Name $rgname - Location $loc - Force;
3506
+
3507
+ $securePassword = Get-PasswordForVM | ConvertTo-SecureString - AsPlainText - Force;
3508
+ $cred = New-Object System.Management.Automation.PSCredential (" azureuser" , $securePassword );
3509
+
3510
+ $vnetname = " myVnet" ;
3511
+ $vnetAddress = " 10.0.0.0/16" ;
3512
+ $subnetname = " default-slb" ;
3513
+ $subnetAddress = " 10.0.2.0/24" ;
3514
+
3515
+ # set up networking
3516
+ # VMSS Flex requires explicit outbound access
3517
+ $frontendSubnet = New-AzVirtualNetworkSubnetConfig - Name $subnetname - AddressPrefix $subnetAddress ;
3518
+ $virtualNetwork = New-AzVirtualNetwork - Name $vnetname - ResourceGroupName $rgname - Location $loc - AddressPrefix $vnetAddress - Subnet $frontendSubnet ;
3519
+
3520
+ # # Create a public IP address
3521
+ $publicIP = New-AzPublicIpAddress `
3522
+ - ResourceGroupName $rgname `
3523
+ - Location $loc `
3524
+ - AllocationMethod Static `
3525
+ - Sku " Standard" `
3526
+ - IpAddressVersion " IPv4" `
3527
+ - Name " myLBPublicIP" ;
3528
+
3529
+ # Create a frontend and backend IP pool
3530
+ $frontendIP = New-AzLoadBalancerFrontendIpConfig `
3531
+ - Name " myFrontEndPool" `
3532
+ - PublicIpAddress $publicIP ;
3533
+
3534
+ $backendPool = New-AzLoadBalancerBackendAddressPoolConfig `
3535
+ - Name " myBackEndPool" ;
3536
+
3537
+ # Create the load balancer
3538
+ $lb = New-AzLoadBalancer `
3539
+ - ResourceGroupName $rgname `
3540
+ - Name " myLoadBalancer" `
3541
+ - Sku " Standard" `
3542
+ - Tier " Regional" `
3543
+ - Location $loc `
3544
+ - FrontendIpConfiguration $frontendIP `
3545
+ - BackendAddressPool $backendPool ;
3546
+
3547
+ # # Create a load balancer health probe for TCP port 80
3548
+ Add-AzLoadBalancerProbeConfig - Name " myHealthProbe" `
3549
+ - LoadBalancer $lb `
3550
+ - Protocol TCP `
3551
+ - Port 80 `
3552
+ - IntervalInSeconds 15 `
3553
+ - ProbeCount 2 ;
3554
+
3555
+ # # Create a load balancer rule to distribute traffic on port TCP 80
3556
+ # # The health probe from the previous step is used to make sure that traffic is
3557
+ # # only directed to healthy VM instances
3558
+ Add-AzLoadBalancerRuleConfig `
3559
+ - Name " myLoadBalancerRule" `
3560
+ - LoadBalancer $lb `
3561
+ - FrontendIpConfiguration $lb.FrontendIpConfigurations [0 ] `
3562
+ - BackendAddressPool $lb.BackendAddressPools [0 ] `
3563
+ - Protocol TCP `
3564
+ - FrontendPort 80 `
3565
+ - BackendPort 80 `
3566
+ - DisableOutboundSNAT `
3567
+ - Probe (Get-AzLoadBalancerProbeConfig - Name " myHealthProbe" - LoadBalancer $lb );
3568
+
3569
+ # Add outbound connectivity rule
3570
+ Add-AzLoadBalancerOutboundRuleConfig `
3571
+ - Name " outboundrule" `
3572
+ - LoadBalancer $lb `
3573
+ - AllocatedOutboundPort ' 9000' `
3574
+ - Protocol ' All' `
3575
+ - IdleTimeoutInMinutes ' 15' `
3576
+ - FrontendIpConfiguration $lb.FrontendIpConfigurations [0 ] `
3577
+ - BackendAddressPool $lb.BackendAddressPools [0 ] ;
3578
+
3579
+ # Update the load balancer configuration
3580
+ Set-AzLoadBalancer - LoadBalancer $lb ;
3581
+
3582
+ # Create IP address configurations
3583
+ # Instances will require explicit outbound connectivity, for example
3584
+ # - NAT Gateway on the subnet (recommended)
3585
+ # - Instances in backend pool of Standard LB with outbound connectivity rules
3586
+ # - Public IP address on each instance
3587
+ # See aka.ms/defaultoutboundaccess for more info
3588
+ $ipConfig = New-AzVmssIpConfig `
3589
+ - Name " myIPConfig" `
3590
+ - SubnetId $virtualNetwork.Subnets [0 ].Id `
3591
+ - LoadBalancerBackendAddressPoolsId $lb.BackendAddressPools [0 ].Id `
3592
+ - Primary;
3593
+
3594
+ $baseRegularPriorityVMCount = 0 ;
3595
+ $regularPriorityVMPercentage = 50 ;
3596
+
3597
+ # Create a config object
3598
+ # The VMSS config object stores the core information for creating a scale set
3599
+ $vmssConfig = New-AzVmssConfig `
3600
+ - Location $loc `
3601
+ - SkuCapacity $vmssInstanceCount `
3602
+ - SkuName $vmssSku `
3603
+ - OrchestrationMode ' Flexible' `
3604
+ - EvictionPolicy ' Delete' `
3605
+ - PlatformFaultDomainCount 1 `
3606
+ - Priority ' Spot' `
3607
+ - BaseRegularPriorityCount $baseRegularPriorityVMCount `
3608
+ - RegularPriorityPercentage $regularPriorityVMPercentage ;
3609
+
3610
+ # Reference a virtual machine image from the gallery
3611
+ Set-AzVmssStorageProfile $vmssConfig `
3612
+ - OsDiskCreateOption " FromImage" `
3613
+ - ImageReferencePublisher " MicrosoftWindowsServer" `
3614
+ - ImageReferenceOffer " WindowsServer" `
3615
+ - ImageReferenceSku " 2022-datacenter-azure-edition-core-smalldisk" `
3616
+ - ImageReferenceVersion " latest" ;
3617
+
3618
+ # Set up information for authenticating with the virtual machine
3619
+ Set-AzVmssOsProfile $vmssConfig `
3620
+ - AdminUsername $cred.UserName `
3621
+ - AdminPassword $cred.Password `
3622
+ - ComputerNamePrefix $vmNamePrefix `
3623
+ - WindowsConfigurationProvisionVMAgent $true `
3624
+ - WindowsConfigurationPatchMode " AutomaticByPlatform" `
3625
+ - EnableHotpatching;
3626
+
3627
+ # Attach the virtual network to the config object
3628
+ Add-AzVmssNetworkInterfaceConfiguration `
3629
+ - VirtualMachineScaleSet $vmssConfig `
3630
+ - Name " network-config" `
3631
+ - Primary $true `
3632
+ - IPConfiguration $ipConfig `
3633
+ - NetworkApiVersion ' 2020-11-01' ;
3634
+
3635
+ # Define the Application Health extension properties
3636
+ $publicConfig = @ {" protocol" = " http" ; " port" = 80 ; " requestPath" = " /healthEndpoint" };
3637
+ $extensionName = " myHealthExtension" ;
3638
+ $extensionType = " ApplicationHealthWindows" ;
3639
+ $publisher = " Microsoft.ManagedServices" ;
3640
+
3641
+ # Add the Application Health extension to the scale set model
3642
+ Add-AzVmssExtension - VirtualMachineScaleSet $vmssConfig `
3643
+ - Name $extensionName `
3644
+ - Publisher $publisher `
3645
+ - Setting $publicConfig `
3646
+ - Type $extensionType `
3647
+ - TypeHandlerVersion " 1.0" `
3648
+ - AutoUpgradeMinorVersion $True ;
3649
+
3650
+ # Create the scale set with the config object
3651
+ New-AzVmss `
3652
+ - ResourceGroupName $rgname `
3653
+ - Name $vmssName `
3654
+ - VirtualMachineScaleSet $vmssConfig ;
3655
+
3656
+ $vmss = Get-AzVmss - ResourceGroupName $rgname - Name $vmssName ;
3657
+
3658
+ Assert-AreEqual $baseRegularPriorityVMCount $vmss.PriorityMixPolicy.BaseRegularPriorityCount ;
3659
+ Assert-AreEqual $regularPriorityVMPercentage $vmss.PriorityMixPolicy.RegularPriorityPercentageAboveBase ;
3660
+
3661
+ # validate priority mix split after create
3662
+ $vmssVMsAfterCreate = Get-AzVmssVM - ResourceGroupName $rgname - VMScaleSetName $vmssName
3663
+ $expectedRegularCount = 1 ;
3664
+ $expectedSpotCount = 1 ;
3665
+
3666
+ ValidatePriorityMixSplit $vmssVMsAfterCreate $expectedRegularCount $expectedSpotCount ;
3667
+
3668
+ # perform a scale out with updated priority mix policy
3669
+ $scaleOutCapacity = $vmssInstanceCount + 4 ;
3670
+ $updatedRegularPriorityCount = 2 ;
3671
+ $updatedRegularPriorityPercentage = 33 ;
3672
+
3673
+ $vmss.sku.Capacity = $scaleOutCapacity ;
3674
+ $vmss.PriorityMixPolicy.BaseRegularPriorityCount = $updatedRegularPriorityCount ;
3675
+ $vmss.PriorityMixPolicy.RegularPriorityPercentageAboveBase = $updatedRegularPriorityPercentage ;
3676
+
3677
+ Update-AzVmss - ResourceGroupName $rgname - Name $vmssName - VirtualMachineScaleSet $vmss ;
3678
+ $vmss = Get-AzVmss - ResourceGroupName $rgname - Name $vmssName ;
3679
+
3680
+ # validate the vmss with updated priority mix parameters
3681
+ Assert-AreEqual $updatedRegularPriorityCount $vmss.PriorityMixPolicy.BaseRegularPriorityCount ;
3682
+ Assert-AreEqual $updatedRegularPriorityPercentage $vmss.PriorityMixPolicy.RegularPriorityPercentageAboveBase ;
3683
+
3684
+ $vmssVMsAfterScaleOut = Get-AzVmssVM - ResourceGroupName $rgname - VMScaleSetName $vmssName ;
3685
+ $expectedRegularCount = 3 ;
3686
+ $expectedSpotCount = 3 ;
3687
+
3688
+ ValidatePriorityMixSplit $vmssVMsAfterScaleOut $expectedRegularCount $expectedSpotCount ;
3689
+
3690
+ # perform a scale in while keeping priority mix policy the same
3691
+ $scaleInCapacity = $scaleOutCapacity - 4
3692
+ $vmss.sku.capacity = $scaleInCapacity ;
3693
+
3694
+ Update-AzVmss - ResourceGroupName $rgname - Name $vmssName - VirtualMachineScaleSet $vmss ;
3695
+ $vmss = Get-AzVmss - ResourceGroupName $rgname - Name $vmssName ;
3696
+
3697
+ # validate the VMSS after scale in
3698
+ $vmssVMsAfterScaleIn = Get-AzVmssVM - ResourceGroupName $rgname - VMScaleSetName $vmssName ;
3699
+ $expectedRegularCount = 2 ;
3700
+ $expectedSpotCount = 0 ;
3701
+
3702
+ ValidatePriorityMixSplit $vmssVMsAfterScaleIn $expectedRegularCount $expectedSpotCount ;
3454
3703
}
3455
3704
finally
3456
3705
{
0 commit comments