-
Notifications
You must be signed in to change notification settings - Fork 8
/
AzureAutomationManager.ps1
356 lines (337 loc) · 13.9 KB
/
AzureAutomationManager.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
##############################################################################################
# AzureAutomationManager.ps1
# Description : This script manages all the setup and test operations in Azure environemnt.
# It is an entry script of Azure Automation
# Operations :
# - Installing AzureSDK
# - VHD preparation : Installing packages required by ICA, LIS drivers and waagent
# - Uplaoding test VHD to cloud
# - Invokes azure test suite
## Author : v-shisav@microsoft.com
## Author : v-ampaw@microsoft.com
###############################################################################################
param (
[string] $xmlConfigFile,
[switch] $eMail,
[string] $logFilename="azure_ica.log",
[switch] $runtests, [switch]$onCloud,
[switch] $vhdprep,
[switch] $upload,
[switch] $help,
[string] $Distro,
[string] $cycleName,
[string] $RunSelectedTests,
[string] $TestPriority,
[string] $osImage,
[switch] $EconomyMode,
[switch] $keepReproInact,
[string] $DebugDistro,
[switch] $UseAzureResourceManager,
[string] $OverrideVMSize,
[switch] $EnableAcceleratedNetworking,
[string] $customKernel,
[string] $customLIS,
[string] $customLISBranch,
[string] $resizeVMsAfterDeployment,
[string] $ExistingResourceGroup,
[switch] $CleanupExistingRG,
[switch] $UseManagedDisks,
[int] $coureCountExceededTimeout = 3600,
[int] $testIterations = 1,
[string] $tipSessionId="",
[string] $tipCluster="",
[switch] $ForceDeleteResources
)
Import-Module .\TestLibs\AzureWinUtils.psm1 -Force -Scope Global
Import-Module .\TestLibs\RDFELibs.psm1 -Force -Scope Global
Import-Module .\TestLibs\ARMLibrary.psm1 -Force -Scope Global
$xmlConfig = [xml](Get-Content $xmlConfigFile)
$user = $xmlConfig.config.Azure.Deployment.Data.UserName
$password = $xmlConfig.config.Azure.Deployment.Data.Password
$sshKey = $xmlConfig.config.Azure.Deployment.Data.sshKey
$sshPublickey = $xmlConfig.config.Azure.Deployment.Data.sshPublicKey
Set-Variable -Name user -Value $user -Scope Global
Set-Variable -Name password -Value $password -Scope Global
Set-Variable -Name sshKey -Value $sshKey -Scope Global
Set-Variable -Name sshPublicKey -Value $sshPublicKey -Scope Global
Set-Variable -Name sshPublicKeyThumbprint -Value $sshPublicKeyThumbprint -Scope Global
Set-Variable -Name PublicConfiguration -Value @() -Scope Global
Set-Variable -Name PrivateConfiguration -Value @() -Scope Global
Set-Variable -Name CurrentTestData -Value $CurrentTestData -Scope Global
Set-Variable -Name preserveKeyword -Value "preserving" -Scope Global
Set-Variable -Name tipSessionId -Value $tipSessionId -Scope Global
Set-Variable -Name tipCluster -Value $tipCluster -Scope Global
Set-Variable -Name global4digitRandom -Value $(Get-Random -SetSeed $(Get-Random) -Maximum 9999 -Minimum 1111) -Scope Global
Set-Variable -Name coureCountExceededTimeout -Value $coureCountExceededTimeout -Scope Global
if($EnableAcceleratedNetworking)
{
Set-Variable -Name EnableAcceleratedNetworking -Value $true -Scope Global
}
if($ForceDeleteResources)
{
Set-Variable -Name ForceDeleteResources -Value $true -Scope Global
}
if($resizeVMsAfterDeployment)
{
Set-Variable -Name resizeVMsAfterDeployment -Value $resizeVMsAfterDeployment -Scope Global
}
if ( $OverrideVMSize )
{
Set-Variable -Name OverrideVMSize -Value $OverrideVMSize -Scope Global
}
if ( $customKernel )
{
Set-Variable -Name customKernel -Value $customKernel -Scope Global
}
if ( $customLIS )
{
Set-Variable -Name customLIS -Value $customLIS -Scope Global
}
if ( $customLISBranch )
{
Set-Variable -Name customLISBranch -Value $customLISBranch -Scope Global
}
if ( $RunSelectedTests )
{
Set-Variable -Name RunSelectedTests -Value $RunSelectedTests -Scope Global
}
if ($ExistingResourceGroup)
{
Set-Variable -Name ExistingRG -Value $ExistingResourceGroup -Scope Global
LogMsg "1111111111111111111111"
}
if ($CleanupExistingRG)
{
Set-Variable -Name CleanupExistingRG -Value $true -Scope Global
}
else
{
Set-Variable -Name CleanupExistingRG -Value $false -Scope Global
}
if ($UseManagedDisks)
{
Set-Variable -Name UseManagedDisks -Value $true -Scope Global
}
else
{
Set-Variable -Name UseManagedDisks -Value $false -Scope Global
}
if ( $xmlConfig.config.Azure.General.StorageAccount -imatch "NewStorage_" )
{
$NewASMStorageAccountType = ($xmlConfig.config.Azure.General.StorageAccount).Replace("NewStorage_","")
Set-Variable -Name NewASMStorageAccountType -Value $NewASMStorageAccountType -Scope Global
}
if ( $xmlConfig.config.Azure.General.ARMStorageAccount -imatch "NewStorage_" )
{
$NewARMStorageAccountType = ($xmlConfig.config.Azure.General.ARMStorageAccount).Replace("NewStorage_","")
Set-Variable -Name NewARMStorageAccountType -Value $NewASMStorageAccountType -Scope Global
}
try
{
# Main Body of the script
# Work flow starts here
# Creating TestResults directory
$testResults = "TestResults"
if (! (test-path $testResults))
{
mkdir $testResults | out-null
}
if ($help)
{
Usage
Write-Host "Info : Help command was passed, not runTests."
exit 1
}
if (! $xmlConfigFile)
{
Write-Host "Error: Missing the xmlConfigFile command-line argument." -ForegroundColor Red
Usage
exit 2
}
if (! (test-path $xmlConfigFile))
{
Write-Host "Error: XML config file", $xmlConfigFile, "does not exist." -ForegroundColor Red
exit 3
}
$Platform=$xmlConfig.config.global.platform
$global=$xmlConfig.config.global
$testStartTime = [DateTime]::Now.ToUniversalTime()
Set-Variable -Name testStartTime -Value $testStartTime -Scope Global
$testDir = $testResults + "\" + $cycleName + "-" + $testStartTime.ToString("yyyyMMddHHmmssff")
mkdir $testDir -ErrorAction SilentlyContinue | out-null
Set-Content -Value "" -Path .\report\testSummary.html -Force -ErrorAction SilentlyContinue | Out-Null
Set-Content -Value "" -Path .\report\AdditionalInfo.html -Force -ErrorAction SilentlyContinue | Out-Null
if ($logFilename)
{
$logfile = $logFilename
}
$logFile = $testDir + "\" + $logfile
Set-Variable -Name logfile -Value $logFile -Scope Global
Set-Content -Path .\report\lastLogDirectory.txt -Value $testDir -ErrorAction SilentlyContinue
Set-Variable -Name Distro -Value $Distro -Scope Global
Set-Variable -Name onCloud -Value $onCloud -Scope Global
Set-Variable -Name xmlConfig -Value $xmlConfig -Scope Global
Set-Content -Path .\report\lastLogDirectory.txt -Value $testDir -ErrorAction SilentlyContinue
Set-Variable -Name vnetIsAllConfigured -Value $false -Scope Global
if($EconomyMode)
{
Set-Variable -Name EconomyMode -Value $true -Scope Global
if($keepReproInact)
{
Set-Variable -Name keepReproInact -Value $true -Scope Global
}
}
else
{
Set-Variable -Name EconomyMode -Value $false -Scope Global
if($keepReproInact)
{
Set-Variable -Name keepReproInact -Value $true -Scope Global
}
else
{
Set-Variable -Name keepReproInact -Value $false -Scope Global
}
}
$AzureSetup = $xmlConfig.config.Azure.General
LogMsg ("Info : AzureAutomationManager.ps1 - LIS on Azure Automation")
LogMsg ("Info : Created test results directory:", $testDir)
LogMsg ("Info : Logfile = ", $logfile)
LogMsg ("Info : Using config file $xmlConfigFile")
if ( ( $xmlConfig.config.Azure.General.ARMStorageAccount -imatch "ExistingStorage" ) -or ($xmlConfig.config.Azure.General.StorageAccount -imatch "ExistingStorage" ) )
{
$regionName = $xmlConfig.config.Azure.General.Location.Replace(" ","").Replace('"',"").ToLower()
$regionStorageMapping = [xml](Get-Content .\XML\RegionAndStorageAccounts.xml)
if ( $xmlConfig.config.Azure.General.ARMStorageAccount -imatch "standard")
{
$xmlConfig.config.Azure.General.ARMStorageAccount = $regionStorageMapping.AllRegions.$regionName.StandardStorage
$xmlConfig.config.Azure.General.StorageAccount = $regionStorageMapping.AllRegions.$regionName.StandardStorage
LogMsg "Info : Selecting existing standard storage account in $regionName - $($regionStorageMapping.AllRegions.$regionName.StandardStorage)"
}
if ( $xmlConfig.config.Azure.General.ARMStorageAccount -imatch "premium")
{
$xmlConfig.config.Azure.General.ARMStorageAccount = $regionStorageMapping.AllRegions.$regionName.PremiumStorage
$xmlConfig.config.Azure.General.StorageAccount = $regionStorageMapping.AllRegions.$regionName.PremiumStorage
LogMsg "Info : Selecting existing premium storage account in $regionName - $($regionStorageMapping.AllRegions.$regionName.PremiumStorage)"
}
}
if ($UseAzureResourceManager)
{
Set-Variable -Name UseAzureResourceManager -Value $true -Scope Global
$selectSubscription = Select-AzureRmSubscription -SubscriptionId $AzureSetup.SubscriptionID
$subIDSplitted = ($AzureSetup.SubscriptionID).Split("-")
$userIDSplitted = ($selectSubscription.Account.Id).Split("-")
LogMsg "SubscriptionName : $($AzureSetup.SubscriptionName)"
LogMsg "SubscriptionId : $($subIDSplitted[0])-xxxx-xxxx-xxxx-$($subIDSplitted[4])"
LogMsg "User : $($userIDSplitted[0])-xxxx-xxxx-xxxx-$($userIDSplitted[4])"
LogMsg "ServiceEndpoint : $($selectSubscription.Environment.ActiveDirectoryServiceEndpointResourceId)"
LogMsg "CurrentStorageAccount : $($AzureSetup.ARMStorageAccount)"
}
else
{
$LinuxSSHCertificate = Import-Certificate -FilePath .\ssh\$sshPublickey -CertStoreLocation Cert:\CurrentUser\My
$sshPublicKeyThumbprint = $LinuxSSHCertificate.Thumbprint
Set-Variable -Name UseAzureResourceManager -Value $false -Scope Global
LogMsg "Setting Azure Subscription ..."
$out = SetSubscription -subscriptionID $AzureSetup.SubscriptionID -subscriptionName $AzureSetup.SubscriptionName -certificateThumbprint $AzureSetup.CertificateThumbprint -managementEndpoint $AzureSetup.ManagementEndpoint -storageAccount $AzureSetup.StorageAccount -environment $AzureSetup.Environment
$currentSubscription = Get-AzureSubscription -SubscriptionId $AzureSetup.SubscriptionID -ExtendedDetails
LogMsg "SubscriptionName : $($currentSubscription.SubscriptionName)"
LogMsg "SubscriptionId : $($currentSubscription.SubscriptionID)"
LogMsg "ServiceEndpoint : $($currentSubscription.ServiceEndpoint)"
LogMsg "CurrentStorageAccount : $($AzureSetup.StorageAccount)"
}
#Check for the Azure platform
if($Platform -eq "Azure")
{
#Installing Azure-SDK
if ( $UseAzureResourceManager )
{
LogMsg "*************AZURE RESOURCE GROUP MODE****************"
}
else
{
LogMsg "*************AZURE SERVICE MANAGEMENT MODE****************"
}
if($keepReproInact)
{
LogMsg "PLEASE NOTE: keepReproInact is set. VMs will not be deleted after test is finished even if, test gets PASS."
}
}
if($upload)
{
$uploadflag=$true
}
if ($vhdprep)
{
$sts=VHDProvision $xmlConfig $uploadflag
if($sts -contains $false)
{
LogMsg "Exiting with Error..!!!"
exit 3
}
LogMsg "moving VHD provision log file to test results directory"
LogMsg "move VHD_Provision.log ${testDir}\VHD_Provision.log"
move "VHD_Provision.log" "${testDir}\VHD_Provision.log"
LogMsg "----------------------------------------------------------"
LogMsg "VHD provision logs : ${testDir}\VHD_Provision.log "
}
if (!$runTests)
{
LogMsg "No tests will be run as runtests parameter is not provided"
LogMsg "Exiting : with VHD prepared for Automation"
LogMsg "==========================================="
exit 4
}
if ($runTests)
{
if($Platform -ne "Azure")
{
LogMsg "Info : Starting ICA test suite on Hyper-V Server"
##To do
#Ivoking ICA scripts on Hyper-V server
#cd ...\Win8_ICA\ica
#.\ica.ps1 .\XML\test.xml -runtests
exit
}
if ($DebugDistro)
{
$OsImage = $xmlConfig.config.Azure.Deployment.Data.Distro | ? { $_.name -eq $DebugDistro} | % { $_.OsImage }
Set-Variable -Name DebugOsImage -Value $OsImage -Scope Global
}
$testCycle = GetCurrentCycleData -xmlConfig $xmlConfig -cycleName $cycleName
#Invoke Azure Test Suite
$testSuiteResultDetails=.\AzureTestSuite.ps1 $xmlConfig -Distro $Distro -cycleName $cycleName -testIterations $testIterations
#if(!$sts)
#{
#exit
#}
# Add summary information to the ica log file
$logDirFilename = [System.IO.Path]::GetFilenameWithoutExtension($xmlConfigFile)
#$summaryText = "<br />~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br /><br />"
$summaryAll = GetTestSummary -testCycle $testCycle -StartTime $testStartTime -xmlFileName $logDirFilename -distro $Distro -testSuiteResultDetails $testSuiteResultDetails
$PlainTextSummary += $summaryAll[0]
$HtmlTextSummary += $summaryAll[1]
Set-Content -Value $HtmlTextSummary -Path .\report\testSummary.html -Force | Out-Null
# Remove HTML tags from platin text summary.
$PlainTextSummary = $PlainTextSummary.Replace("<br />", "`r`n")
$PlainTextSummary = $PlainTextSummary.Replace("<pre>", "")
$PlainTextSummary = $PlainTextSummary.Replace("</pre>", "")
LogMsg "$PlainTextSummary"
if($eMail)
{
SendEmail $xmlConfig -body $HtmlTextSummary
}
}
}
catch
{
$line = $_.InvocationInfo.ScriptLineNumber
$script_name = ($_.InvocationInfo.ScriptName).Replace($PWD,".")
$ErrorMessage = $_.Exception.Message
LogErr "EXCEPTION : $ErrorMessage"
LogErr "Source : Line $line in script $script_name."
}
Finally
{
exit
}