Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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 @@ -51,5 +51,12 @@ public void TestAvailabilitySetConvert()
{
TestRunner.RunTestScript("Test-AvailabilitySetConvert 'eastus2euap'");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestAvailabilitySetScheduledEventsPolicy()
{
TestRunner.RunTestScript("Test-AvailabilitySetScheduledEventsPolicy 'eastus2euap'");
}
}
}
51 changes: 51 additions & 0 deletions src/Compute/Compute.Test/ScenarioTests/AvailabilitySetTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,54 @@ function New-TestVmInAvailabilitySet {
New-AzVM -ResourceGroupName $ResourceGroupName -Location $Location -VM $vmConfig;
return Get-AzVM -ResourceGroupName $ResourceGroupName -Name $VmName;
}

<#
.SYNOPSIS
Test Availability Set ScheduledEventsPolicy
Note: This test requires a region where ScheduledEventsPolicy is enabled
#>
function Test-AvailabilitySetScheduledEventsPolicy
{
param ($loc)
# Setup
$rgname = Get-ComputeTestResourceName

try
{
# Common
if ($loc -eq $null)
{
$loc = Get-ComputeVMLocation;
}
New-AzResourceGroup -Name $rgname -Location $loc -Force;

$asetName = 'avs' + $rgname;
$nonDefaultUD = 2;
$nonDefaultFD = 2;

# Create Availability Set
New-AzAvailabilitySet -ResourceGroupName $rgname -Name $asetName -Location $loc `
-PlatformUpdateDomainCount $nonDefaultUD -PlatformFaultDomainCount $nonDefaultFD -Sku 'Aligned';

$aset = Get-AzAvailabilitySet -ResourceGroupName $rgname -Name $asetName;
Assert-NotNull $aset;

# Update with ScheduledEventsPolicy
$apiVersion = "2020-07-01";
$asetUpdated = $aset | Update-AzAvailabilitySet `
-ScheduledEventsApiVersion $apiVersion -EnableAllInstancesDown $true;

# Verify the properties are set
Assert-NotNull $asetUpdated.ScheduledEventsPolicy;
Assert-NotNull $asetUpdated.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets;
Assert-NotNull $asetUpdated.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph;
Assert-AreEqual $apiVersion $asetUpdated.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph.ScheduledEventsApiVersion;
Assert-NotNull $asetUpdated.ScheduledEventsPolicy.AllInstancesDown;
Assert-AreEqual $true $asetUpdated.ScheduledEventsPolicy.AllInstancesDown.AutomaticallyApprove;
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,12 @@ public void TestSimpleGalleryCrossTenant()
{
TestRunner.RunTestScript("Test-SimpleGalleryCrossTenant");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestSimpleNewVmScheduledEventsPolicy()
{
TestRunner.RunTestScript("Test-SimpleNewVmScheduledEventsPolicy");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -695,3 +695,45 @@ function Test-SimpleGalleryCrossTenant
Clean-ResourceGroup $vmname
}
}
<#
.SYNOPSIS
Test Simple Parameter Set for New-AzVM with ScheduledEventsPolicy parameters
Note: This test requires a region where ScheduledEventsPolicy is enabled
#>
function Test-SimpleNewVmScheduledEventsPolicy
{
param ($loc)
# Setup
$vmname = Get-ResourceName

try
{
if ($loc -eq $null)
{
$loc = "eastus2euap";
}

$username = "admin01"
$password = Get-PasswordForVM | ConvertTo-SecureString -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
[string]$domainNameLabel = "$vmname-$vmname".tolower();
$stnd = "Standard";
$apiVersion = "2020-07-01";

# Create VM with ScheduledEventsPolicy parameters
# Note: The parameters are validated during creation, but the Azure API may not return
# the ScheduledEventsPolicy property in the GET response. The test verifies that
# the VM is created successfully with these parameters (no error thrown).
$vm = New-AzVM -Name $vmname -Location $loc -Credential $cred -DomainNameLabel $domainNameLabel `
-SecurityType $stnd -ScheduledEventsApiVersion $apiVersion -EnableAllInstancesDown $true

# Verify VM creation succeeded
Assert-NotNull $vm;
Assert-AreEqual $vmname $vm.Name;
}
finally
{
# Cleanup
Clean-ResourceGroup $vmname
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -514,5 +514,12 @@ public void TestVirtualMachineScaleSetHighSpeedInterconnectPlacement()
{
TestRunner.RunTestScript("Test-VirtualMachineScaleSetHighSpeedInterconnectPlacement");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestVirtualMachineScaleSetScheduledEventsPolicy()
{
TestRunner.RunTestScript("Test-VirtualMachineScaleSetScheduledEventsPolicy 'eastus2euap'");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6345,4 +6345,60 @@ function Test-VirtualMachineScaleSetHighSpeedInterconnectPlacement
# Cleanup
Clean-ResourceGroup $rgname;
}
}

<#
.SYNOPSIS
Test Virtual Machine Scale Set ScheduledEventsPolicy
Note: This test requires a region where ScheduledEventsPolicy is enabled
#>
function Test-VirtualMachineScaleSetScheduledEventsPolicy
{
param ($loc)
# Setup
$rgname = Get-ComputeTestResourceName

try
{
# Common
if ($loc -eq $null)
{
$loc = Get-ComputeVMLocation;
}
$loc = $loc.Replace(' ', '');
New-AzResourceGroup -Name $rgname -Location $loc -Force;

# Create VMSS with ScheduledEventsPolicy parameters
$vmssName = 'vmss' + $rgname;
$domainNameLabel = "d1" + $rgname;

$adminUsername = 'Foo12';
$adminPassword = $PLACEHOLDER;
$securePassword = ConvertTo-SecureString $adminPassword -AsPlainText -Force;
$cred = New-Object System.Management.Automation.PSCredential ($adminUsername, $securePassword);

# Create VMSS
$vmss = New-AzVmss -ResourceGroupName $rgname -Location $loc -Credential $cred `
-VMScaleSetName $vmssName -DomainNameLabel $domainNameLabel;

# Get the VMSS and set ScheduledEventsPolicy
$vmssGet = Get-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName;

$apiVersion = "2020-07-01";
$vmssUpdated = Update-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName `
-VirtualMachineScaleSet $vmssGet -ScheduledEventsApiVersion $apiVersion -EnableAllInstancesDown $true;

# Verify the properties are set
Assert-NotNull $vmssUpdated.ScheduledEventsPolicy;
Assert-NotNull $vmssUpdated.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets;
Assert-NotNull $vmssUpdated.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph;
Assert-AreEqual $apiVersion $vmssUpdated.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph.ScheduledEventsApiVersion;
Assert-NotNull $vmssUpdated.ScheduledEventsPolicy.AllInstancesDown;
Assert-AreEqual $true $vmssUpdated.ScheduledEventsPolicy.AllInstancesDown.AutomaticallyApprove;
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname;
}
}
7 changes: 7 additions & 0 deletions src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -703,5 +703,12 @@ public void TestVirtualMachineGalleryApplicationFlags()
{
TestRunner.RunTestScript("Test-VirtualMachineGalleryApplicationFlags");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestVirtualMachineScheduledEventsPolicy()
{
TestRunner.RunTestScript("Test-VirtualMachineScheduledEventsPolicy 'eastus2euap'");
}
}
}
75 changes: 75 additions & 0 deletions src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8115,4 +8115,79 @@ function Test-VirtualMachineGalleryApplicationFlags
finally {
Clean-ResourceGroup $resourceGroupName
}
}

<#
.SYNOPSIS
Test Virtual Machine ScheduledEventsPolicy
Note: This test requires a region where ScheduledEventsPolicy is enabled
#>
function Test-VirtualMachineScheduledEventsPolicy
{
param ($loc)
# Setup
$rgname = Get-ComputeTestResourceName

try
{
# Common
if ($loc -eq $null)
{
$loc = Get-ComputeVMLocation;
}
New-AzResourceGroup -Name $rgname -Location $loc -Force;

# Create a simple VM
$vmsize = 'Standard_DS1_v2';
$vmname = 'vm' + $rgname;
$stnd = "Standard";
$p = New-AzVMConfig -VMName $vmname -VMSize $vmsize -SecurityType $stnd;

# 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 Static -DomainNameLabel ('pubip' + $rgname);
$pubip = Get-AzPublicIpAddress -Name ('pubip' + $rgname) -ResourceGroupName $rgname;
$nic = New-AzNetworkInterface -Force -Name ('nic' + $rgname) -ResourceGroupName $rgname -Location $loc -SubnetId $subnetId -PublicIpAddressId $pubip.Id;
$nic = Get-AzNetworkInterface -Name ('nic' + $rgname) -ResourceGroupName $rgname;

$p = Add-AzVMNetworkInterface -VM $p -Id $nic.Id;

# OS Profile
$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;

# Image
$imgRef = Get-DefaultCRPImage -loc $loc;
$p = ($imgRef | Set-AzVMSourceImage -VM $p);

# Create VM
New-AzVM -ResourceGroupName $rgname -Location $loc -VM $p;

# Get the created VM and update with ScheduledEventsPolicy
$vm = Get-AzVM -ResourceGroupName $rgname -Name $vmname;
$apiVersion = "2020-07-01";
$vmUpdated = Update-AzVM -ResourceGroupName $rgname -VM $vm `
-ScheduledEventsApiVersion $apiVersion -EnableAllInstancesDown $true;

# Get updated VM to verify
$vmAfterUpdate = Get-AzVM -ResourceGroupName $rgname -Name $vmname;
Assert-NotNull $vmAfterUpdate.ScheduledEventsPolicy;
Assert-NotNull $vmAfterUpdate.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets;
Assert-NotNull $vmAfterUpdate.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph;
Assert-AreEqual $apiVersion $vmAfterUpdate.ScheduledEventsPolicy.ScheduledEventsAdditionalPublishingTargets.EventGridAndResourceGraph.ScheduledEventsApiVersion;
Assert-NotNull $vmAfterUpdate.ScheduledEventsPolicy.AllInstancesDown;
Assert-AreEqual $true $vmAfterUpdate.ScheduledEventsPolicy.AllInstancesDown.AutomaticallyApprove;
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname;
}
}
Loading
Loading