Skip to content

Commit e1d5816

Browse files
author
aliasgar16
committed
Added test case and its recording for options added for ASM mode.
Signed-off-by: aliasgar16 <[email protected]>
1 parent 3752414 commit e1d5816

File tree

7 files changed

+1817
-491
lines changed

7 files changed

+1817
-491
lines changed

src/ServiceManagement/Common/Commands.ScenarioTest/ChefExtension/ChefExtensionTests.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616

1717
namespace Microsoft.WindowsAzure.Commands.ScenarioTest
18-
{
18+
{
1919
public class ChefExtensionTests
2020
{
2121
private EnvironmentSetupHelper helper = new EnvironmentSetupHelper();
@@ -33,6 +33,14 @@ public void TestSetAzureVMChefExtension()
3333
this.RunPowerShellTest("Test-SetAzureVMChefExtension");
3434
}
3535

36+
[Fact]
37+
[Trait(Category.AcceptanceType, Category.CheckIn)]
38+
[Trait(Category.AcceptanceType, Category.BVT)]
39+
public void TestSetAzureVMChefExtensionAdvancedOptions()
40+
{
41+
this.RunPowerShellTest("Test-SetAzureVMChefExtensionAdvancedOptions");
42+
}
43+
3644
protected void SetupManagementClients()
3745
{
3846
var rdfeTestFactory = new RDFETestEnvironmentFactory();
@@ -53,7 +61,7 @@ protected void RunPowerShellTest(params string[] scripts)
5361
using (UndoContext context = UndoContext.Current)
5462
{
5563
context.Start(TestUtilities.GetCallingClass(1), TestUtilities.GetCurrentMethodName(2));
56-
64+
5765
SetupManagementClients();
5866

5967
var modules = new List<string>
@@ -76,6 +84,6 @@ protected void RunPowerShellTest(params string[] scripts)
7684

7785
helper.RunPowerShellTest(scriptEnvPath, scripts);
7886
}
79-
}
87+
}
8088
}
8189
}

src/ServiceManagement/Common/Commands.ScenarioTest/Commands.ScenarioTest.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@
220220
<None Include="Resources\ChefExtension\tstorgnztn-validator.pem">
221221
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
222222
</None>
223+
<None Include="Resources\ChefExtension\encrypted_data_bag_secret">
224+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
225+
</None>
223226
<None Include="Resources\DiagnosticsExtension\DiagnosticsExtensionTests.ps1">
224227
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
225228
</None>
@@ -283,6 +286,9 @@
283286
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.ChefExtensionTests\TestSetAzureVMChefExtension.json">
284287
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
285288
</None>
289+
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.ChefExtensionTests\TestSetAzureVMChefExtensionAdvancedOptions.json">
290+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
291+
</None>
286292
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.DscExtensionTests\TestGetAzureVMDscExtension.json">
287293
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
288294
</None>

src/ServiceManagement/Common/Commands.ScenarioTest/Resources/ChefExtension/ChefExtensionTests.ps1

Lines changed: 99 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,29 @@ $PLACEHOLDER = "PLACEHOLDER1@";
2525
Test the usage of the Set virtual machine chef extension command
2626
#>
2727

28-
# Setup
29-
$vmName = "vmone"
30-
$svcName = "storone"
31-
$storageName = "storone"
32-
$location = "West US"
33-
$TestOutputRoot = [System.AppDomain]::CurrentDomain.BaseDirectory;
34-
3528
function Test-SetAzureVMChefExtension
36-
{
29+
{
30+
# Setup
31+
$vmName = "vmtwo"
32+
$svcName = "stortwo"
33+
$storageName = "stortwo"
34+
$location = "West US"
35+
$TestOutputRoot = [System.AppDomain]::CurrentDomain.BaseDirectory;
36+
3737
try
38-
{
39-
New-AzureStorageAccount -StorageAccountName $storageName -Location $location
38+
{
39+
New-AzureStorageAccount -StorageAccountName $storageName -Location $location
4040
Set-CurrentStorageAccountName $storageName
4141

42-
New-AzureService -ServiceName $svcName -Location $location
43-
New-AzureQuickVM -Windows -ImageName "a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-R2-BYOL-20160915-en.us-127GB.vhd" -Name $vmName -ServiceName $svcName -AdminUsername "pstestuser" -Password $PLACEHOLDER
42+
New-AzureService -ServiceName $svcName -Location $location
43+
New-AzureQuickVM -Windows -ImageName "a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-R2-20161214-en.us-127GB.vhd" -Name $vmName -ServiceName $svcName -AdminUsername "pstestuser" -Password $PLACEHOLDER
44+
$vm = Get-AzureVM -ServiceName $svcName -Name $vmName
4445

45-
$vm = Get-AzureVM -ServiceName $svcName -Name $vmName
46+
Set-AzureVMChefExtension -VM $vm -ValidationPem "$TestOutputRoot\Resources\ChefExtension\tstorgnztn-validator.pem" -ClientRb "$TestOutputRoot\Resources\ChefExtension\client.rb" -JsonAttribute '{"container_service": {"chef-init-test": {"command": "C:\\opscode\\chef\\bin"}}}' -ChefServiceInterval 35 -Windows
4647

47-
Set-AzureVMChefExtension -VM $vm -ValidationPem "$TestOutputRoot\Resources\ChefExtension\tstorgnztn-validator.pem" -ClientRb "$TestOutputRoot\Resources\ChefExtension\client.rb" -JsonAttribute '{"container_service": {"chef-init-test": {"command": "C:\\opscode\\chef\\bin"}}}' -ChefServiceInterval 35 -Windows
48-
49-
Update-AzureVM -VM $vm.VM -ServiceName $svcName -Name $vmName
48+
Update-AzureVM -VM $vm.VM -ServiceName $svcName -Name $vmName
5049

51-
# Call Get-AzureVMDscExtensionStatus to check the status of the installation
50+
# Call Get-AzureVMDscExtensionStatus to check the status of the installation
5251
[TimeSpan] $timeout = [TimeSpan]::FromMinutes(60)
5352
$maxTime = [datetime]::Now + $timeout
5453
$status = Get-AzureVMChefExtension -VM $vm.VM
@@ -74,23 +73,95 @@ function Test-SetAzureVMChefExtension
7473
$status = Get-AzureVMChefExtension -VM $vm.VM
7574
}
7675

77-
# Call Get-AzureVMChefExtension to ensure extension was installed on the VM
76+
# Call Get-AzureVMChefExtension to ensure extension was installed on the VM
7877
$vm = Get-AzureVM -ServiceName $svcName -Name $vmName
79-
$extension = Get-AzureVMChefExtension -VM $vm.VM -Verbose
78+
$extension = Get-AzureVMChefExtension -VM $vm.VM -Verbose
8079
Assert-NotNull $extension
8180
Assert-NotNull $extension.ExtensionName
8281
Assert-NotNull $extension.Publisher
8382
Assert-NotNull $extension.Version
83+
84+
# Remove Extension
85+
Remove-AzureVMChefExtension -VM $vm.VM -Verbose
86+
}
87+
finally
88+
{
89+
# Cleanup
90+
Remove-AzureStorageAccount -StorageAccountName $storageName -ErrorAction SilentlyContinue
91+
Cleanup-CloudService $svcName
92+
}
93+
}
94+
95+
96+
<#
97+
.SYNOPSIS
98+
Test the usage of the Set virtual machine chef extension command with some advanced options
99+
#>
100+
101+
function Test-SetAzureVMChefExtensionAdvancedOptions
102+
{
103+
# Setup
104+
$vmName = "vmthree"
105+
$svcName = "storthree"
106+
$storageName = "storthree"
107+
$location = "West US"
108+
$TestOutputRoot = [System.AppDomain]::CurrentDomain.BaseDirectory;
109+
110+
try
111+
{
112+
New-AzureStorageAccount -StorageAccountName $storageName -Location $location
113+
Set-CurrentStorageAccountName $storageName
114+
115+
New-AzureService -ServiceName $svcName -Location $location
116+
New-AzureQuickVM -Windows -ImageName "a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-R2-20161214-en.us-127GB.vhd" -Name $vmName -ServiceName $svcName -AdminUsername "pstestuser" -Password $PLACEHOLDER
117+
118+
$vm = Get-AzureVM -ServiceName $svcName -Name $vmName
119+
120+
Set-AzureVMChefExtension -VM $vm -ValidationPem "$TestOutputRoot\Resources\ChefExtension\tstorgnztn-validator.pem" -ClientRb "$TestOutputRoot\Resources\ChefExtension\client.rb" -Daemon "service" -SecretFile "$TestOutputRoot\Resources\ChefExtension\encrypted_data_bag_secret" -Windows
121+
122+
Update-AzureVM -VM $vm.VM -ServiceName $svcName -Name $vmName
123+
124+
# Call Get-AzureVMDscExtensionStatus to check the status of the installation
125+
[TimeSpan] $timeout = [TimeSpan]::FromMinutes(60)
126+
$maxTime = [datetime]::Now + $timeout
127+
$status = Get-AzureVMChefExtension -VM $vm.VM
128+
129+
while($true)
130+
{
131+
if($status -ne $null -and $status.State -ne $null)
132+
{
133+
if(($status.State -eq "Enable") -or ($status.State -eq "Error"))
134+
{
135+
break;
136+
}
137+
}
84138

139+
if([datetime]::Now -gt $maxTime)
140+
{
141+
Throw "The Chef Extension did not report any status within the given timeout from VM [$vmName]"
142+
}
143+
144+
if ($env:AZURE_TEST_MODE -eq "Record"){
145+
sleep -Seconds 15
146+
}
147+
$status = Get-AzureVMChefExtension -VM $vm.VM
148+
}
149+
150+
# Call Get-AzureVMChefExtension to ensure extension was installed on the VM
151+
$vm = Get-AzureVM -ServiceName $svcName -Name $vmName
152+
$extension = Get-AzureVMChefExtension -VM $vm.VM -Verbose
153+
Assert-NotNull $extension
154+
Assert-NotNull $extension.ExtensionName
155+
Assert-NotNull $extension.Publisher
156+
Assert-NotNull $extension.Version
85157

86-
# Remove Extension
158+
# Remove Extension
87159
Remove-AzureVMChefExtension -VM $vm.VM -Verbose
88-
}
89-
finally
90-
{
91-
# Cleanup
92-
Remove-AzureStorageAccount -StorageAccountName $storageName -ErrorAction SilentlyContinue
93-
Cleanup-CloudService $svcName
94-
}
95-
160+
}
161+
finally
162+
{
163+
# Cleanup
164+
Remove-AzureStorageAccount -StorageAccountName $storageName -ErrorAction SilentlyContinue
165+
Cleanup-CloudService $svcName
166+
}
96167
}

0 commit comments

Comments
 (0)