@@ -25,30 +25,29 @@ $PLACEHOLDER = "PLACEHOLDER1@";
25
25
Test the usage of the Set virtual machine chef extension command
26
26
#>
27
27
28
- # Setup
29
- $vmName = " vmone"
30
- $svcName = " storone"
31
- $storageName = " storone"
32
- $location = " West US"
33
- $TestOutputRoot = [System.AppDomain ]::CurrentDomain.BaseDirectory;
34
-
35
28
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
+
37
37
try
38
- {
39
- New-AzureStorageAccount - StorageAccountName $storageName - Location $location
38
+ {
39
+ New-AzureStorageAccount - StorageAccountName $storageName - Location $location
40
40
Set-CurrentStorageAccountName $storageName
41
41
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
44
45
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
46
47
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
50
49
51
- # Call Get-AzureVMDscExtensionStatus to check the status of the installation
50
+ # Call Get-AzureVMDscExtensionStatus to check the status of the installation
52
51
[TimeSpan ] $timeout = [TimeSpan ]::FromMinutes(60 )
53
52
$maxTime = [datetime ]::Now + $timeout
54
53
$status = Get-AzureVMChefExtension - VM $vm.VM
@@ -74,23 +73,95 @@ function Test-SetAzureVMChefExtension
74
73
$status = Get-AzureVMChefExtension - VM $vm.VM
75
74
}
76
75
77
- # Call Get-AzureVMChefExtension to ensure extension was installed on the VM
76
+ # Call Get-AzureVMChefExtension to ensure extension was installed on the VM
78
77
$vm = Get-AzureVM - ServiceName $svcName - Name $vmName
79
- $extension = Get-AzureVMChefExtension - VM $vm.VM - Verbose
78
+ $extension = Get-AzureVMChefExtension - VM $vm.VM - Verbose
80
79
Assert-NotNull $extension
81
80
Assert-NotNull $extension.ExtensionName
82
81
Assert-NotNull $extension.Publisher
83
82
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
+ }
84
138
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
85
157
86
- # Remove Extension
158
+ # Remove Extension
87
159
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
+ }
96
167
}
0 commit comments