Skip to content

Commit 40d636e

Browse files
Cplat enable automatic upgrade (#13956)
* update for the new parameter * update * Update VirtualMachineScaleSetExtensionTests.cs * Update ChangeLog.md fix change log Co-authored-by: Jin Lei <[email protected]>
1 parent bad3a2d commit 40d636e

File tree

12 files changed

+5078
-9
lines changed

12 files changed

+5078
-9
lines changed

src/Compute/Compute.Test/ScenarioTests/VirtualMachineExtensionTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,5 +176,11 @@ public void TestVirtualMachineADDomainExtensionDomainJoin()
176176
{
177177
TestRunner.RunTestScript("Test-VirtualMachineADDomainExtensionDomainJoin");
178178
}
179+
[Fact]
180+
[Trait(Category.AcceptanceType, Category.CheckIn)]
181+
public void TestVirtualMachineExtensionEnableAutomaticUpgrade()
182+
{
183+
TestRunner.RunTestScript("Test-VirtualMachineExtensionEnableAutomaticUpgrade");
184+
}
179185
}
180186
}

src/Compute/Compute.Test/ScenarioTests/VirtualMachineExtensionTests.ps1

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2519,3 +2519,64 @@ function Test-VirtualMachineADDomainExtensionDomainJoin
25192519
Clean-ResourceGroup $rgname
25202520
}
25212521
}
2522+
2523+
<#
2524+
.SYNOPSIS
2525+
Test Virtual Machine Extensions EnableAutomaticUpgrade
2526+
#>
2527+
function Test-VirtualMachineExtensionEnableAutomaticUpgrade
2528+
{
2529+
# Setup
2530+
$rgname = Get-ComputeTestResourceName;
2531+
2532+
try
2533+
{
2534+
$loc = Get-ComputeVMLocation;
2535+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
2536+
2537+
$user = "Foo2";
2538+
$password = $PLACEHOLDER;
2539+
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
2540+
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
2541+
2542+
$vmname = "extensionTestVM"
2543+
$vmssname = "extensionTestVmss"
2544+
$domainNameLabel = 'pubip'+$rgname;
2545+
$domainNameLabel2 = $domainNameLabel + '2'
2546+
2547+
2548+
# create vm/vmss
2549+
New-AzVM -ResourceGroupName $rgname -Location $loc -name $vmname -credential $cred -domainNameLabel $domainNameLabel
2550+
New-AzVmss -ResourceGroupName $rgname -Location $loc -VMScalesetName $vmssname -credential $cred -domainNameLabel $domainNameLabel2
2551+
2552+
# check vm/vmss
2553+
$vm = Get-AzVM -Name $vmname -ResourceGroupName $rgname;
2554+
Assert-NotNull $vm;
2555+
$vmss = Get-AzVmss -Name $vmssname -ResourceGroupName $rgname;
2556+
Assert-NotNull $vmss;
2557+
2558+
# Extension
2559+
$extname = 'csetest';
2560+
$publisher = 'Microsoft.Compute';
2561+
$exttype = 'CustomScriptExtension';
2562+
$extver = '1.1';
2563+
2564+
# Set extension settings by raw strings
2565+
$settingstr = '{"fileUris":[],"commandToExecute":"powershell Get-Process"}';
2566+
$protectedsettingstr = '{"storageAccountName":"somename","storageAccountKey":"somekey"}';
2567+
2568+
Set-AzVMExtension -ResourceGroupName $rgname -Location $loc -VMName $vmname -Name $extname -Publisher $publisher -ExtensionType $exttype -TypeHandlerVersion $extver -SettingString $settingstr -ProtectedSettingString $protectedsettingstr -enableAutomaticUpgrade $False;
2569+
$VMSSext = Add-AzVmssExtension -VirtualMachineScaleSet $vmss -Name $extname -Publisher $publisher -Type $exttype -TypeHandlerVersion $extver -enableAutomaticUpgrade $False;
2570+
2571+
$VMext = Get-AzVMExtension -ResourceGroupName $rgname -VMName $vmname -Name $extname;
2572+
2573+
# check enableAutomaticUpgrade property
2574+
Assert-False { $VMext.EnableAutomaticUpgrade };
2575+
Assert-False { $VMSSext.VirtualMachineProfile.ExtensionProfile.Extensions[-1].EnableAutomaticUpgrade };
2576+
}
2577+
finally
2578+
{
2579+
# Cleanup
2580+
Clean-ResourceGroup $rgname
2581+
}
2582+
}

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineExtensionTests/TestVirtualMachineExtensionEnableAutomaticUpgrade.json

Lines changed: 4955 additions & 0 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
@@ -20,6 +20,7 @@
2020
2121
-->
2222
## Upcoming Release
23+
* Added parameter `-EnableAutomaticUpgrade` to `Set-AzVmExtension` and `Add-AzVmssExtension`.
2324
* Removed FilterExpression parameter from `Get-AzVMImage` cmdlet documentation.
2425
* Added deprecation message to the ContainerService cmdlets:
2526
- `Add-AzureRmContainerServiceAgentPoolProfileCommand`

src/Compute/Compute/Extension/SetAzureVMExtensionBaseCmdlet.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ public class SetAzureVMExtensionBaseCmdlet : VirtualMachineExtensionBaseCmdlet
6969
HelpMessage = "Disable auto-upgrade of minor version")]
7070
public SwitchParameter DisableAutoUpgradeMinorVersion { get; set; }
7171

72+
[Parameter(
73+
Mandatory = false)]
74+
public bool? EnableAutomaticUpgrade { get; set; }
75+
7276
[Parameter(
7377
Mandatory = false,
7478
ValueFromPipelineByPropertyName = true,

src/Compute/Compute/Extension/SetAzureVMExtensionCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ public override void ExecuteCmdlet()
102102
Settings = this.Settings,
103103
ProtectedSettings = this.ProtectedSettings,
104104
AutoUpgradeMinorVersion = !this.DisableAutoUpgradeMinorVersion.IsPresent,
105-
ForceUpdateTag = this.ForceRerun
105+
ForceUpdateTag = this.ForceRerun,
106+
EnableAutomaticUpgrade = this.EnableAutomaticUpgrade
106107
};
107108

108109
if (NoWait.IsPresent)

src/Compute/Compute/Generated/VirtualMachineScaleSet/Config/AddAzureRmVmssExtensionCommand.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ public partial class AddAzureRmVmssExtensionCommand : Microsoft.Azure.Commands.R
8383
ValueFromPipelineByPropertyName = true)]
8484
public Object ProtectedSetting { get; set; }
8585

86+
[Parameter(
87+
Mandatory = false)]
88+
public bool? EnableAutomaticUpgrade { get; set; }
89+
8690
[Parameter(
8791
Mandatory = false,
8892
ValueFromPipelineByPropertyName = true)]
@@ -132,6 +136,7 @@ private void Run()
132136
vExtensions.Settings = this.IsParameterBound(c => c.Setting) ? this.Setting : null;
133137
vExtensions.ProtectedSettings = this.IsParameterBound(c => c.ProtectedSetting) ? this.ProtectedSetting : null;
134138
vExtensions.ProvisionAfterExtensions = this.IsParameterBound(c => c.ProvisionAfterExtension) ? this.ProvisionAfterExtension : null;
139+
vExtensions.EnableAutomaticUpgrade = this.IsParameterBound(c => c.EnableAutomaticUpgrade) ? this.EnableAutomaticUpgrade : null;
135140
this.VirtualMachineScaleSet.VirtualMachineProfile.ExtensionProfile.Extensions.Add(vExtensions);
136141
WriteObject(this.VirtualMachineScaleSet);
137142
}

src/Compute/Compute/Manual/PSVirtualMachineScaleSetExtension.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class PSVirtualMachineScaleSetExtension
3232
public string Type { get; set; } // This is Type1 in SDK, but mapped to Type to hide a breaking change.
3333
public string TypeHandlerVersion { get; set; }
3434
public bool? AutoUpgradeMinorVersion { get; set; }
35+
public bool? EnableAutomaticUpgrade { get; set; }
3536
public object Settings { get; set; }
3637
public object ProtectedSettings { get; set; }
3738
public string ProvisioningState { get; set; }

src/Compute/Compute/Models/PSVirtualMachineExtension.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class PSVirtualMachineExtension
5252
public bool? AutoUpgradeMinorVersion { get; set; }
5353

5454
public string ForceUpdateTag { get; set; }
55+
public bool? EnableAutomaticUpgrade { get; set; }
5556
}
5657

5758
public static class PSVirtualMachineExtensionConversions
@@ -85,7 +86,8 @@ public static PSVirtualMachineExtension ToPSVirtualMachineExtension(this Virtual
8586
Statuses = ext.InstanceView == null ? null : ext.InstanceView.Statuses,
8687
SubStatuses = ext.InstanceView == null ? null : ext.InstanceView.Substatuses,
8788
AutoUpgradeMinorVersion = ext.AutoUpgradeMinorVersion,
88-
ForceUpdateTag = ext.ForceUpdateTag
89+
ForceUpdateTag = ext.ForceUpdateTag,
90+
EnableAutomaticUpgrade = ext.EnableAutomaticUpgrade
8991
};
9092

9193
return result;

src/Compute/Compute/help/Add-AzVmssExtension.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Adds an extension to the VMSS.
1717
Add-AzVmssExtension [-VirtualMachineScaleSet] <PSVirtualMachineScaleSet> [[-Name] <String>]
1818
[[-Publisher] <String>] [[-Type] <String>] [[-TypeHandlerVersion] <String>]
1919
[[-AutoUpgradeMinorVersion] <Boolean>] [[-Setting] <Object>] [[-ProtectedSetting] <Object>]
20-
[-ForceUpdateTag <String>] [-ProvisionAfterExtension <String[]>] [-DefaultProfile <IAzureContextContainer>]
21-
[-WhatIf] [-Confirm] [<CommonParameters>]
20+
[-EnableAutomaticUpgrade <Boolean>] [-ForceUpdateTag <String>] [-ProvisionAfterExtension <String[]>]
21+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
2222
```
2323

2424
## DESCRIPTION
@@ -77,6 +77,21 @@ Accept pipeline input: False
7777
Accept wildcard characters: False
7878
```
7979
80+
### -EnableAutomaticUpgrade
81+
Indicates whether the extension should be automatically upgraded by the platform if there is a newer version of the extension available.
82+
83+
```yaml
84+
Type: System.Nullable`1[System.Boolean]
85+
Parameter Sets: (All)
86+
Aliases:
87+
88+
Required: False
89+
Position: Named
90+
Default value: None
91+
Accept pipeline input: False
92+
Accept wildcard characters: False
93+
```
94+
8095
### -ForceUpdateTag
8196
If a value is provided and is different from the previous value, the extension handler will be forced to update even if the extension configuration has not changed.
8297

src/Compute/Compute/help/Set-AzVMExtension.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ Updates extension properties or adds an extension to a virtual machine.
1717
```
1818
Set-AzVMExtension -Publisher <String> -ExtensionType <String> [-Settings <Hashtable>]
1919
[-ProtectedSettings <Hashtable>] [-AsJob] [-ResourceGroupName] <String> [-VMName] <String> [-Name <String>]
20-
[-TypeHandlerVersion <String>] [-Location <String>] [-DisableAutoUpgradeMinorVersion] [-ForceRerun <String>]
21-
[-NoWait] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
20+
[-TypeHandlerVersion <String>] [-Location <String>] [-DisableAutoUpgradeMinorVersion]
21+
[-EnableAutomaticUpgrade <Boolean>] [-ForceRerun <String>] [-NoWait]
22+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
2223
```
2324

2425
### SettingString
2526
```
2627
Set-AzVMExtension -Publisher <String> -ExtensionType <String> [-SettingString <String>]
2728
[-ProtectedSettingString <String>] [-AsJob] [-ResourceGroupName] <String> [-VMName] <String> [-Name <String>]
28-
[-TypeHandlerVersion <String>] [-Location <String>] [-DisableAutoUpgradeMinorVersion] [-ForceRerun <String>]
29-
[-NoWait] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
29+
[-TypeHandlerVersion <String>] [-Location <String>] [-DisableAutoUpgradeMinorVersion]
30+
[-EnableAutomaticUpgrade <Boolean>] [-ForceRerun <String>] [-NoWait]
31+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
3032
```
3133

3234
## DESCRIPTION
@@ -106,6 +108,21 @@ Accept pipeline input: True (ByPropertyName)
106108
Accept wildcard characters: False
107109
```
108110
111+
### -EnableAutomaticUpgrade
112+
Indicates whether the extension should be automatically upgraded by the platform if there is a newer version of the extension available.
113+
114+
```yaml
115+
Type: System.Nullable`1[System.Boolean]
116+
Parameter Sets: (All)
117+
Aliases:
118+
119+
Required: False
120+
Position: Named
121+
Default value: None
122+
Accept pipeline input: False
123+
Accept wildcard characters: False
124+
```
125+
109126
### -ExtensionType
110127
Specifies the extension type.
111128

src/Compute/Compute/help/Set-AzVmss.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ This command reimages the VMSS named ContosoVMSS that belongs to the resource gr
5555

5656
Sets specific actions on a specified VMSS. (autogenerated)
5757

58-
```powershell <!-- Aladdin Generated Example -->
58+
```powershell
59+
<!-- Aladdin Generated Example -->
5960
Set-AzVmss -ReimageAll -ResourceGroupName 'ContosoGroup' -VMScaleSetName 'ContosoVMSS'
6061
```
6162

0 commit comments

Comments
 (0)