From b223951274dc9a8420156da72421a5ce5ba2a1c7 Mon Sep 17 00:00:00 2001 From: PSCmdAssistant Date: Tue, 11 Feb 2025 17:50:29 +0000 Subject: [PATCH 1/2] Autogen code --- .../VirtualMachine/InvokeAzureVMInstallPatch.cs | 11 ++++++++++- .../Manual/PSVirtualMachineInstallPatchesResult.cs | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Compute/Compute/Generated/VirtualMachine/InvokeAzureVMInstallPatch.cs b/src/Compute/Compute/Generated/VirtualMachine/InvokeAzureVMInstallPatch.cs index 34bc79958a84..1db77dccaf3f 100644 --- a/src/Compute/Compute/Generated/VirtualMachine/InvokeAzureVMInstallPatch.cs +++ b/src/Compute/Compute/Generated/VirtualMachine/InvokeAzureVMInstallPatch.cs @@ -1,4 +1,4 @@ -// ---------------------------------------------------------------------------------- +// ---------------------------------------------------------------------------------- // // Copyright Microsoft Corporation // Licensed under the Apache License, Version 2.0 (the "License"); @@ -233,6 +233,10 @@ public partial class InvokeAzureVMInstallPatch : ComputeAutomationBaseCmdlet [PSArgumentCompleter("Critical", "Security", "Other")] public string[] ClassificationToIncludeForLinux { get; set; } + [Parameter( + Mandatory = false, + HelpMessage = "This is used to install patches that were published on or before this given max published date. It should be a dateTime parsable date string.")] + public string MaxPatchPublishDate { get; set; } [Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")] public SwitchParameter AsJob { get; set; } @@ -278,6 +282,11 @@ public override void ExecuteCmdlet() vmInstallPatchesParameters.MaximumDuration = this.MaximumDuration; vmInstallPatchesParameters.RebootSetting = this.RebootSetting; + if (!string.IsNullOrEmpty(this.MaxPatchPublishDate)) + { + vmInstallPatchesParameters.MaxPatchPublishDate = DateTime.Parse(this.MaxPatchPublishDate); + } + // divde linux and windows if (this.Windows.IsPresent) { diff --git a/src/Compute/Compute/Manual/PSVirtualMachineInstallPatchesResult.cs b/src/Compute/Compute/Manual/PSVirtualMachineInstallPatchesResult.cs index b57dd90b471e..d1b95d6e9d1f 100644 --- a/src/Compute/Compute/Manual/PSVirtualMachineInstallPatchesResult.cs +++ b/src/Compute/Compute/Manual/PSVirtualMachineInstallPatchesResult.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) Microsoft and contributors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -35,5 +35,6 @@ public class PSVirtualMachineInstallPatchesResult public IList Patches { get; set; } public DateTime? StartDateTime { get; set; } public ApiError Error { get; set; } + public string MaxPatchPublishDate { get; set; } } } From b361dc278df7ab22351db12e1ed5471ae814568f Mon Sep 17 00:00:00 2001 From: PSCmdAssistant Date: Tue, 11 Feb 2025 17:51:05 +0000 Subject: [PATCH 2/2] Test generation and changelog update --- .../ScenarioTests/VirtualMachineTests.cs | 9 ++- .../ScenarioTests/VirtualMachineTests.ps1 | 66 +++++++++++++++++++ src/Compute/Compute/ChangeLog.md | 2 + 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.cs b/src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.cs index 2bae407d5b45..c574623310c0 100644 --- a/src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.cs +++ b/src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.cs @@ -689,5 +689,12 @@ public void TestEncryptionIdentityNotPartOfAssignedIdentitiesInAzureVm() { TestRunner.RunTestScript("Test-EncryptionIdentityNotPartOfAssignedIdentitiesInAzureVm"); } - } + + [Fact] + [Trait(Category.AcceptanceType, Category.CheckIn)] + public void testgeninvokeazvminstallpatch() + { + TestRunner.RunTestScript("TestGen-invokeazvminstallpatch"); + } + } } diff --git a/src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.ps1 b/src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.ps1 index 18026b68e738..5fe8a33417b4 100644 --- a/src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.ps1 +++ b/src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.ps1 @@ -7889,3 +7889,69 @@ function Test-EncryptionIdentityNotPartOfAssignedIdentitiesInAzureVm{ } } + +function TestGen-invokeazvminstallpatch +{ + # Setup + $rgname = Get-ComputeTestResourceName; + $loc = Get-Location; + + try + { + New-AzResourceGroup -Name $rgname -Location $loc -Force; + + # VM Profile & Hardware + $vmname = 'vm' + $rgname; + $vmsize = "Standard_B1s"; + $domainNameLabel = "d1" + $rgname; + $stnd = "Standard"; + + # Creating a VM + $p = New-AzVmConfig -VMName $vmname -vmsize $vmsize -SecurityType $stnd; + + $publisherName = "MicrosoftWindowsServer" + $offer = "WindowsServer" + $sku = "2019-DataCenter" + $p = Set-AzVMSourceImage -VM $p -PublisherName $publisherName -Offer $offer -Skus $sku -Version 'latest' + + # NRP + $subnet = New-AzVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24"; + $vnet = New-AzVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -Subnet $subnet; + $vnet = Get-AzVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname; + $subnetId = $vnet.Subnets[0].Id; + $pubip = New-AzPublicIpAddress -Force -Name ('pubip' + $rgname) -ResourceGroupName $rgname -Location $loc -AllocationMethod Dynamic -DomainNameLabel $domainNameLabel; + $pubip = Get-AzPublicIpAddress -Name ('pubip' + $rgname) -ResourceGroupName $rgname; + $pubipId = $pubip.Id; + $nic = New-AzNetworkInterface -Force -Name ('nic' + $rgname) -ResourceGroupName $rgname -Location $loc -SubnetId $subnetId -PublicIpAddressId $pubip.Id; + $nic = Get-AzNetworkInterface -Name ('nic' + $rgname) -ResourceGroupName $rgname; + $nicId = $nic.Id; + + $p = Add-AzVMNetworkInterface -VM $p -Id $nicId; + + # OS & Image + $user = "Foo12"; + $password = $PLACEHOLDER; + $securePassword = ConvertTo-SecureString $password -AsPlainText -Force; + $cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword); + $computerName = 'test'; + + $p = Set-AzVMOperatingSystem -VM $p -Windows -ComputerName $computerName -Credential $cred; + + $vm = New-AzVM -ResourceGroupName $rgname -Location $loc -Vm $p + $vm = Get-AzVM -ResourceGroupName $rgname -Name $vmname + + Assert-NotNull $vm; + + # Test with maxPatchPublishDate parameter + $maxPatchPublishDate = (Get-Date).AddDays(-30).ToString("yyyy-MM-ddTHH:mm:ssZ") + $patchResult = Invoke-azvminstallpatch -VM $vm -windows -RebootSetting 'Never' -MaximumDuration PT1H -ClassificationToIncludeForWindows critical -maxPatchPublishDate $maxPatchPublishDate + + Assert-AreEqual 'Succeeded' $patchResult.Status + + } + finally + { + # Cleanup + Remove-AzResourceGroup -Name $rgname -Force -ErrorAction SilentlyContinue; + } +} diff --git a/src/Compute/Compute/ChangeLog.md b/src/Compute/Compute/ChangeLog.md index d30c40af7a59..01f6a7425007 100644 --- a/src/Compute/Compute/ChangeLog.md +++ b/src/Compute/Compute/ChangeLog.md @@ -20,6 +20,8 @@ --> ## Upcoming Release +* Added new optional parameter `maxPatchPublishDate` to the `Invoke-AzVMInstallPatch` cmdlet + - Allows installation of patches published on or before a specified date. ## Version 9.1.0 * Added new parameter `EncryptionIdentity` to cmdlet `Set-AzVmssDiskEncryptionExtension`