Skip to content

Commit c91d6c5

Browse files
committed
Merge pull request Azure#178 from huangpf/crp2
[P0] VMM Cmdlet - Set-AzureVMPlan
2 parents b84825a + 419a639 commit c91d6c5

File tree

13 files changed

+8924
-1136
lines changed

13 files changed

+8924
-1136
lines changed

src/ResourceManager/Compute/Commands.Compute.Test/Commands.Compute.Test.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
<Compile Include="ScenarioTests\StorageAccountTests.cs" />
149149
<Compile Include="ScenarioTests\TestVirtualMachineImageList.cs" />
150150
<Compile Include="ScenarioTests\TestVirtualMachineList.cs" />
151+
<Compile Include="ScenarioTests\VirtualMachinePlanTests.cs" />
151152
<Compile Include="ScenarioTests\VirtualMachineDataDiskTests.cs" />
152153
<Compile Include="ScenarioTests\VirtualMachineCaptureTests.cs" />
153154
<Compile Include="ScenarioTests\VirtualMachineProfileTests.cs" />
@@ -288,6 +289,12 @@
288289
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineTests\TestVirtualMachinePIRv2.json">
289290
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
290291
</None>
292+
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineTests\TestVirtualMachinePlan.json">
293+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
294+
</None>
295+
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineTests\TestVirtualMachinePlan2.json">
296+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
297+
</None>
291298
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineTests\TestVirtualMachineSizeAndUsage.json">
292299
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
293300
</None>

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/ComputeTestCommon.ps1

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,28 @@ function Get-ComputeTestResourceName
2828
}
2929
}
3030

31-
$assetName = [Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::GetAssetName($testName, "pstestrg")
31+
$oldErrorActionPreferenceValue = $ErrorActionPreference;
32+
$ErrorActionPreference = "SilentlyContinue";
33+
34+
try
35+
{
36+
$assetName = [Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::GetAssetName($testName, "pstestrg");
37+
}
38+
catch
39+
{
40+
if (($Error.Count -gt 0) -and ($Error[0].Exception.Message -like '*Unable to find type*'))
41+
{
42+
$assetName = Get-RandomItemName;
43+
}
44+
else
45+
{
46+
throw;
47+
}
48+
}
49+
finally
50+
{
51+
$ErrorActionPreference = $oldErrorActionPreferenceValue;
52+
}
3253

3354
return $assetName
3455
}
@@ -144,7 +165,7 @@ function Get-DefaultRDFEImage
144165

145166
<#
146167
.SYNOPSIS
147-
Gets default RDFE Image
168+
Gets default CRP Image
148169
#>
149170
function Get-DefaultCRPImage
150171
{
@@ -195,6 +216,19 @@ function Get-DefaultCRPImage
195216
return $vmimg;
196217
}
197218

219+
<#
220+
.SYNOPSIS
221+
Gets VMM Images
222+
#>
223+
function Get-MarketplaceImage
224+
{
225+
param([string] $location = "eastasia", [string] $pubFilter = '*', [string] $offerFilter = '*')
226+
227+
$imgs = Get-AzureVMImagePublisher -Location $location | where { $_.PublisherName -like $pubFilter } | Get-AzureVMImageOffer | where { $_.Offer -like $offerFilter } | Get-AzureVMImageSku | Get-AzureVMImage | Get-AzureVMImageDetail | where { $_.PurchasePlan -ne $null };
228+
229+
return $imgs;
230+
}
231+
198232
<#
199233
.SYNOPSIS
200234
Gets default VM config object
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
16+
using Xunit;
17+
18+
namespace Microsoft.Azure.Commands.Compute.Test.ScenarioTests
19+
{
20+
public partial class VirtualMachineTests
21+
{
22+
[Fact]
23+
[Trait(Category.AcceptanceType, Category.CheckIn)]
24+
public void TestVirtualMachinePlan()
25+
{
26+
ComputeTestController.NewInstance.RunPsTest("Test-VirtualMachinePlan");
27+
}
28+
29+
[Fact]
30+
[Trait(Category.AcceptanceType, Category.CheckIn)]
31+
public void TestVirtualMachinePlan2()
32+
{
33+
ComputeTestController.NewInstance.RunPsTest("Test-VirtualMachinePlan2");
34+
}
35+
}
36+
}

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

Lines changed: 163 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ function Test-VirtualMachineList
194194

195195
if ($s2 -ne $null)
196196
{
197-
Assert-NotNull $s2[0].ResourceGroupName;
197+
Assert-NotNull $s2[0].Id;
198198
}
199199

200200
Assert-ThrowsContains { $s3 = Get-AzureVM -NextLink "http://www.test.com/test"; } "Unexpected character"
@@ -828,7 +828,168 @@ function Test-VirtualMachineDataDisk
828828
$p = Set-AzureVMSourceImage -VM $p -ImageReference $imgRef;
829829

830830
# Negative Tests on A0 Size + 2 Data Disks
831-
Assert-ThrowsContains { New-AzureVM -ResourceGroupName $rgname -Location $loc -Name $vmname -VM $p; } "The value of parameter 'dataDisk.lun' is invalid.";
831+
Assert-ThrowsContains { New-AzureVM -ResourceGroupName $rgname -Location $loc -Name $vmname -VM $p; } "The maximum number of data disks allowed to be attached to a VM is 1.";
832+
}
833+
finally
834+
{
835+
# Cleanup
836+
Clean-ResourceGroup $rgname
837+
}
838+
}
839+
840+
841+
<#
842+
.SYNOPSIS
843+
Test Virtual Machines Plan
844+
#>
845+
function Test-VirtualMachinePlan
846+
{
847+
# Setup
848+
$rgname = Get-ComputeTestResourceName
849+
850+
try
851+
{
852+
# Common
853+
$loc = 'eastasia';
854+
New-AzureResourceGroup -Name $rgname -Location $loc;
855+
856+
# VM Profile & Hardware
857+
$vmsize = 'Standard_A0';
858+
$vmname = 'vm' + $rgname;
859+
$p = New-AzureVMConfig -VMName $vmname -VMSize $vmsize;
860+
# NRP
861+
$subnet = New-AzureVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24";
862+
$vnet = New-AzureVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -DnsServer "10.1.1.1" -Subnet $subnet;
863+
$vnet = Get-AzureVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname;
864+
$subnetId = $vnet.Subnets[0].Id;
865+
$pubip = New-AzurePublicIpAddress -Force -Name ('pubip' + $rgname) -ResourceGroupName $rgname -Location $loc -AllocationMethod Dynamic -DomainNameLabel ('pubip' + $rgname);
866+
$pubip = Get-AzurePublicIpAddress -Name ('pubip' + $rgname) -ResourceGroupName $rgname;
867+
$pubipId = $pubip.Id;
868+
$nic = New-AzureNetworkInterface -Force -Name ('nic' + $rgname) -ResourceGroupName $rgname -Location $loc -SubnetId $subnetId -PublicIpAddressId $pubip.Id;
869+
$nic = Get-AzureNetworkInterface -Name ('nic' + $rgname) -ResourceGroupName $rgname;
870+
$nicId = $nic.Id;
871+
872+
$p = Add-AzureVMNetworkInterface -VM $p -Id $nicId;
873+
874+
# Storage Account (SA)
875+
$stoname = 'sto' + $rgname;
876+
$stotype = 'Standard_GRS';
877+
New-AzureStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype;
878+
$stoaccount = Get-AzureStorageAccount -ResourceGroupName $rgname -Name $stoname;
879+
880+
$osDiskName = 'osDisk';
881+
$osDiskCaching = 'ReadWrite';
882+
$osDiskVhdUri = "https://$stoname.blob.core.windows.net/test/os.vhd";
883+
$dataDiskVhdUri1 = "https://$stoname.blob.core.windows.net/test/data1.vhd";
884+
$dataDiskVhdUri2 = "https://$stoname.blob.core.windows.net/test/data2.vhd";
885+
$dataDiskVhdUri3 = "https://$stoname.blob.core.windows.net/test/data3.vhd";
886+
887+
$p = Set-AzureVMOSDisk -VM $p -Name $osDiskName -VhdUri $osDiskVhdUri -Caching $osDiskCaching -CreateOption FromImage;
888+
889+
# OS & Image
890+
$user = "Foo12";
891+
$password = 'BaR@123' + $rgname;
892+
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
893+
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
894+
$computerName = 'test';
895+
$vhdContainer = "https://$stoname.blob.core.windows.net/test";
896+
$img = 'a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-Datacenter-201503.01-en.us-127GB.vhd';
897+
898+
# $p.StorageProfile.OSDisk = $null;
899+
$p = Set-AzureVMOperatingSystem -VM $p -Windows -ComputerName $computerName -Credential $cred;
900+
901+
# Image Reference;
902+
$p.StorageProfile.SourceImage = $null;
903+
$imgRef = Get-DefaultCRPImage;
904+
$p = Set-AzureVMSourceImage -VM $p -ImageReference $imgRef;
905+
906+
$plan = Get-ComputeTestResourceName;
907+
$p = Set-AzureVMPlan -VM $p -PlanName $plan -Publisher $plan -Product $plan -PromotionCode $plan;
908+
909+
# Negative Tests on non-existing Plan
910+
Assert-ThrowsContains { New-AzureVM -ResourceGroupName $rgname -Location $loc -Name $vmname -VM $p; } "User failed validation to purchase resources";
911+
}
912+
finally
913+
{
914+
# Cleanup
915+
Clean-ResourceGroup $rgname
916+
}
917+
}
918+
919+
920+
921+
<#
922+
.SYNOPSIS
923+
Test Virtual Machines Plan 2
924+
#>
925+
function Test-VirtualMachinePlan2
926+
{
927+
# Setup
928+
$rgname = Get-ComputeTestResourceName
929+
930+
try
931+
{
932+
# Common
933+
$loc = 'eastasia';
934+
New-AzureResourceGroup -Name $rgname -Location $loc;
935+
936+
# VM Profile & Hardware
937+
$vmsize = 'Standard_A0';
938+
$vmname = 'vm' + $rgname;
939+
$p = New-AzureVMConfig -VMName $vmname -VMSize $vmsize;
940+
# NRP
941+
$subnet = New-AzureVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24";
942+
$vnet = New-AzureVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -DnsServer "10.1.1.1" -Subnet $subnet;
943+
$vnet = Get-AzureVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname;
944+
$subnetId = $vnet.Subnets[0].Id;
945+
$pubip = New-AzurePublicIpAddress -Force -Name ('pubip' + $rgname) -ResourceGroupName $rgname -Location $loc -AllocationMethod Dynamic -DomainNameLabel ('pubip' + $rgname);
946+
$pubip = Get-AzurePublicIpAddress -Name ('pubip' + $rgname) -ResourceGroupName $rgname;
947+
$pubipId = $pubip.Id;
948+
$nic = New-AzureNetworkInterface -Force -Name ('nic' + $rgname) -ResourceGroupName $rgname -Location $loc -SubnetId $subnetId -PublicIpAddressId $pubip.Id;
949+
$nic = Get-AzureNetworkInterface -Name ('nic' + $rgname) -ResourceGroupName $rgname;
950+
$nicId = $nic.Id;
951+
952+
$p = Add-AzureVMNetworkInterface -VM $p -Id $nicId;
953+
954+
# Storage Account (SA)
955+
$stoname = 'sto' + $rgname;
956+
$stotype = 'Standard_GRS';
957+
New-AzureStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype;
958+
$stoaccount = Get-AzureStorageAccount -ResourceGroupName $rgname -Name $stoname;
959+
960+
$osDiskName = 'osDisk';
961+
$osDiskCaching = 'ReadWrite';
962+
$osDiskVhdUri = "https://$stoname.blob.core.windows.net/test/os.vhd";
963+
964+
$p = Set-AzureVMOSDisk -VM $p -Name $osDiskName -VhdUri $osDiskVhdUri -Caching $osDiskCaching -CreateOption FromImage;
965+
966+
# OS & Image
967+
$user = "Foo12";
968+
$password = 'BaR@123' + $rgname;
969+
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
970+
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
971+
$computerName = 'test';
972+
$vhdContainer = "https://$stoname.blob.core.windows.net/test";
973+
$img = 'a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-Datacenter-201503.01-en.us-127GB.vhd';
974+
975+
# $p.StorageProfile.OSDisk = $null;
976+
$p = Set-AzureVMOperatingSystem -VM $p -Windows -ComputerName $computerName -Credential $cred;
977+
978+
# Image Reference
979+
$p.StorageProfile.SourceImage = $null;
980+
981+
# Pick a VMM Image
982+
$vmmImgPubName = 'a10networks';
983+
$vmmImgOfferName = 'a10-vthunder-adc';
984+
$vmmImgSkusName = 'vthunder_byol';
985+
$vmmImgVerName = '1.0.0';
986+
$imgRef = Get-AzureVMImageDetail -PublisherName $vmmImgPubName -Location $loc -Offer $vmmImgOfferName -Skus $vmmImgSkusName -Version $vmmImgVerName;
987+
$plan = $imgRef.PurchasePlan;
988+
$p = Set-AzureVMSourceImage -VM $p -ImageReference $imgRef;
989+
$p = Set-AzureVMPlan -VM $p -PlanName $plan.Name -Publisher $plan.Publisher -Product $plan.Product;
990+
$p.OSProfile.WindowsConfiguration = $null;
991+
992+
New-AzureVM -ResourceGroupName $rgname -Location $loc -Name $vmname -VM $p;
832993
}
833994
finally
834995
{

0 commit comments

Comments
 (0)