forked from iamshital/LISAv2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutomationManager.ps1
236 lines (202 loc) · 9.39 KB
/
AutomationManager.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
##############################################################################################
# AutomationManager.ps1
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the Apache License.
#
<#
.SYNOPSIS
This script manages all the setup and test operations in Azure & Hyper-V environment.
It is an entry script of Automation
Installing AzureSDK
- VHD preparation : Installing packages required by ICA, LIS drivers and WALA
- Uploading test VHD to cloud
- Invokes Azure test suite or Hyper-v tests
.PARAMETER
# See param lines
.INPUTS
Load dependent modules
Set all parameters as global variables
Azure login
Start AzureTestSuite.ps1, if for Azure testing
#>
###############################################################################################
param (
[CmdletBinding()]
[string] $xmlConfigFile,
[switch] $eMail,
[switch] $runtests, [switch]$onCloud,
[switch] $vhdprep,
[switch] $upload,
[switch] $help,
[string] $RGIdentifier,
[string] $cycleName,
[string] $RunSelectedTests,
[string] $TestPriority,
[string] $osImage,
[switch] $DeployVMPerEachTest,
[switch] $DoNotDeleteVMs,
[string] $OverrideVMSize,
[switch] $EnableAcceleratedNetworking,
[string] $CustomKernel,
[string] $CustomLIS,
[string] $customLISBranch,
[string] $resizeVMsAfterDeployment,
[string] $ExistingResourceGroup,
[switch] $CleanupExistingRG,
[string] $XMLSecretFile,
# Experimental Feature
[switch] $UseManagedDisks,
[int] $CoreCountExceededTimeout = 3600,
[int] $TestIterations = 1,
[string] $TiPSessionId="",
[string] $TiPCluster="",
[switch] $ForceDeleteResources
)
Get-ChildItem .\Libraries -Recurse | Where-Object { $_.FullName.EndsWith(".psm1") } | `
ForEach-Object { Import-Module $_.FullName -Force -Global -DisableNameChecking}
$xmlConfig = [xml](Get-Content $xmlConfigFile)
$user = $xmlConfig.config.$TestPlatform.Deployment.Data.UserName
$password = $xmlConfig.config.$TestPlatform.Deployment.Data.Password
$sshKey = $xmlConfig.config.$TestPlatform.Deployment.Data.sshKey
$sshPublickey = $xmlConfig.config.$TestPlatform.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 CoreCountExceededTimeout -Value $CoreCountExceededTimeout -Scope Global
Set-Variable -Name resultPass -Value "PASS" -Scope Global
Set-Variable -Name resultFail -Value "FAIL" -Scope Global
Set-Variable -Name resultAborted -Value "ABORTED" -Scope Global
Set-Variable -Name AllVMData -Value @() -Scope Global
Set-Variable -Name isDeployed -Value @() -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
}
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
}
try {
$TestResultsDir = "TestResults"
if (! (test-path $TestResultsDir)) {
mkdir $TestResultsDir | out-null
}
if (! (test-path ".\Report")) {
mkdir ".\Report" | out-null
}
$testStartTime = [DateTime]::Now.ToUniversalTime()
Set-Variable -Name testStartTime -Value $testStartTime -Scope Global
Set-Content -Value "" -Path .\Report\testSummary.html -Force -ErrorAction SilentlyContinue | Out-Null
Set-Content -Value "" -Path .\Report\AdditionalInfo.html -Force -ErrorAction SilentlyContinue | Out-Null
Set-Variable -Name LogFile -Value $LogFile -Scope Global
Set-Variable -Name Distro -Value $RGIdentifier -Scope Global
Set-Variable -Name onCloud -Value $onCloud -Scope Global
Set-Variable -Name xmlConfig -Value $xmlConfig -Scope Global
LogMsg "'$LogDir' saved to .\Report\lastLogDirectory.txt"
Set-Content -Path .\Report\lastLogDirectory.txt -Value $LogDir -Force
Set-Variable -Name vnetIsAllConfigured -Value $false -Scope Global
if($DoNotDeleteVMs) {
Set-Variable -Name DoNotDeleteVMs -Value $true -Scope Global
} else {
Set-Variable -Name DoNotDeleteVMs -Value $false -Scope Global
}
Set-Variable -Name IsWindows -Value $false -Scope Global
if($xmlconfig.config.testsDefinition.test.Tags `
-and $xmlconfig.config.testsDefinition.test.Tags.ToString().Contains("nested-hyperv"))
{
Set-Variable -Name IsWindows -Value $true -Scope Global
}
$AzureSetup = $xmlConfig.config.$TestPlatform.General
LogMsg ("Info : Using config file $xmlConfigFile")
if ( ( $xmlConfig.config.$TestPlatform.General.ARMStorageAccount -imatch "ExistingStorage" ) -or ($xmlConfig.config.$TestPlatform.General.StorageAccount -imatch "ExistingStorage" )) {
$regionName = $xmlConfig.config.$TestPlatform.General.Location.Replace(" ","").Replace('"',"").ToLower()
$regionStorageMapping = [xml](Get-Content .\XML\RegionAndStorageAccounts.xml)
if ( $xmlConfig.config.$TestPlatform.General.ARMStorageAccount -imatch "standard") {
$xmlConfig.config.$TestPlatform.General.ARMStorageAccount = $regionStorageMapping.AllRegions.$regionName.StandardStorage
LogMsg "Info : Selecting existing standard storage account in $regionName - $($regionStorageMapping.AllRegions.$regionName.StandardStorage)"
}
if ( $xmlConfig.config.$TestPlatform.General.ARMStorageAccount -imatch "premium") {
$xmlConfig.config.$TestPlatform.General.ARMStorageAccount = $regionStorageMapping.AllRegions.$regionName.PremiumStorage
LogMsg "Info : Selecting existing premium storage account in $regionName - $($regionStorageMapping.AllRegions.$regionName.PremiumStorage)"
}
}
LogMsg "------------------------------------------------------------------"
if ( $TestPlatform -eq "Azure") {
$SelectedSubscription = Select-AzureRmSubscription -SubscriptionId $AzureSetup.SubscriptionID
$subIDSplitted = ($SelectedSubscription.Subscription.SubscriptionId).Split("-")
$userIDSplitted = ($SelectedSubscription.Account.Id).Split("-")
LogMsg "SubscriptionName : $($SelectedSubscription.Subscription.Name)"
LogMsg "SubscriptionId : $($subIDSplitted[0])-xxxx-xxxx-xxxx-$($subIDSplitted[4])"
LogMsg "User : $($userIDSplitted[0])-xxxx-xxxx-xxxx-$($userIDSplitted[4])"
LogMsg "ServiceEndpoint : $($SelectedSubscription.Environment.ActiveDirectoryServiceEndpointResourceId)"
LogMsg "CurrentStorageAccount : $($AzureSetup.ARMStorageAccount)"
} elseif ( $TestPlatform -eq "HyperV") {
for( $index=0 ; $index -lt $xmlConfig.config.Hyperv.Hosts.ChildNodes.Count ; $index++ ) {
LogMsg "HyperV Host : $($xmlConfig.config.Hyperv.Hosts.ChildNodes[$($index)].ServerName)"
LogMsg "Source VHD Path : $($xmlConfig.config.Hyperv.Hosts.ChildNodes[$($index)].SourceOsVHDPath)"
LogMsg "Destination VHD Path : $($xmlConfig.config.Hyperv.Hosts.ChildNodes[$($index)].DestinationOsVHDPath)"
}
}
LogMsg "------------------------------------------------------------------"
if($DoNotDeleteVMs) {
LogMsg "PLEASE NOTE: DoNotDeleteVMs is set. VMs will not be deleted after test is finished even if, test gets PASS."
}
$testCycle = GetCurrentCycleData -xmlConfig $xmlConfig -cycleName $cycleName
$testSuiteResultDetails=.\AzureTestSuite.ps1 $xmlConfig -Distro $Distro -cycleName $cycleName -TestIterations $TestIterations -DeployVMPerEachTest $DeployVMPerEachTest
$testSuiteResultDetails = $testSuiteResultDetails | Select-Object -Last 1
$logDirFilename = [System.IO.Path]::GetFilenameWithoutExtension($xmlConfigFile)
$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
$PlainTextSummary = $PlainTextSummary.Replace("<br />", "`r`n")
$PlainTextSummary = $PlainTextSummary.Replace("<pre>", "")
$PlainTextSummary = $PlainTextSummary.Replace("</pre>", "")
LogMsg "$PlainTextSummary"
if($eMail){
SendEmail $xmlConfig -body $HtmlTextSummary
}
}
catch {
ThrowException($_)
}
Finally {
exit
}