Skip to content

Edited New-AzVm to ensure the PlatformFaultDomain parameter in the VmConfig object is used #17859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 25, 2022
Merged
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 @@ -493,5 +493,12 @@ public void TestGetVirtualMachineById()
{
TestRunner.RunTestScript("Test-GetVirtualMachineById");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestVirtualMachinePlatformFaultDomain()
{
TestRunner.RunTestScript("Test-VirtualMachinePlatformFaultDomain");
}
}
}
81 changes: 81 additions & 0 deletions src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5714,3 +5714,84 @@ function Test-GetVirtualMachineById
Clean-ResourceGroup $rgname;
}
}

<#
.SYNOPSIS
Test Test GetVirtualMachineById Parameter Set
#>
function Test-VirtualMachinePlatformFaultDomain
{
# Setup
$rgname = Get-ComputeTestResourceName;
$loc = Get-ComputeVMLocation;

try
{
New-AzResourceGroup -Name $rgname -Location $loc -Force;

# VM Profile & Hardware
$vmname = 'vm' + $rgname;
$domainNameLabel = "d1" + $rgname;

$vnetname = "myVnet";
$vnetAddress = "10.0.0.0/16";
$subnetname = "slb" + $rgname;
$subnetAddress = "10.0.2.0/24";
$vmssName = "vmss" + $rgname;
$FaultDomainNumber = 2;
$vmssFaultDomain = 3;

$OSDiskName = $vmname + "-osdisk";
$NICName = $vmname+ "-nic";
$NSGName = $vmname + "-NSG";
$OSDiskSizeinGB = 128;
$VMSize = "Standard_DS2_v2";
$PublisherName = "MicrosoftWindowsServer";
$Offer = "WindowsServer";
$SKU = "2019-Datacenter";



# Creating a VM using Simple parameterset
$securePassword = Get-PasswordForVM | ConvertTo-SecureString -AsPlainText -Force;
$user = "admin01";
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);

$frontendSubnet = New-AzVirtualNetworkSubnetConfig -Name $subnetname -AddressPrefix $subnetAddress;

$vnet = New-AzVirtualNetwork -Name $vnetname -ResourceGroupName $rgname -Location $loc -AddressPrefix $vnetAddress -Subnet $frontendSubnet;

$vmssConfig = New-AzVmssConfig -Location $loc -PlatformFaultDomainCount $vmssFaultDomain;
$VMSS = New-AzVmss -ResourceGroupName $RGName -Name $VMSSName -VirtualMachineScaleSet $vmssConfig -Verbose;

$nsgRuleRDP = New-AzNetworkSecurityRuleConfig -Name RDP -Protocol Tcp -Direction Inbound -Priority 1001 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 3389 -Access Allow;
$nsg = New-AzNetworkSecurityGroup -ResourceGroupName $RGName -Location $loc -Name $NSGName -SecurityRules $nsgRuleRDP;
$nic = New-AzNetworkInterface -Name $NICName -ResourceGroupName $RGName -Location $loc -SubnetId $vnet.Subnets[0].Id -NetworkSecurityGroupId $nsg.Id -EnableAcceleratedNetworking;

# VM
$vmConfig = New-AzVMConfig -VMName $vmName -VMSize $VMSize -VmssId $VMSS.Id -PlatformFaultDomain $FaultDomainNumber ;
Set-AzVMOperatingSystem -VM $vmConfig -Windows -ComputerName $vmName -Credential $cred ;
Set-AzVMOSDisk -VM $vmConfig -StorageAccountType "Premium_LRS" -Caching ReadWrite -Name $OSDiskName -DiskSizeInGB $OSDiskSizeinGB -CreateOption FromImage ;
Set-AzVMSourceImage -VM $vmConfig -PublisherName $PublisherName -Offer $Offer -Skus $SKU -Version latest ;
Add-AzVMNetworkInterface -VM $vmConfig -Id $nic.Id;

New-AzVM -ResourceGroupName $RGName -Location $loc -VM $vmConfig ;
$vm = Get-AzVm -ResourceGroupName $rgname -Name $vmName;

Assert-AreEqual $vm.PlatformFaultDomain $FaultDomainNumber;

# Create VM using Default Parameter set
$domainNameLabel = "d1" + $rgname;
$vmnameDef = "defvm" + $rgname;
$platformFaultDomainVMDefaultSet = 2;
$vmDef = New-AzVM -ResourceGroupName $rgname -Name $vmname -Credential $cred -DomainNameLabel $domainNameLabel -PlatformFaultDomain $platformFaultDomainVMDefaultSet -VmssId $VMSS.Id;

Assert-AreEqual $vmDef.PlatformFaultDomain $platformFaultDomainVMDefaultSet;

}
finally
{
# Cleanup
Clean-ResourceGroup $rgname;
}
}

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Compute/Compute/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

-->
## Upcoming Release
* Edited `New-AzVm` cmdlet internal logic to use the `PlatformFaultDomain` value in the `PSVirtualMachine` object passed to it in the new virtual machine.

## Version 4.26.0
* Added `-ImageReferenceId` parameter to following cmdlets: `New-AzVm`, `New-AzVmConfig`, `New-AzVmss`, `Set-AzVmssStorageProfile`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,8 @@ public void DefaultExecuteCmdlet()
BillingProfile = this.VM.BillingProfile,
SecurityProfile = this.VM.SecurityProfile,
CapacityReservation = this.VM.CapacityReservation,
UserData = this.VM.UserData
UserData = this.VM.UserData,
PlatformFaultDomain = this.VM.PlatformFaultDomain
};

Dictionary<string, List<string>> auxAuthHeader = null;
Expand Down
17 changes: 17 additions & 0 deletions src/Compute/Compute/help/New-AzVM.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,23 @@ New-AzVm -ResourceGroupName ResourceGroup1 -Location SouthCentralUS -VM $Virtual

This example deploys a Windows VM from the marketplace in one resource group with an existing subnet in another resource group.

### Example 6: Creating a new VM as part of a VMSS with a PlatformFaultDomain value.
```
$resourceGroupName= <Resource Group Name>
$domainNameLabel = <Domain Name Label Name>
$vmname = "<Virtual Machine Name>
$platformFaultDomainVMDefaultSet = 2
$securePassword = <Password> | ConvertTo-SecureString -AsPlainText -Force
$user = <Username>
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword)
$vmssName = <Vmss Name>;

$vmssConfig = New-AzVmssConfig -Location $loc -PlatformFaultDomainCount $vmssFaultDomain;
$vmss = New-AzVmss -ResourceGroupName $resourceGroupName -Name $vmssName -VirtualMachineScaleSet $vmssConfig;

$vm = New-AzVM -ResourceGroupName $resourceGroupName -Name $vmname -Credential $cred -DomainNameLabel $domainNameLabel -PlatformFaultDomain $platformFaultDomainVMDefaultSet -VmssId $vmss.Id
```

## PARAMETERS

### -AddressPrefix
Expand Down