Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -695,5 +695,12 @@ public void TestVirtualMachinePlacement()
{
TestRunner.RunTestScript("Test-VirtualMachinePlacement");
}
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void testgeninvokeazvminstallpatch()
{
TestRunner.RunTestScript("TestGen-invokeazvminstallpatch");
}
}
}
70 changes: 69 additions & 1 deletion src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7945,4 +7945,72 @@ function Test-VirtualMachinePlacement
# Cleanup
Clean-ResourceGroup $rgname;
}
}
}
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 case 1: Invoke-AzVMInstallPatch without maxPatchPublishDate
$patchResult = Invoke-AzVMInstallPatch -VM $vm -Windows -RebootSetting 'Never' -MaximumDuration PT1H -ClassificationToIncludeForWindows critical
Assert-AreEqual 'Succeeded' $patchResult.Status

# Test case 2: Invoke-AzVMInstallPatch with maxPatchPublishDate
$maxPatchPublishDate = (Get-Date).AddDays(-30).ToString("yyyy-MM-ddTHH:mm:ss")
$patchResultWithDate = Invoke-AzVMInstallPatch -VM $vm -Windows -RebootSetting 'Never' -MaximumDuration PT1H -ClassificationToIncludeForWindows critical -MaxPatchPublishDate $maxPatchPublishDate
Assert-AreEqual 'Succeeded' $patchResultWithDate.Status

}
finally
{
# Cleanup
Remove-AzResourceGroup -Name $rgname -Force -ErrorAction SilentlyContinue;
}
}
2 changes: 2 additions & 0 deletions src/Compute/Compute/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

-->
## Upcoming Release
* Added new cmdlet `Invoke-AzVMInstallPatch` to install patches on Azure VMs.
- Introduced optional parameter `maxPatchPublishDate` to specify the maximum publish date for patches, accepting a dateTime parsable string.
* Added new cmdlets `Add-AzVmssSkuProfileVMSize` and `Remove-AzVmssSkuProfileVMSize` to add and remove VM sizes to and from the VMSS SkuProfile.
* Added new parameters `ZonePlacementPolicy`, `IncludeZone`, `ExcludeZone`, and `AlignRegionalDisksToVMZone` to cmdlets `New-AzVM` and `New-AzVmConfig`
* Added new parameter `AlignRegionalDisksToVMZone` to cmdlet `Update-AzVM`.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// ----------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -233,6 +232,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.")]
public string MaxPatchPublishDate { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
public SwitchParameter AsJob { get; set; }
Expand Down Expand Up @@ -278,6 +281,11 @@ public override void ExecuteCmdlet()
vmInstallPatchesParameters.MaximumDuration = this.MaximumDuration;
vmInstallPatchesParameters.RebootSetting = this.RebootSetting;

if (this.IsParameterBound(c => c.MaxPatchPublishDate))
{
vmInstallPatchesParameters.MaxPatchPublishDate = this.MaxPatchPublishDate;
}

// divde linux and windows
if (this.Windows.IsPresent)
{
Expand Down Expand Up @@ -331,4 +339,4 @@ public override void ExecuteCmdlet()
});
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
//
//
// Copyright (c) Microsoft and contributors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
Expand Down Expand Up @@ -35,5 +34,6 @@ public class PSVirtualMachineInstallPatchesResult
public IList<PatchInstallationDetail> Patches { get; set; }
public DateTime? StartDateTime { get; set; }
public ApiError Error { get; set; }
public string MaxPatchPublishDate { get; set; }
}
}
}