Skip to content

Commit 3613b14

Browse files
committed
Set-AzureVMPlan cmdlet
1 parent c487e3b commit 3613b14

File tree

10 files changed

+3293
-1099
lines changed

10 files changed

+3293
-1099
lines changed

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

Lines changed: 4 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,9 @@
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>
291295
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineTests\TestVirtualMachineSizeAndUsage.json">
292296
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
293297
</None>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
}

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

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,86 @@ 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";
832911
}
833912
finally
834913
{

0 commit comments

Comments
 (0)