-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathAzureAutomationManager.ps1
180 lines (166 loc) · 6.71 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
##############################################################################################
# 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 : [email protected]
###############################################################################################
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] $TestPriority, [string]$osImage)
#Import-Module .\TestLibs\RDFELibs.psm1 -Force
Import-Module .\TestLibs\AzureWinUtils.psm1 -Force
$xmlConfig = [xml](Get-Content $xmlConfigFile)
$user = $xmlConfig.config.Azure.Deployment.Data.UserName
$password = $xmlConfig.config.Azure.Deployment.Data.Password
Set-Variable -Name user -Value $user -Scope Global
Set-Variable -Name password -Value $password -Scope Global
$dtapServerIp = $xmlConfig.config.Azure.Deployment.Data.DTAP.IP
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
}
#Parse XML file
#Get Parameters through XML file
$xmlConfig=[XML](Get-Content $xmlConfigFile)
$Platform=$xmlConfig.config.global.platform
$global=$xmlConfig.config.global
$testStartTime = [DateTime]::Now.ToUniversalTime()
Set-Variable -Name testStartTime -Value $testStartTime -Scope Global
$fname = [System.IO.Path]::GetFilenameWithoutExtension($xmlConfigFile)
$testDir = $testResults + "\" + $fname + "-" + $testStartTime.ToString("yyyyMMdd-HHmmss")
mkdir $testDir -ErrorAction SilentlyContinue | out-null
if ($logFilename)
{
$logfile = $logFilename
}
$logFile = $testDir + "\" + $logfile
Set-Variable -Name logfile -Value $logFile -Scope Global
Set-Variable -Name Distro -Value $Distro -Scope Global
Set-Variable -Name onCloud -Value $onCloud -Scope Global
Set-Variable -Name xmlConfig -Value $xmlConfig -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")
LogMsg ("Setting Subscription")
SetSubscription -subscriptionID $AzureSetup.SubscriptionID -subscriptionName $AzureSetup.SubscriptionName -certificateThumbprint $AzureSetup.CertificateThumbprint -managementEndpoint $AzureSetup.ManagementEndpoint -storageAccount $AzureSetup.StorageAccount
$AllSubscriptions = Get-AzureSubscription
foreach ($subscription in $AllSubscriptions)
{
if (($subscription.CurrentStorageAccountName -imatch $AzureSetup.StorageAccount) -and ( $subscription.SubscriptionName -imatch $AzureSetup.SubscriptionName))
{
$currentSubscription = $subscription
}
}
LogMsg "SubscriptionName : $($currentSubscription.SubscriptionName)"
LogMsg "SubscriptionId : $($currentSubscription.SubscriptionID)"
LogMsg "ServiceEndpoint : $($currentSubscription.ServiceEndpoint)"
LogMsg "CurrentStorageAccount : $($currentSubscription.CurrentStorageAccountName)"
#Check for the Azure platform
if($Platform -eq "Azure")
{
#Installing Azure-SDK
.\SetupScripts\ImportAzureSDK.ps1
if(!$?)
{
LogMsg "Failed to import Azure-SDK"
exit 2
}
LogMsg "*************AZURE POWERSHELL****************"
}
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
}
$testCycle = GetCurrentCycleData -xmlConfig $xmlConfig -cycleName $cycleName
#Invoke Azure Test Suite
$testSuiteResultDetails=.\AzureTestSuite.ps1 $xmlConfig -Distro $Distro -cycleName $cycleName
#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]
# 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
{
$ErrorMessage = $_.Exception.Message
LogMsg "EXCEPTION : $ErrorMessage"
}
Finally
{
exit
}