@@ -5057,4 +5057,87 @@ function Test-VirtualMachineEnableAutoUpdate
5057
5057
# Cleanup
5058
5058
Clean - ResourceGroup $rgname ;
5059
5059
}
5060
+ }
5061
+
5062
+ <#
5063
+ . SYNOPSIS
5064
+ Windows machine test ensuring the EnableAutoUpdate value on the
5065
+ provided VM is not overwritten.
5066
+ #>
5067
+ function Test-CapacityReservation
5068
+ {
5069
+ # Setup
5070
+ $rgname = Get-ComputeTestResourceName ;
5071
+ $loc = ' eastus2euap' ;
5072
+
5073
+ try
5074
+ {
5075
+ New-AzResourceGroup - Name $rgname - Location $loc - Force;
5076
+
5077
+ # create a CRG
5078
+ $CRGName = ' CRG' + $rgname
5079
+ New-AzCapacityReservationGroup - ResourceGroupName $rgname - Name $CRGName - Location $loc
5080
+
5081
+ # Create 2 CR in CRG with two different skus
5082
+ $CRName1 = " cr1" + $rgname
5083
+ $Sku1 = " Standard_DS1_v2"
5084
+ $CRName2 = " cr2" + $rgname
5085
+ $Sku2 = " Standard_A2_v2"
5086
+ $cr1 = New-AzCapacityReservation - ResourceGroupName $rgname - ReservationGroupName $CRGName - Name $CRName1 - Sku $Sku1 - CapacityToReserve 4 - location $loc
5087
+ $cr2 = New-AzCapacityReservation - ResourceGroupName $rgname - ReservationGroupName $CRGName - Name $CRName2 - Sku $Sku2 - CapacityToReserve 4 - location $loc
5088
+
5089
+ # try Get-CRG with InstanceView
5090
+ $CRG = Get-AzCapacityReservationGroup - ResourceGroupName $rgname - Name $CRGName - InstanceView
5091
+ Assert-AreEqual 2 $crg.InstanceView.CapacityReservations.count
5092
+
5093
+ # try Get-CR count == 2
5094
+ $CR = Get-AzCapacityReservation - ResourceGroupName $rgname - ReservationGroupName $CRGName
5095
+ Assert-AreEqual 2 $CR.count
5096
+
5097
+ # create credential
5098
+ $securePassword = Get-PasswordForVM | ConvertTo-SecureString - AsPlainText - Force;
5099
+ $user = " admin01" ;
5100
+ $cred = New-Object System.Management.Automation.PSCredential ($user , $securePassword );
5101
+
5102
+ # Add one VM from creation
5103
+ $vmname1 = ' 1' + $rgname ;
5104
+ $domainNameLabel1 = " d1" + $rgname ;
5105
+ $vm1 = New-AzVM - ResourceGroupName $rgname - Name $vmname1 - Credential $cred - DomainNameLabel $domainNameLabel1 - CapacityReservationGroupId $CRG.id - Size $Sku1 - Location $loc
5106
+
5107
+ # Create one VM then update to associate with CRG
5108
+ $vmname2 = ' 2' + $rgname ;
5109
+ $domainNameLabel2 = " d2" + $rgname ;
5110
+ $vm2 = New-AzVM - ResourceGroupName $rgname - Name $vmname2 - Credential $cred - DomainNameLabel $domainNameLabel2 - Size $Sku2 - Location $loc
5111
+ Stop-AzVM - ResourceGroupName $rgname - Name $vmname2 - Force
5112
+ Update-AzVm - ResourceGroupName $rgname - vm $vm2 - CapacityReservationGroupId $CRG.id
5113
+
5114
+ # get instance view of CR. verify
5115
+ $vm2 = Get-AzVM - ResourceGroupName $rgname - Name $vmname2
5116
+ $cr1 = Get-AzCapacityReservation - ResourceGroupName $rgname - ReservationGroupName $CRGName - Name $CRName1 - InstanceView
5117
+ $cr2 = Get-AzCapacityReservation - ResourceGroupName $rgname - ReservationGroupName $CRGName - Name $CRName2 - InstanceView
5118
+ Assert-AreEqual $vm2.CapacityReservation.CapacityReservationGroup.id $CRG.id
5119
+ Assert-AreEqual $cr1.InstanceView.UtilizationInfo.VirtualMachinesAllocated.id $vm1.id
5120
+ Assert-AreEqual $cr2.VirtualMachinesAssociated [0 ].id $vm2.id
5121
+
5122
+ # remove VMs
5123
+ Remove-AzVm - ResourceGroupName $rgname - Name $vmname1 - Force
5124
+ Remove-AzVm - ResourceGroupName $rgname - Name $vmname2 - Force
5125
+
5126
+ # remove CRs
5127
+ Remove-AzCapacityReservation - ResourceGroupName $rgname - ReservationGroupName $CRGName - Name $CRName1
5128
+ Remove-AzCapacityReservation - ResourceGroupName $rgname - ReservationGroupName $CRGName - Name $CRName2
5129
+ $CR = Get-AzCapacityReservation - ResourceGroupName $rgname - ReservationGroupName $CRGName
5130
+ Assert-AreEqual 0 $CR.count
5131
+
5132
+ # remove CRG
5133
+ Remove-AzCapacityReservationGroup - ResourceGroupName $rgname - Name $CRGName
5134
+ $CRG = Get-AzCapacityReservationGroup - ResourceGroupName $rgname
5135
+ Assert-AreEqual 0 $CRG.count
5136
+
5137
+ }
5138
+ finally
5139
+ {
5140
+ # Cleanup
5141
+ Clean - ResourceGroup $rgname ;
5142
+ }
5060
5143
}
0 commit comments