Skip to content

Commit 58f4edd

Browse files
Nimisha Sharadshahabhijeet
authored andcommitted
Added tests with recording for AzurerM commands (Azure#2713)
1 parent 626036a commit 58f4edd

File tree

7 files changed

+5297
-1
lines changed

7 files changed

+5297
-1
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
<Compile Include="Common\ComputeTestController.cs" />
167167
<Compile Include="ScenarioTests\AddVhdTests.cs" />
168168
<Compile Include="ScenarioTests\AEMExtensionTests.cs" />
169+
<Compile Include="ScenarioTests\ChefExtensionTests.cs" />
169170
<Compile Include="ScenarioTests\ComputeCloudExceptionTests.cs" />
170171
<Compile Include="ScenarioTests\ContainerServiceTests.cs" />
171172
<Compile Include="ScenarioTests\DiagnosticsExtensionTests.cs" />
@@ -243,6 +244,9 @@
243244
<None Include="ScenarioTests\AEMExtensionTests.ps1">
244245
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
245246
</None>
247+
<None Include="ScenarioTests\ChefExtensionTests.ps1">
248+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
249+
</None>
246250
<None Include="ScenarioTests\ComputeCloudExceptionTests.ps1">
247251
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
248252
</None>
@@ -355,6 +359,9 @@
355359
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.DscExtensionTests\TestGetAzureRmVMDscExtension.json">
356360
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
357361
</None>
362+
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.ChefExtensionTests\TestSetChefExtensionBasic.json">
363+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
364+
</None>
358365
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.SqlIaaSExtensionTests\TestSqlIaaSAKVExtension.json">
359366
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
360367
</None>
@@ -523,6 +530,12 @@
523530
<None Include="Templates\azuredeploy.json">
524531
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
525532
</None>
533+
<None Include="Templates\client.rb">
534+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
535+
</None>
536+
<None Include="Templates\tstorgnztn-validator.pem">
537+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
538+
</None>
526539
</ItemGroup>
527540
<ItemGroup>
528541
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 class ChefExtensionTests
21+
{
22+
public ChefExtensionTests(Xunit.Abstractions.ITestOutputHelper output)
23+
{
24+
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
25+
}
26+
27+
[Fact]
28+
[Trait(Category.AcceptanceType, Category.CheckIn)]
29+
public void TestSetChefExtensionBasic()
30+
{
31+
ComputeTestController.NewInstance.RunPsTest("Test-SetChefExtensionBasic");
32+
}
33+
}
34+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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+
16+
#
17+
# ChefExtensionTests.ps1
18+
#
19+
20+
<#
21+
.SYNOPSIS
22+
Test the usage of the Set virtual machine chef extension command
23+
#>
24+
function Test-SetChefExtensionBasic
25+
{
26+
$rgname = Get-ComputeTestResourceName
27+
$loc = Get-ComputeVMLocation
28+
$TestOutputRoot = [System.AppDomain]::CurrentDomain.BaseDirectory;
29+
30+
try
31+
{
32+
############ Create Virtual Machine #############
33+
# Common
34+
New-AzureRmResourceGroup -Name $rgname -Location $loc -Force;
35+
36+
# VM Profile & Hardware
37+
$vmsize = 'Standard_A2';
38+
$vmname = 'vm' + $rgname;
39+
$p = New-AzureRmVMConfig -VMName $vmname -VMSize $vmsize;
40+
Assert-AreEqual $p.HardwareProfile.VmSize $vmsize;
41+
42+
# NRP
43+
$subnet = New-AzureRmVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24";
44+
$vnet = New-AzureRmVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -Subnet $subnet;
45+
$vnet = Get-AzureRmVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname;
46+
$subnetId = $vnet.Subnets[0].Id;
47+
$pubip = New-AzureRmPublicIpAddress -Force -Name ('pubip' + $rgname) -ResourceGroupName $rgname -Location $loc -AllocationMethod Dynamic -DomainNameLabel ('pubip' + $rgname);
48+
$pubip = Get-AzureRmPublicIpAddress -Name ('pubip' + $rgname) -ResourceGroupName $rgname;
49+
$pubipId = $pubip.Id;
50+
$nic = New-AzureRmNetworkInterface -Force -Name ('nic' + $rgname) -ResourceGroupName $rgname -Location $loc -SubnetId $subnetId -PublicIpAddressId $pubip.Id;
51+
$nic = Get-AzureRmNetworkInterface -Name ('nic' + $rgname) -ResourceGroupName $rgname;
52+
$nicId = $nic.Id;
53+
54+
$p = Add-AzureRmVMNetworkInterface -VM $p -Id $nicId;
55+
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces.Count 1;
56+
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces[0].Id $nicId;
57+
58+
# Storage Account
59+
$stoname = 'sto' + $rgname;
60+
$stotype = 'Standard_GRS';
61+
New-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype;
62+
Retry-IfException { $global:stoaccount = Get-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname; }
63+
64+
$osDiskName = 'osDisk';
65+
$osDiskCaching = 'ReadWrite';
66+
$osDiskVhdUri = "https://$stoname.blob.core.windows.net/test/os.vhd";
67+
$dataDiskVhdUri1 = "https://$stoname.blob.core.windows.net/test/data1.vhd";
68+
69+
$p = Set-AzureRmVMOSDisk -VM $p -Name $osDiskName -VhdUri $osDiskVhdUri -Caching $osDiskCaching -CreateOption FromImage;
70+
$p = Add-AzureRmVMDataDisk -VM $p -Name 'testDataDisk1' -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 1 -VhdUri $dataDiskVhdUri1 -CreateOption Empty;
71+
72+
# OS & Image
73+
$user = "localadmin";
74+
$password = $PLACEHOLDER;
75+
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
76+
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
77+
$computerName = 'test';
78+
$vhdContainer = "https://$stoname.blob.core.windows.net/test";
79+
80+
$p = Set-AzureRmVMOperatingSystem -VM $p -Windows -ComputerName $computerName -Credential $cred -ProvisionVMAgent;
81+
$p = Set-AzureRmVMSourceImage -VM $p -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus 2012-R2-Datacenter -Version "latest"
82+
83+
# Virtual Machine
84+
New-AzureRmVM -ResourceGroupName $rgname -Location $loc -VM $p;
85+
86+
############ Created Virtual Machine #############
87+
88+
############ Test Chef Extension #################
89+
$version = "1210.12"
90+
$client_rb = "$TestOutputRoot\Templates\client.rb";
91+
$validationPemFile = "$TestOutputRoot\Templates\tstorgnztn-validator.pem";
92+
93+
# Set Chef extension
94+
Set-AzureRmVMChefExtension -ResourceGroupName $rgname -VMName $vmname -TypeHandlerVersion $version -ClientRb $client_rb -ValidationPem $validationPemFile -Windows
95+
$extension = Get-AzureRmVMChefExtension -ResourceGroupName $rgname -VMName $vmname -Windows
96+
97+
Assert-NotNull $extension
98+
Assert-AreEqual $extension.Publisher 'Chef.Bootstrap.WindowsAzure'
99+
Assert-AreEqual $extension.ExtensionType 'ChefClient'
100+
Assert-AreEqual $extension.Name 'ChefClient'
101+
102+
# Test Remove command.
103+
Remove-AzureRmVMChefExtension -ResourceGroupName $rgname -VMName $vmname -Windows
104+
}
105+
finally
106+
{
107+
# Cleanup
108+
Clean-ResourceGroup $rgname
109+
}
110+
}

0 commit comments

Comments
 (0)