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");
}
}
}
65 changes: 64 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,67 @@ function Test-VirtualMachinePlacement
# Cleanup
Clean-ResourceGroup $rgname;
}
}
}
function TestGen-invokeazvminstallpatch {
# Setup
$rgname = Get-ComputeTestResourceName;
$loc = Get-Location;

try {
# Create a new resource group
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';

# Network Resources
$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;

# Create the VM
$vm = New-AzVM -ResourceGroupName $rgname -Location $loc -VM $p;
$vm = Get-AzVM -ResourceGroupName $rgname -Name $vmname;

Assert-NotNull $vm;

# Test Invoke-AzVMInstallPatch with maxPatchPublishDate parameter
$maxPatchPublishDate = (Get-Date).AddDays(-30).ToString("yyyy-MM-ddTHH:mm:ssZ"); # Example: 30 days ago
$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;
}
}
Loading