Skip to content

Commit 65e7a43

Browse files
haaghaisra-felmadewithsmilesSandidogrizzlytheodore
authored
Vmss dedicated host (#12588)
* checking in changes * Adding test recording with new param * help.md file * added new AssignedHostGroup field in the objects * updated changelog * added test change * Fxing test * updated tests to hit canary region * adding the new parameter * adding the actual subresource connected to the cmdlet parameter * added dedicatedhostgroup strategy and overload getSubResourceReference for hostgroup in subresourcestrategy method * added tests for new parameter in vmss * New-AzVm cmdlet dev and test work (#12595) * Update NewAzureVMCommand.cs * Update VirtualMachineStrategy.cs * Update PSVirtualMachine.cs * Update VirtualMachineTests.cs * Update VirtualMachineTests.ps1 * Update ChangeLog.md * Update VirtualMachineTests.ps1 * Update NewAzureVMCommand.cs * Update VirtualMachineTests.ps1 * New-AzVm hostgroupId help doc update * Update VirtualMachineStrategy.cs * recorded test file for New-AzVm * added call to new-azvm with hostgroup id for the test * fixing testdedicatedhost * New-AzVmss.md help doc * added test for get-azvm -status returning AssignedHost * added help description for the HostGroupId property for New-AzVmss * adding test + recording for new-azvmss .. -HostGroupId * added the domain name label so the tests could pass in playback mode * dedicated host changes for vmss * added DomainNameLabel added DomainNameLabel to Test-HostGroupPropertySetOnVirtualMachine test to ensure it passes in Playback. * Revert "dedicated host changes for vmss" This reverts commit fc103bd. * bringing back changes after revert * added new AssignedHostGroup field in the objects * updated changelog * added test change * updated tests to hit canary region * checking in changes * Adding test recording with new param * help.md file * adding the new parameter * adding the actual subresource connected to the cmdlet parameter * added dedicatedhostgroup strategy and overload getSubResourceReference for hostgroup in subresourcestrategy method * added tests for new parameter in vmss * New-AzVm cmdlet dev and test work (#12595) * Update NewAzureVMCommand.cs * Update VirtualMachineStrategy.cs * Update PSVirtualMachine.cs * Update VirtualMachineTests.cs * Update VirtualMachineTests.ps1 * Update ChangeLog.md * Update VirtualMachineTests.ps1 * Update NewAzureVMCommand.cs * Update VirtualMachineTests.ps1 * New-AzVm hostgroupId help doc update * Update VirtualMachineStrategy.cs * added call to new-azvm with hostgroup id for the test * recorded test file for New-AzVm * added test for get-azvm -status returning AssignedHost * added help description for the HostGroupId property for New-AzVmss * Fxing test * fixing testdedicatedhost * New-AzVmss.md help doc * adding test + recording for new-azvmss .. -HostGroupId * dedicated host changes for vmss * added the domain name label so the tests could pass in playback mode * Revert "dedicated host changes for vmss" This reverts commit fc103bd. * bringing back changes after revert * added DomainNameLabel added DomainNameLabel to Test-HostGroupPropertySetOnVirtualMachine test to ensure it passes in Playback. * added vmss tests and new recordings for the test * better print for get-azhostgroup -instanceview * Update ChangeLog.md Adding changelog for New-AzVmss (7745035), Get-AzVmss's returned instance view object, SupportAutomaticPlacement to New-AzHostGroup * Adding ValueFromPipelineByPropertyName Adding it for consistency with HostGroupId in New-AzVM * Making the HostGroupId accept pipeline input * test dedicatedhost rerecorded * Update DedicatedHostTests.ps1 * Removing plain text password * fixing cred scan and psvmssinstanceview * Updated help * Update ChangeLog.md * Update ChangeLog.md Co-authored-by: Yeming Liu <[email protected]> Co-authored-by: N'Godjigui Junior Diarrassouba <[email protected]> Co-authored-by: Adam Sandor <[email protected]> Co-authored-by: Theodore Chang <[email protected]>
1 parent f40884f commit 65e7a43

31 files changed

+19230
-1812
lines changed

src/Compute/Compute.Test/ScenarioTests/DedicatedHostTests.ps1

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ function Test-DedicatedHost
2424
try
2525
{
2626
# Common
27-
[string]$loc = Get-ComputeVMLocation;
27+
[string]$loc = Get-Location "Microsoft.Resources" "resourceGroups" "East US 2 EUAP";
2828
$loc = $loc.Replace(' ', '');
2929

3030
New-AzResourceGroup -Name $rgname -Location $loc -Force;
3131

3232
# Create a VM first
3333
$hostGroupName = $rgname + 'hostgroup'
34-
New-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName -Location $loc -PlatformFaultDomain 1 -Zone "1" -Tag @{key1 = "val1"};
34+
New-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName -Location $loc -PlatformFaultDomain 1 -Zone "2" -Tag @{key1 = "val1"};
3535

3636
$hostGroup = Get-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName;
3737

@@ -40,15 +40,13 @@ function Test-DedicatedHost
4040
Assert-AreEqual $loc $hostGroup.Location;
4141
Assert-True { $hostGroup.Tags.Keys.Contains("key1") };
4242
Assert-AreEqual "val1" $hostGroup.Tags["key1"];
43-
Assert-True { $hostGroup.Zones.Contains("1") };
43+
Assert-True { $hostGroup.Zones.Contains("2") };
4444
Assert-AreEqual 0 $hostGroup.Hosts.Count;
45+
Assert-AreEqual $true $hostGroup.SupportAutomaticPlacement;
4546

4647
$hostGroups = Get-AzHostGroup -ResourceGroupName $rgname;
4748
Assert-AreEqual 1 $hostGroups.Count;
4849

49-
$hostGroups = Get-AzHostGroup;
50-
Assert-True { $hostGroups.Count -ge 1 };
51-
5250
$hostName = $rgname + 'host'
5351
New-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName -Location $loc -Sku "ESv3-Type1" -Tag @{key1 = "val2"};
5452

@@ -81,7 +79,7 @@ function Test-DedicatedHost
8179

8280
$hostGroupInstanceViewResult = Get-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName -InstanceView;
8381
Assert-NotNull $hostGroupInstanceViewResult.Hosts;
84-
foreach ($hostInstanceViewWithName in $hostGroupInstanceViewResult.Hosts) {
82+
foreach ($hostInstanceViewWithName in $hostGroupInstanceViewResult.InstanceView.Hosts) {
8583
Assert-NotNull $hostInstanceViewWithName.Name;
8684
}
8785

@@ -129,15 +127,18 @@ function Test-DedicatedHostVirtualMachine
129127
try
130128
{
131129
# Common
132-
[string]$loc = Get-ComputeVMLocation;
130+
[string]$loc = Get-Location "Microsoft.Resources" "resourceGroups" "East US 2 EUAP";
133131
$loc = $loc.Replace(' ', '');
134132

135133
New-AzResourceGroup -Name $rgname -Location $loc -Force;
136134

137135
# Create a VM first
138136
$hostGroupName = $rgname + 'hostgroup'
139-
New-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName -Location $loc -PlatformFaultDomain 2 -Zone "1" -Tag @{key1 = "val1"};
140-
137+
New-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName -Location $loc -PlatformFaultDomain 2 -Zone "2" -SupportAutomaticPlacement $false -Tag @{key1 = "val1"};
138+
$hostGroup = Get-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName;
139+
140+
Assert-AreEqual $false $hostGroup.SupportAutomaticPlacement;
141+
141142
$hostName = $rgname + 'host'
142143
New-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName -Location $loc -Sku "ESv3-Type1" -PlatformFaultDomain 1 -Tag @{key1 = "val2"};
143144

@@ -154,7 +155,7 @@ function Test-DedicatedHostVirtualMachine
154155
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
155156
[string]$domainNameLabel = "$vmname0-$vmname0".tolower();
156157

157-
New-AzVM -ResourceGroupName $rgname -Name $vmname0 -Credential $cred -Zone "1" -Size $vmsize -HostId $dedicatedHostId -DomainNameLabel $domainNameLabel;
158+
New-AzVM -ResourceGroupName $rgname -Name $vmname0 -Credential $cred -Zone "2" -Size $vmsize -HostId $dedicatedHostId -DomainNameLabel $domainNameLabel;
158159
$vm0 = Get-AzVM -ResourceGroupName $rgname -Name $vmname0;
159160
Assert-AreEqual $dedicatedHostId $vm0.Host.Id;
160161

@@ -164,7 +165,7 @@ function Test-DedicatedHostVirtualMachine
164165
$subnet = New-AzVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24";
165166
$vnet = New-AzVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -Subnet $subnet;
166167
$subnetId = $vnet.Subnets[0].Id;
167-
$pubip = New-AzPublicIpAddress -Force -Name ('pubip' + $rgname) -ResourceGroupName $rgname -Location $loc -Zone "1" -Sku "Standard" -AllocationMethod "Static" -DomainNameLabel ('pubip' + $rgname);
168+
$pubip = New-AzPublicIpAddress -Force -Name ('pubip' + $rgname) -ResourceGroupName $rgname -Location $loc -Zone "2" -Sku "Standard" -AllocationMethod "Static" -DomainNameLabel ('pubip' + $rgname);
168169
$pubipId = $pubip.Id;
169170
$nic = New-AzNetworkInterface -Force -Name ('nic' + $rgname) -ResourceGroupName $rgname -Location $loc -SubnetId $subnetId -PublicIpAddressId $pubip.Id;
170171
$nicId = $nic.Id;
@@ -176,7 +177,7 @@ function Test-DedicatedHostVirtualMachine
176177
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
177178
$computerName = 'test';
178179

179-
$p = New-AzVMConfig -VMName $vmname1 -VMSize $vmsize -Zone "1" -HostId $dedicatedHostId `
180+
$p = New-AzVMConfig -VMName $vmname1 -VMSize $vmsize -Zone "2" -HostId $dedicatedHostId `
180181
| Add-AzVMNetworkInterface -Id $nicId -Primary `
181182
| Set-AzVMOperatingSystem -Windows -ComputerName $computerName -Credential $cred;
182183

src/Compute/Compute.Test/ScenarioTests/StrategiesVmssTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ public void TestSimpleNewVmssPpg()
110110
TestRunner.RunTestScript("Test-SimpleNewVmssPpg");
111111
}
112112

113+
[Fact]
114+
[Trait(Category.AcceptanceType, Category.CheckIn)]
115+
public void TestSimpleNewVmssHostGroup()
116+
{
117+
TestRunner.RunTestScript("Test-SimpleNewVmssHostGroup");
118+
}
119+
113120
[Fact]
114121
[Trait(Category.AcceptanceType, Category.CheckIn)]
115122
public void TestSimpleNewVmssBilling()

src/Compute/Compute.Test/ScenarioTests/StrategiesVmssTests.ps1

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,50 @@ function Test-SimpleNewVmssPpg
405405
}
406406
}
407407

408+
<#
409+
.SYNOPSIS
410+
Test Simple Paremeter Set With HostGroup (automatic placement)
411+
#>
412+
function Test-SimpleNewVmssHostGroup
413+
{
414+
# Setup
415+
$rgname = Get-ResourceName
416+
417+
try
418+
{
419+
# Common
420+
[string]$loc = Get-Location "Microsoft.Resources" "resourceGroups" "East US 2 EUAP";
421+
$loc = $loc.Replace(' ', '');
422+
$zone = "2"
423+
424+
# Creating the resource group
425+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
426+
427+
# Hostgroup and Host
428+
$hostGroupName = $rgname + "HostGroup"
429+
$hostGroup = New-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName -Location $loc -PlatformFaultDomain 2 -Zone $zone -SupportAutomaticPlacement $true -Tag @{key1 = "val1"};
430+
431+
$Sku = "Dsv3-Type1"
432+
$hostName = $rgname + "Host"
433+
New-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName -Location $loc -Sku $Sku -PlatformFaultDomain 1 -Tag @{test = "true"}
434+
435+
# Creating a new vmss
436+
$VmSku = "Standard_D2s_v3"
437+
$vmssname = "MyVmss"
438+
$username = "admin01"
439+
$password = Get-PasswordForVM | ConvertTo-SecureString -AsPlainText -Force
440+
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
441+
$vmss = New-AzVmss -Name $vmssname -ResourceGroup $rgname -Credential $cred -HostGroupId $hostGroup.Id -Zone $zone -VmSize $VmSku -DomainNameLabel "myvmss-48e3cf"
442+
443+
Assert-AreEqual $vmss.HostGroup.Id $hostGroup.Id
444+
}
445+
finally
446+
{
447+
# Cleanup
448+
Clean-ResourceGroup $rgname
449+
}
450+
}
451+
408452
<#
409453
.SYNOPSIS
410454
Test Simple Paremeter Set for New Vmss with eviction policy, priority, and max price.

src/Compute/Compute.Test/ScenarioTests/VirtualMachineScaleSetTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,12 @@ public void TestVirtualMachineScaleSetNewEncryptionAtHost()
178178
{
179179
TestRunner.RunTestScript("Test-VirtualMachineScaleSetEncryptionAtHost");
180180
}
181+
182+
[Fact]
183+
[Trait(Category.AcceptanceType, Category.CheckIn)]
184+
public void TestVirtualMachineScaleSetAssignedHost()
185+
{
186+
TestRunner.RunTestScript("Test-VirtualMachineScaleSetAssignedHost");
187+
}
181188
}
182189
}

src/Compute/Compute.Test/ScenarioTests/VirtualMachineScaleSetTests.ps1

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2536,3 +2536,50 @@ function Test-VirtualMachineScaleSetEncryptionAtHost
25362536
Clean-ResourceGroup $rgname
25372537
}
25382538
}
2539+
2540+
<#
2541+
.SYNOPSIS
2542+
testing encryptionAtHost cmdlet for
2543+
new-azvmss - create vmss using simple parameter set and hostencryption tag.
2544+
update-azvmss test boolean parameter
2545+
new-azvmssconfig
2546+
#>
2547+
function Test-VirtualMachineScaleSetAssignedHost
2548+
{
2549+
# Setup
2550+
$rgname = Get-ComputeTestResourceName
2551+
2552+
try
2553+
{
2554+
# Common
2555+
$zone = "2"
2556+
[string]$loc = Get-Location "Microsoft.Resources" "resourceGroups" "East US 2 EUAP";
2557+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
2558+
2559+
# Hostgroup and Host
2560+
$hostGroupName = $rgname + "HostGroup"
2561+
$hostGroup = New-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName -Location $loc -PlatformFaultDomain 2 -Zone $zone -SupportAutomaticPlacement $true -Tag @{key1 = "val1"};
2562+
2563+
$Sku = "Esv3-Type1"
2564+
$hostName = $rgname + "Host"
2565+
$host_ = New-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName -Location $loc -Sku $Sku -PlatformFaultDomain 1 -Tag @{test = "true"}
2566+
2567+
# Creating a new vmss
2568+
$VmSku = "Standard_E2s_v3"
2569+
$domainNameLabel = "domainlabel"
2570+
$vmssname = "MyVmss"
2571+
$username = "admin01"
2572+
$password = Get-PasswordForVM | ConvertTo-SecureString -AsPlainText -Force
2573+
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
2574+
$vmss = New-AzVmss -Name $vmssname -ResourceGroup $rgname -Credential $cred -HostGroupId $hostGroup.Id -Zone $zone -VmSize $VmSku -DomainNameLabel $domainNameLabel
2575+
2576+
$vmssResult = Get-AzVmssVM -InstanceView -ResourceGroupName $rgname -VMScaleSetName $vmssname;
2577+
2578+
Assert-AreEqual $host_.Id $vmssResult[0].InstanceView.AssignedHost;
2579+
}
2580+
finally
2581+
{
2582+
# Cleanup
2583+
Clean-ResourceGroup $rgname
2584+
}
2585+
}

src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@ public void TestVirtualMachineGetStatus()
214214
TestRunner.RunTestScript("Test-VirtualMachineGetStatus");
215215
}
216216

217+
[Fact]
218+
[Trait(Category.AcceptanceType, Category.CheckIn)]
219+
public void TestVirtualMachineGetStatusWithAssignedHost()
220+
{
221+
TestRunner.RunTestScript("Test-VirtualMachineGetStatusWithAssignedHost");
222+
}
223+
217224
[Fact]
218225
[Trait(Category.AcceptanceType, Category.CheckIn)]
219226
public void TestVirtualMachineManagedDiskConversion()
@@ -311,5 +318,12 @@ public void TestSetAzVMOperatingSystemError()
311318
{
312319
TestRunner.RunTestScript("Test-SetAzVMOperatingSystemError");
313320
}
321+
322+
[Fact]
323+
[Trait(Category.AcceptanceType, Category.CheckIn)]
324+
public void TestHostGroupPropertySetOnVirtualMachine()
325+
{
326+
TestRunner.RunTestScript("Test-HostGroupPropertySetOnVirtualMachine");
327+
}
314328
}
315329
}

src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.ps1

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2994,6 +2994,57 @@ function Test-VirtualMachineGetStatus
29942994
}
29952995
}
29962996

2997+
<#
2998+
.SYNOPSIS
2999+
Test Virtual Machines
3000+
#>
3001+
function Test-VirtualMachineGetStatusWithAssignedHost
3002+
{
3003+
param ($loc)
3004+
# Setup
3005+
$rgname = Get-ComputeTestResourceName
3006+
3007+
try
3008+
{
3009+
# Common
3010+
[string]$loc = Get-Location "Microsoft.Resources" "resourceGroups" "East US 2 EUAP";
3011+
$loc = $loc.Replace(' ', '');
3012+
3013+
# Creating the resource group
3014+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
3015+
3016+
# Hostgroup and Hostgroupname
3017+
$hostGroupName = $rgname + "HostGroup"
3018+
$hostGroup = New-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName -Location $loc -PlatformFaultDomain 2 -Zone "2" -SupportAutomaticPlacement $true -Tag @{key1 = "val1"};
3019+
3020+
3021+
$Sku = "Esv3-Type1"
3022+
$hostName = $rgname + "Host"
3023+
New-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName -Location $loc -Sku $Sku -PlatformFaultDomain 1 -Tag @{test = "true"}
3024+
3025+
# VM Profile & Hardware
3026+
$vmsize = 'Standard_E2s_v3';
3027+
$vmname = $rgname + 'Vm';
3028+
3029+
# Creating a VM using simple parameter set
3030+
$user = "Foo2";
3031+
$password = Get-PasswordForVM
3032+
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
3033+
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
3034+
3035+
New-AzVM -ResourceGroupName $rgname -Location $loc -Name $vmname -Credential $cred -Zone "2" -Size $vmsize -DomainNameLabel "crptestps2532vm-1d1de" -HostGroupId $hostGroup.Id;
3036+
$vm = Get-AzVM -ResourceGroupName $rgname -Name $vmname -Status
3037+
$a = $vm | Out-String
3038+
3039+
Assert-True {$a.Contains("AssignedHost")};
3040+
}
3041+
finally
3042+
{
3043+
# Cleanup
3044+
Clean-ResourceGroup $rgname
3045+
}
3046+
}
3047+
29973048
<#
29983049
.SYNOPSIS
29993050
Test Virtual Machine managed disk conversion
@@ -4171,3 +4222,48 @@ function Test-SetAzVMOperatingSystemError
41714222
}
41724223
}
41734224

4225+
<#
4226+
.SYNOPSIS
4227+
Test HostGroup property is set on a VM correctly when HostGroup.Id is passed as a parameter.
4228+
#>
4229+
function Test-HostGroupPropertySetOnVirtualMachine
4230+
{
4231+
# Setup
4232+
$rgname = Get-ComputeTestResourceName
4233+
4234+
try
4235+
{
4236+
# Common
4237+
[string]$loc = Get-Location "Microsoft.Resources" "resourceGroups" "East US 2 EUAP";
4238+
$loc = $loc.Replace(' ', '');
4239+
4240+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
4241+
4242+
# Create a VM first
4243+
$hostGroupName = $rgname + 'hostgroup'
4244+
$hostGroup = New-AzHostGroup -ResourceGroupName $rgname -Name $hostGroupName -Location $loc -PlatformFaultDomain 2 -Zone "2";
4245+
4246+
$hostName = $rgname + 'host'
4247+
New-AzHost -ResourceGroupName $rgname -HostGroupName $hostGroupName -Name $hostName -Location $loc -Sku "ESv3-Type1" -PlatformFaultDomain 1;
4248+
4249+
# VM Profile & Hardware
4250+
$vmsize = 'Standard_E2s_v3';
4251+
$vmname0 = 'v' + $rgname;
4252+
4253+
# Creating a VM using simple parameter set
4254+
$username = "admin01"
4255+
$password = Get-PasswordForVM | ConvertTo-SecureString -AsPlainText -Force
4256+
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
4257+
[string]$domainNameLabel = "vcrptestps7691-6f2166";
4258+
4259+
$vm0 = New-AzVM -ResourceGroupName $rgname -Location $loc -Name $vmname0 -Credential $cred -Zone "2" -Size $vmsize -HostGroupId $hostGroup.Id -DomainNameLabel $domainNameLabel;
4260+
4261+
Assert-AreEqual $hostGroup.Id $vm0.HostGroup.Id;
4262+
}
4263+
finally
4264+
{
4265+
# Cleanup
4266+
Clean-ResourceGroup $rgname
4267+
}
4268+
}
4269+

0 commit comments

Comments
 (0)