Skip to content

Commit cd7916b

Browse files
authored
[Compute] Bug fix for Update-Azvmss (#22601)
* Bug fix * Adding test recording * Fixing tests * adding tests * updated changelog
1 parent 4922da0 commit cd7916b

File tree

9 files changed

+19085
-3965
lines changed

9 files changed

+19085
-3965
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,5 +353,13 @@ public void TestVirtualMachineScaleSetSecurityTypeStandardWithConfig()
353353
{
354354
TestRunner.RunTestScript("Test-VirtualMachineScaleSetSecurityTypeStandardWithConfig");
355355
}
356+
357+
[Fact]
358+
[Trait(Category.AcceptanceType, Category.CheckIn)]
359+
public void TestVirtualMachineScaleSetImageReferenceSkuUpdate()
360+
{
361+
TestRunner.RunTestScript("Test-VirtualMachineScaleSetImageReferenceSkuUpdate");
362+
}
363+
356364
}
357365
}

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

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ function Test-VirtualMachineScaleSetUpdate
450450
$adminUsername = 'Foo12';
451451
$adminPassword = $PLACEHOLDER;
452452

453-
$imgRef = Get-DefaultCRPImage -loc $loc;
453+
$imgRef = Get-DefaultCRPImage -loc $loc -New $True;
454454
$vhdContainer = "https://" + $stoname + ".blob.core.windows.net/" + $vmssName;
455455

456456
$extname = 'csetest';
@@ -1391,7 +1391,7 @@ function Test-VirtualMachineScaleSetRollingUpgrade
13911391
try
13921392
{
13931393
# Common
1394-
[string]$loc = Get-ComputeVMLocation;
1394+
[string]$loc = "westus2";
13951395
$loc = $loc.Replace(' ', '');
13961396

13971397
New-AzResourceGroup -Name $rgname -Location $loc -Force;
@@ -1407,7 +1407,7 @@ function Test-VirtualMachineScaleSetRollingUpgrade
14071407
$vnet = New-AzVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -Subnet $subnet;
14081408
$vnet = Get-AzVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname;
14091409
$subnetId = $vnet.Subnets[0].Id;
1410-
$pubip = New-AzPublicIpAddress -Force -Name ('pubip' + $rgname) -ResourceGroupName $rgname -Location $loc -AllocationMethod Dynamic -DomainNameLabel ('pubip' + $rgname);
1410+
$pubip = New-AzPublicIpAddress -Force -Name ('pubip' + $rgname) -ResourceGroupName $rgname -Location $loc -AllocationMethod Static -DomainNameLabel ('pubip' + $rgname);
14111411
$pubip = Get-AzPublicIpAddress -Name ('pubip' + $rgname) -ResourceGroupName $rgname;
14121412

14131413

@@ -1440,7 +1440,7 @@ function Test-VirtualMachineScaleSetRollingUpgrade
14401440
$adminUsername = 'Foo12';
14411441
$adminPassword = $PLACEHOLDER;
14421442

1443-
$imgRef = Get-DefaultCRPImage -loc $loc;
1443+
$imgRef = Get-DefaultCRPImage -loc $loc -New $True;
14441444
$storageUri = "https://" + $stoname + ".blob.core.windows.net/"
14451445
$vhdContainer = "https://" + $stoname + ".blob.core.windows.net/" + $vmssName;
14461446

@@ -1456,7 +1456,7 @@ function Test-VirtualMachineScaleSetRollingUpgrade
14561456
-LoadBalancerBackendAddressPoolsId $expectedLb.BackendAddressPools[0].Id `
14571457
-SubnetId $subnetId;
14581458

1459-
$vmss = New-AzVmssConfig -Location $loc -SkuCapacity 2 -SkuName 'Standard_A0' -UpgradePolicyMode 'Rolling' -HealthProbeId $expectedLb.Probes[0].Id `
1459+
$vmss = New-AzVmssConfig -Location $loc -SkuCapacity 2 -SkuName 'Standard_DS1_v2' -UpgradePolicyMode 'Rolling' -HealthProbeId $expectedLb.Probes[0].Id `
14601460
| Add-AzVmssNetworkInterfaceConfiguration -Name 'test' -Primary $true -IPConfiguration $ipCfg `
14611461
| Set-AzVmssOSProfile -ComputerNamePrefix 'test' -AdminUsername $adminUsername -AdminPassword $adminPassword `
14621462
| Set-AzVmssStorageProfile -Name 'test' -OsDiskCreateOption 'FromImage' -OsDiskCaching 'None' `
@@ -1481,10 +1481,14 @@ function Test-VirtualMachineScaleSetRollingUpgrade
14811481
$job = Start-AzVmssRollingOSUpgrade -ResourceGroupName $rgname -VMScaleSetName $vmssName -AsJob;
14821482
$result = $job | Wait-Job;
14831483
Assert-AreEqual "Failed" $result.State;
1484-
Assert-True { $result.Error[0].ToString().Contains("failed after exceeding the MaxUnhealthyInstancePercent value ")};
1484+
Write-Debug $result;
1485+
Write-Debug $result.Error[0].ToString();
1486+
Assert-True { $result.Error[0].ToString().Contains("failed due to exceeding the MaxUnhealthyInstancePercent value ")};
14851487

14861488
$job = Stop-AzVmssRollingUpgrade -ResourceGroupName $rgname -VMScaleSetName $vmssName -Force -AsJob;
14871489
$result = $job | Wait-Job;
1490+
Write-Debug $result;
1491+
Write-Debug $result.Error[0].ToString();
14881492
Assert-AreEqual "Failed" $result.State;
14891493
Assert-True { $result.Error[0].ToString().Contains("There is no ongoing Rolling Upgrade to cancel.")};
14901494
}
@@ -2130,7 +2134,7 @@ function Test-VirtualMachineScaleSetAutoRollback
21302134

21312135
$adminUsername = 'Foo12';
21322136
$adminPassword = $PLACEHOLDER;
2133-
$imgRef = Get-DefaultCRPImage -loc $loc;
2137+
$imgRef = Get-DefaultCRPImage -loc $loc -New $True;
21342138

21352139
$extname = 'csetest';
21362140
$publisher = 'Microsoft.Compute';
@@ -2547,7 +2551,7 @@ function Test-VirtualMachineScaleSetEncryptionAtHost
25472551
$cred = New-Object System.Management.Automation.PSCredential ($adminUsername, $securePassword);
25482552

25492553

2550-
$imgRef = Get-DefaultCRPImage -loc $loc;
2554+
$imgRef = Get-DefaultCRPImage -loc $loc -New $True;
25512555
$ipCfg = New-AzVmssIPConfig -Name 'test' -SubnetId $subnetId;
25522556

25532557
$vmss = New-AzVmssConfig -Location $loc -SkuCapacity 2 -SkuName 'Standard_E4-2ds_v4' -UpgradePolicyMode 'Manual' -EncryptionAtHost `
@@ -4741,3 +4745,49 @@ function Test-VirtualMachineScaleSetSecurityTypeStandardWithConfig
47414745
Clean-ResourceGroup $rgname;
47424746
}
47434747
}
4748+
4749+
4750+
<#
4751+
.SYNOPSIS
4752+
Test Virtual Machine Scale ImageReferenceSku Update
4753+
using Update-Azvmss
4754+
#>
4755+
function Test-VirtualMachineScaleSetImageReferenceSkuUpdate
4756+
{
4757+
# Setup
4758+
$rgname = Get-ComputeTestResourceName;
4759+
$loc = Get-ComputeVMLocation;
4760+
4761+
try
4762+
{
4763+
# Common
4764+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
4765+
4766+
$vmssSize = 'Standard_D4s_v3';
4767+
$vmssName1 = 'vmss1' + $rgname;
4768+
$imageName = "Win2016DataCenter";
4769+
$PublisherName = "MicrosoftWindowsServer";
4770+
$Offer = "WindowsServer";
4771+
$SKU = "2016-datacenter-gensecond";
4772+
$domainNameLabel1 = "d1" + $rgname;
4773+
$domainNameLabel2 = "d2" + $rgname;
4774+
$disable = $false;
4775+
$enable = $true;
4776+
$securityType = "TrustedLaunch";
4777+
$adminUsername = Get-ComputeTestResourceName;
4778+
$adminPassword = Get-PasswordForVM | ConvertTo-SecureString -AsPlainText -Force;
4779+
$vmCred = New-Object System.Management.Automation.PSCredential ($adminUsername, $adminPassword);
4780+
4781+
$res = New-AzVmss -ResourceGroupName $rgname -Credential $vmCred -VMScaleSetName $vmssName1 -ImageName $imageName -DomainNameLabel $domainNameLabel1 ;
4782+
$vmss = Get-AzVmss -ResourceGroupName $rgname -Name $vmssName1;
4783+
Assert-AreEqual $vmss.VirtualMachineProfile.StorageProfile.ImageReference.SKU "2016-datacenter";
4784+
4785+
Update-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName1 -VirtualMachineScaleSet $vmss -ImageReferenceSku 2019-datacenter
4786+
Assert-AreEqual $vmss.VirtualMachineProfile.StorageProfile.ImageReference.SKU "2019-datacenter";
4787+
}
4788+
finally
4789+
{
4790+
# Cleanup
4791+
Clean-ResourceGroup $rgname;
4792+
}
4793+
}

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineScaleSetTests/TestVirtualMachineScaleSetAutoRollback.json

Lines changed: 3325 additions & 832 deletions
Large diffs are not rendered by default.

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineScaleSetTests/TestVirtualMachineScaleSetImageReferenceSkuUpdate.json

Lines changed: 3209 additions & 0 deletions
Large diffs are not rendered by default.

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineScaleSetTests/TestVirtualMachineScaleSetNewEncryptionAtHost.json

Lines changed: 2444 additions & 998 deletions
Large diffs are not rendered by default.

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineScaleSetTests/TestVirtualMachineScaleSetRollingUpgrade.json

Lines changed: 1700 additions & 1021 deletions
Large diffs are not rendered by default.

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineScaleSetTests/TestVirtualMachineScaleSetUpdate.json

Lines changed: 8338 additions & 1105 deletions
Large diffs are not rendered by default.

src/Compute/Compute/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* Updated Azure.Core to 1.34.0.
2626
* Added new cmdlets `Get-AzHostSize` and `Update-AzHost`.
2727
* Added the `Standard` value to the `SecurityType` parameter to the cmdlets `Set-AzDiskSecurityType`, `New-AzvmssConfig`, `Set-AzVmssSecurityProfile`, `Update-AzVmss`, `New-AzVmss`, `New-AzVMConfig`, `Set-AzVMsecurityProfile`, and `New-AzVM`.
28+
* Fixed `Update-AzVMSS` to update ImageReferenceSKU [#22195]
2829
* Updated the above change to include `New-AzVMConfig` as 1 scenario was initially missed when only using this cmdlet.
2930

3031
## Version 6.2.0

src/Compute/Compute/Generated/VirtualMachineScaleSet/VirtualMachineScaleSetUpdateMethod.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public override void ExecuteCmdlet()
6464
if (this.VirtualMachineScaleSet != null
6565
&& this.VirtualMachineScaleSet.VirtualMachineProfile != null
6666
&& this.VirtualMachineScaleSet.VirtualMachineProfile.StorageProfile != null
67-
&& this.VirtualMachineScaleSet.VirtualMachineProfile.StorageProfile.ImageReference != null)
67+
&& this.VirtualMachineScaleSet.VirtualMachineProfile.StorageProfile.ImageReference != null
68+
&& this.VirtualMachineScaleSet.VirtualMachineProfile.StorageProfile.ImageReference.Id != null)
6869
{
6970
var newImageRef = this.VirtualMachineScaleSet.VirtualMachineProfile.StorageProfile.ImageReference;
7071
var currVMSS = VirtualMachineScaleSetsClient.Get(resourceGroupName, vmScaleSetName);

0 commit comments

Comments
 (0)