Skip to content

Commit de72acd

Browse files
committed
add negative test for data disks
1 parent 02c411c commit de72acd

File tree

4 files changed

+2457
-0
lines changed

4 files changed

+2457
-0
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\VirtualMachineDataDiskTests.cs" />
151152
<Compile Include="ScenarioTests\VirtualMachineCaptureTests.cs" />
152153
<Compile Include="ScenarioTests\VirtualMachineProfileTests.cs" />
153154
<Compile Include="ScenarioTests\AvailabilitySetTests.cs" />
@@ -266,6 +267,9 @@
266267
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineProfileTests\TestVirtualMachineProfile.json">
267268
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
268269
</None>
270+
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineTests\TestVirtualMachineDataDisk.json">
271+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
272+
</None>
269273
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineTests\TestVirtualMachineImageList.json">
270274
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
271275
</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 TestVirtualMachineDataDisk()
25+
{
26+
ComputeTestController.NewInstance.RunPsTest("Test-VirtualMachineDataDisk");
27+
}
28+
}
29+
}

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

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,4 +759,84 @@ function Test-VirtualMachineCapture
759759
# Cleanup
760760
Clean-ResourceGroup $rgname
761761
}
762+
}
763+
764+
<#
765+
.SYNOPSIS
766+
Test Virtual Machines Data Disks
767+
#>
768+
function Test-VirtualMachineDataDisk
769+
{
770+
# Setup
771+
$rgname = Get-ComputeTestResourceName
772+
773+
try
774+
{
775+
# Common
776+
$loc = 'eastasia';
777+
New-AzureResourceGroup -Name $rgname -Location $loc;
778+
779+
# VM Profile & Hardware
780+
$vmsize = 'Standard_A0';
781+
$vmname = 'vm' + $rgname;
782+
$p = New-AzureVMConfig -VMName $vmname -VMSize $vmsize;
783+
# NRP
784+
$subnet = New-AzureVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24";
785+
$vnet = New-AzureVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -DnsServer "10.1.1.1" -Subnet $subnet;
786+
$vnet = Get-AzureVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname;
787+
$subnetId = $vnet.Subnets[0].Id;
788+
$pubip = New-AzurePublicIpAddress -Force -Name ('pubip' + $rgname) -ResourceGroupName $rgname -Location $loc -AllocationMethod Dynamic -DomainNameLabel ('pubip' + $rgname);
789+
$pubip = Get-AzurePublicIpAddress -Name ('pubip' + $rgname) -ResourceGroupName $rgname;
790+
$pubipId = $pubip.Id;
791+
$nic = New-AzureNetworkInterface -Force -Name ('nic' + $rgname) -ResourceGroupName $rgname -Location $loc -SubnetId $subnetId -PublicIpAddressId $pubip.Id;
792+
$nic = Get-AzureNetworkInterface -Name ('nic' + $rgname) -ResourceGroupName $rgname;
793+
$nicId = $nic.Id;
794+
795+
$p = Add-AzureVMNetworkInterface -VM $p -Id $nicId;
796+
797+
# Storage Account (SA)
798+
$stoname = 'sto' + $rgname;
799+
$stotype = 'Standard_GRS';
800+
New-AzureStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype;
801+
$stoaccount = Get-AzureStorageAccount -ResourceGroupName $rgname -Name $stoname;
802+
803+
$osDiskName = 'osDisk';
804+
$osDiskCaching = 'ReadWrite';
805+
$osDiskVhdUri = "https://$stoname.blob.core.windows.net/test/os.vhd";
806+
$dataDiskVhdUri1 = "https://$stoname.blob.core.windows.net/test/data1.vhd";
807+
$dataDiskVhdUri2 = "https://$stoname.blob.core.windows.net/test/data2.vhd";
808+
$dataDiskVhdUri3 = "https://$stoname.blob.core.windows.net/test/data3.vhd";
809+
810+
$p = Set-AzureVMOSDisk -VM $p -Name $osDiskName -VhdUri $osDiskVhdUri -Caching $osDiskCaching -CreateOption FromImage;
811+
812+
$p = Add-AzureVMDataDisk -VM $p -Name 'testDataDisk1' -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 1 -VhdUri $dataDiskVhdUri1 -CreateOption Empty;
813+
$p = Add-AzureVMDataDisk -VM $p -Name 'testDataDisk2' -Caching 'ReadOnly' -DiskSizeInGB 11 -Lun 2 -VhdUri $dataDiskVhdUri2 -CreateOption Empty;
814+
$p = Add-AzureVMDataDisk -VM $p -Name 'testDataDisk3' -Caching 'ReadOnly' -DiskSizeInGB 12 -Lun 3 -VhdUri $dataDiskVhdUri3 -CreateOption Empty;
815+
$p = Remove-AzureVMDataDisk -VM $p -Name 'testDataDisk3';
816+
817+
# OS & Image
818+
$user = "Foo12";
819+
$password = 'BaR@123' + $rgname;
820+
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
821+
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
822+
$computerName = 'test';
823+
$vhdContainer = "https://$stoname.blob.core.windows.net/test";
824+
$img = 'a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-Datacenter-201503.01-en.us-127GB.vhd';
825+
826+
# $p.StorageProfile.OSDisk = $null;
827+
$p = Set-AzureVMOperatingSystem -VM $p -Windows -ComputerName $computerName -Credential $cred;
828+
829+
# Image Reference;
830+
$p.StorageProfile.SourceImage = $null;
831+
$imgRef = Get-DefaultCRPImage;
832+
$p = Set-AzureVMSourceImage -VM $p -ImageReference $imgRef;
833+
834+
# Negative Tests on A0 Size + 2 Data Disks
835+
Assert-ThrowsContains { New-AzureVM -ResourceGroupName $rgname -Location $loc -Name $vmname -VM $p; } "The value of parameter 'dataDisk.lun' is invalid.";
836+
}
837+
finally
838+
{
839+
# Cleanup
840+
Clean-ResourceGroup $rgname
841+
}
762842
}

0 commit comments

Comments
 (0)