forked from VirtQE-S1/ESX-LISA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilFunctions.ps1
1852 lines (1604 loc) · 50.9 KB
/
utilFunctions.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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
###############################################################################
##
## ___________ _____________ ___ .____ .___ _________ _____
## \_ _____// _____/\ \/ / | | | |/ _____/ / _ \
## | __)_ \_____ \ \ / ______ | | | |\_____ \ / /_\ \
## | \/ \ / \ /_____/ | |___| |/ \/ | \
## /_______ /_______ //___/\ \ |_______ \___/_______ /\____|__ /
## \/ \/ \_/ \/ \/ \/
##
###############################################################################
##
## ESX-LISA is an automation testing framework based on github.com/LIS/lis-test
## project. In order to support ESX, ESX-LISA uses PowerCLI to automate all
## aspects of vSphere maagement, including network, storage, VM, guest OS and
## more. This framework automates the tasks required to test the
## Redhat Enterprise Linux Server on WMware ESX Server.
##
###############################################################################
##
## Revision:
## v1.0 - xiaofwan - 11/25/2016 - Fork from github.com/LIS/lis-test.
## Incorporate VMware PowerCLI with framework
## v1.1 - xiaofwan - 11/28/2016 - Merge SendEmail and SummaryToString update
## Merge bug fix from LISA
## v1.2 - xiaofwan - 1/25/2017 - Insert suite name into result dir name,
## such as cases-open_vm_tools-20170120-141152
## v1.3 - xiaofwan - 1/25/2017 - $vm.testCaseResults only contains "Passed",
## "Failed", "Skipped", "Aborted", and "none".
## v1.4 - xiaofwan - 2/3/2017 - $True will be $true and $False will be $false.
## v1.5 - xiaofwan - 2/4/2017 - Test result can be exported as JUnix XML file.
## Correct some comment issues.
## v1.6 - xiaofwan - 2/4/2017 - Remove Test-Admin function.
## v1.7 - xiaofwan - 2/6/2017 - The <skipped/> section should be removed when
## case failed or aborted.
## v1.8 - xiaofwan - 2/21/2017 - Two new functions to set XML result the kernel
## firmware and ESX version.
## v1.9 - xiaofwan - 2/21/2017 - Iteration related code has been removed.
## v2.0 - xiaofwan - 2/21/2017 - Add test case running date and time in XML.
## v2.1 - xiaofwan - 2/21/2017 - Move case running time calculation into
## SetRunningTime function.
## v2.2 - xiaofwan - 3/17/2017 - Change case result timer from TotalMinutes to
## TotalSeconds to satisfy Jenkins and Polarion
## v2.3 - xiaofwan - 7/18/2017 - Add a property in case result to save
## TC_COVERED info into result XML.
##
###############################################################################
<#
.Synopsis
Helper functions for the Lisa automation.
.Description
The functions in this file are helper functions for the
the lisa.ps1 and stateEngine.ps1 automation scripts.
.Link
None.
#>
###############################################################################
#
# PowerCLIImport
#
###############################################################################
function PowerCLIImport () {
<#
.Description
Import VMware.VimAutomation.Core module if it does not exist.
#>
$modules = Get-Module
$foundVimautomation = $false
foreach($module in $modules)
{
if($module.Name -eq "VMware.VimAutomation.Core")
{
"Info: PowerCLI module VMware.VimAutomation.Core already exists."
$foundVimautomation = $true
break
}
}
if (-not $foundVimautomation)
{
Import-Module VMware.VimAutomation.Core
}
}
###############################################################################
#
# ConnectToVIServer
#
###############################################################################
function ConnectToVIServer ([string] $visIpAddr,
[string] $visUsername,
[string] $visPassword,
[string] $visProtocol)
{
<#
.Description
Connect with VSphere VI Server if connnect does not exist.
.Parameter visIpAddr
REQUIRED
VI Server IP address
Type : [String]
.Parameter visUsername
REQUIRED
VI Server login username
Type : [String]
.Parameter visPassword
REQUIRED
VI Server login password
Type : [String]
.Parameter visProtocol
REQUIRED
VI Server login method, such as HTTP or HTTPS.
Type : [String]
.Example
ConnectToVIServer <visIpAddr> <visUsername> <visPassword> <visProtocol>
#>
#
# Verify the VIServer related environment variable existed.
#
if (-not $visIpAddr)
{
"Error : vCenter IP address is not configured, it is required."
exit
}
if (-not $visUsername)
{
"Error : vCenter login username is not configured, it is required."
exit
}
if (-not $visPassword)
{
"Error : vCenter login password is not configured, it is required."
exit
}
if (-not $visProtocol)
{
"Error : vCenter connection method is not configured, it is required."
exit
}
#
# Check the PowerCLI package installed
#
Get-PowerCLIVersion | out-null
if (-not $?)
{
"Error : Please install VMWare PowerCLI package."
exit
}
if (-not $global:DefaultVIServer)
{
"Info : Connecting with VIServer $visIpAddr."
Connect-VIServer -Server $visIpAddr `
-Protocol $visProtocol `
-User $visUsername `
-Password $visPassword `
-Force | Out-Null
if (-not $?)
{
"Error : Cannot connect with vCenter with $visIpAddr " +
"address, $visProtocol protocol, username $visUsername, " +
"and password $visPassword."
exit
}
"Debug : vCenter connected with " +
"session id $($global:DefaultVIServer.SessionId)"
}
else
{
"Info : vCenter connected already! " +
"Session id: $($global:DefaultVIServer.SessionId)"
}
}
#####################################################################
#
# GetJUnitXML
#
#####################################################################
function GetJUnitXML()
{
<#
.Synopsis
Generate a JUnit XML object from template file.
.Description
Load JUnit XML result template file, and generate an XML object.
.ReturnValue
An xml object of JUnit result.
Output type: [XML]
.Example
GetJUnitXML
#>
LogMsg 6 ("Info : GetJUnitXML()")
$template = @'
<testsuite name="" timestamp="">
<properties>
<property name="esx.version" value="" />
<property name="kernel.version" value="" />
<property name="firmware.version" value="" />
</properties>
<testcase id="" name="" time="">
<skipped/>
<failure type=""></failure>
<properties>
<property name="TC_COVERED" value="" />
</properties>
</testcase>
</testsuite>
'@
$guid = [System.Guid]::NewGuid().ToString("N")
$templatePath = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), $guid + ".txt");
$template | Out-File $templatePath -encoding UTF8
# load template into XML object
$junit_xml = New-Object xml
$junit_xml.Load($templatePath)
Remove-Item $templatePath
return $junit_xml
}
#####################################################################
#
# SetESXVersion
#
#####################################################################
function SetESXVersion([String] $ver)
{
<#
.Synopsis
Add ESX version into XML result.
.Description
Find the ESX version property and set ESX version into result XML object.
.Parameter ver
The version of ESX host.
Type : [String]
.Example
SetESXVersion "6.0 build 4192238"
#>
LogMsg 6 ("Info : SetESXVersion($($ver))")
foreach ($property in $testResult.testsuite.properties.property)
{
if ($property.name -eq "esx.version")
{
$property.value = $ver
return
}
}
}
#####################################################################
#
# SetOSInfo
#
#####################################################################
function SetOSInfo([String] $kernelVer, [String] $firmwareVer)
{
<#
.Synopsis
Add Kernel and firmware version into XML result.
.Description
Find the Kernel and firmware version properties and set Kernel
and firmware version into result XML object.
.Parameter kernelVer
The version of guest kernel.
Type : [String]
.Parameter firmwareVer
The version of guest firmware info.
Type : [String]
.Example
SetOSInfo "2.6.32-694.el6.x86_64" "BIOS"
#>
LogMsg 6 ("Info : SetOSInfo($($kernelVer), $($firmwareVer))")
foreach ($property in $testResult.testsuite.properties.property)
{
if ($property.name -eq "kernel.version" -and $property.value -eq "")
{
$property.value = $kernelVer
}
if ($property.name -eq "firmware.version" -and $property.value -eq "")
{
$property.value = $firmwareVer
}
}
}
#####################################################################
#
# SetResultSuite
#
#####################################################################
function SetResultSuite([String] $testSuite)
{
<#
.Synopsis
Configure test suite in result XML object.
.Description
Find the test suite, and configure test suite into result XML object.
.Parameter testSuite
The name of the test suite to run
Type : [String]
.Example
SetResultSuite "acceptance"
#>
LogMsg 6 ("Info : SetResultSuite($($testSuite))")
$testResult.testsuite.name = $testSuite
}
#####################################################################
#
# SetTimeStamp
#
#####################################################################
function SetTimeStamp([String] $testTimeStamp)
{
<#
.Synopsis
Add test date time in result XML object.
.Description
Find the test suite, and configure test date time into result XML object.
.Parameter testTimeStamp
The start time of test run
Type : [String]
.Example
SetTimeStamp "02/21/2017 13:14:25"
#>
LogMsg 6 ("Info : SetTimeStamp($($testTimeStamp))")
$testResult.testsuite.timestamp = $testTimeStamp
}
#####################################################################
#
# SetTestResult
#
#####################################################################
function SetTestResult([String] $testName, [Object] $testID, [String] $completionCode)
{
<#
.Synopsis
Add test case result into result XML object except running time.
.Description
Clone a test case group as template, add test result into that group.
.Parameter testName
The name of the test
Type : [String]
.Parameter testID
The ID of the test
Type : [Object]
.Parameter completionCode
The test result, such as Passed, Failed, Skipped, and Aborted
Type : [String]
.Example
SetTestResult $testName $testID $completionCode
#>
LogMsg 6 ("Info : SetTestResult($($testName))")
$newTestCaseTemplate = (@($testResult.testsuite.testcase)[0]).Clone()
$newTestCase = $newTestCaseTemplate.clone()
$newTestCase.name = $testName
$newTestCase.id = $testID.test
switch ($completionCode)
{
"Passed" {
$newTestCase.RemoveChild($newTestCase.ChildNodes[0]) | Out-Null
$newTestCase.RemoveChild($newTestCase.ChildNodes[0]) | Out-Null
}
"Skipped" {
$newTestCase.RemoveChild($newTestCase.ChildNodes[1]) | Out-Null
}
"Failed" {
$newTestCase.RemoveChild($newTestCase.ChildNodes[0]) | Out-Null
$newTestCase.failure.type = "Failed"
$newTestCase.failure.InnerText = "Test $testName Failed."
}
"Aborted" {
$newTestCase.RemoveChild($newTestCase.ChildNodes[0]) | Out-Null
$newTestCase.failure.type = "Aborted"
$newTestCase.failure.InnerText = "Test $testName Aborted."
}
}
foreach ($property in $newTestCase.properties.property)
{
if ($property.name -eq "TC_COVERED")
{
$property.value = $testID.tc
break
}
}
$testResult.testsuite.AppendChild($newTestCase) > $null
}
#####################################################################
#
# SetRunningTime
#
#####################################################################
function SetRunningTime([String] $testName, [System.Xml.XmlElement] $vm)
{
<#
.Synopsis
Set running time in result XML object.
.Description
Find the test case, and configure test running time into result XML object.
.Parameter testName
The test name
Type : [String]
.Parameter vm
An XML element representing the VM
Type : [System.Xml.XmlElement]
.Example
SetRunningTime $testName $vm
#>
LogMsg 6 ("Info : SetRunningTime($testName)")
$caseEndTime = [DateTime]::Now
$deltaTime = $caseEndTime - [DateTime]::Parse($vm.caseStartTime)
LogMsg 0 "Info : $($vm.vmName) currentTest lasts $($deltaTime.hours) Hours, $($deltaTime.minutes) Minutes, $($deltaTime.seconds) seconds."
$runningTime = "{0:N0}" -f $deltaTime.TotalSeconds
foreach ($testCase in $testResult.testsuite.testcase)
{
if ($testCase.name -eq $testName)
{
$testCase.time = $runningTime
}
}
}
#####################################################################
#
# SaveResultToXML
#
#####################################################################
function SaveResultToXML([String] $testDir)
{
<#
.Synopsis
Save test result to XML file in result folder..
.Description
Export result XML object into an XML file.
.Parameter testDir
The folder storing test log.
Type : [String]
.Example
SaveResultToXML $testDir
#>
LogMsg 6 ("Info : SaveResultToXML to ($($testDir))")
$resultXMLFileName = "Report-" + $testResult.testsuite.name + ".xml"
# remove users with undefined name (remove template)
$testResult.testsuite.testcase | Where-Object { $_.Name -eq "" } | ForEach-Object { [void]$testResult.testsuite.RemoveChild($_) }
# save xml to file
$resultXMLFile = Join-Path -path $testDir -childPath $resultXMLFileName
$resultXMLFile = (Get-Item -Path ".\" -Verbose).FullName + "\" + $resultXMLFile
$testResult.Save($resultXMLFile)
}
#####################################################################
#
# HasItBeenTooLong
#
#####################################################################
function HasItBeenTooLong([String] $timestamp, [Int] $timeout)
{
<#
.Synopsis
Check to see if a timeout has occured.
.Description
Convert the timestamp from a string to a [DateTime] type,
add in the timeout value and see if it is less than the
current date/time.
.Parameter timestamp
A string representing the timestamp
Type : [String]
.Parameter timeout
An integer timeout period in seconds.
Type : [Int]
.ReturnValue
Return $true if current time is greater than timestamp + timeout,
$false otherwise.
Output type : [Boolean]
.Example
HasItBeenTooLong $myTimeStamp $myTimeOut
#>
$retVal = $false
if (-not $timeStamp)
{
# Bad data - force a timeout
return $true
}
if (-not $timeout)
{
# Bad data - force a timeout
return $true
}
if ($timeout -le 0)
{
# Bad data - force a timeout
return $true
}
$now = [DateTime]::Now
$ts = [DateTime]::Parse($timestamp)
$tooLong = [DateTime]::Compare($ts.AddSeconds($timeout), $now)
if ($tooLong -eq -1)
{
LogMsg 9 "INFO : The current task is started at $timestamp"
LogMsg 9 "INFO : Timeout is set to $timeout seconds"
$retVal = $true
}
return $retVal
}
#####################################################################
#
# GetNextTest
#
#####################################################################
function GetNextTest([System.Xml.XmlElement] $vm, [xml] $xmlData)
{
<#
.Synopsis
Get the name of the next test the VM is to run
.Description
Examine the $vm.suite field and then walk through the test suite
to return the string name of the next test the VM is to perform.
If all tests have been performed, return the string "done".
.Parameter vm
An XML element representing the VM
Type : [System.Xml.XmlElement]
.ReturnValue
A string of the name of the next test.
Output type : [Boolean]
.Example
GetNextTest $myVM
#>
LogMsg 9 "Info : GetNextText($($vm.vmName))"
LogMsg 9 "Debug: vm.currentTest = $($vm.currentTest)"
LogMsg 9 "Debug: vm.suite = $($vm.suite)"
$done = "done" # Assume no more tests to run
if (-not $vm)
{
LogMsg 0 "Error: GetNextTest() received a null VM parameter"
return $done
}
if (-not $xmlData)
{
LogMsg 0 "Error: GetNextTest() received a null xmlData parameter"
return $done
}
if ($vm.currentTest -eq $done)
{
return $done
}
if (-not $xmlData.config.testSuites.suite)
{
LogMsg 0 "Error: no test suites defined in .xml file"
return $done
}
$tests = $null
$nextTest = $done
foreach ($suite in $xmlData.config.testSuites.suite)
{
if ($suite.suiteName -eq $vm.suite)
{
if ($suite.suiteTests)
{
$tests = $suite.suiteTests
}
else
{
LogMsg 0 "Error: Test suite $($suite.suiteName) does not have any tests"
return $done
}
break
}
}
#
# We found the tests for the VMs test suite. Next find the next test to run.
#
if ($tests)
{
$prev = "unknown"
$currentTest = $vm.currentTest
foreach ($t in $tests.suiteTest)
{
if ($currentTest -eq "none")
{
$nextTest = [string] $t
break
}
if ($currentTest -eq $prev)
{
$nextTest = [string] $t
break
}
$prev = $t
}
}
return $nextTest
}
#####################################################################
#
# GetTestData
#
#####################################################################
function GetTestData([String] $testName, [xml] $xmlData)
{
<#
.Synopsis
Retrieve the xml object for the specified test
.Description
Find the test named $testName, and return the xml element
for that test, on $null if the test is not found.
.Parameter testName
The name of the test to return
Type : [String]
.ReturnValue
An xml element of the specific test
Output type: [System.Xml.XmlElement]
.Example
GetTestData "MyTest"
#>
LogMsg 6 ("Info : GetTestData($($testName))")
$testData = $null
foreach ($test in $xmlData.config.testCases.test)
{
if ($test.testName -eq $testName)
{
$testData = $test
break
}
}
return $testData
}
#####################################################################
#
# GetTestID
#
#####################################################################
function GetTestID([String] $testName, [xml] $xmlData)
{
<#
.Synopsis
Retrieve the xml object for the test ID of specified test
.Description
Find the test named $testName, and return the testID field value,
on $null if the test is not found.
.Parameter testName
The name of the test to return
Type : [String]
.ReturnValue
An ID object with test and tc properties.
Type: [Object]
.Example
GetTestData "MyTest"
#>
LogMsg 6 ("Info : GetTestID($($testName))")
$idObj = "" | Select-Object -Property test,tc
foreach ($test in $xmlData.config.testCases.test)
{
if ($test.testName -eq $testName)
{
$idObj.test = $test.testID
foreach ($param in $test.testParams.param)
{
if ($param.contains("TC_COVERED="))
{
$idObj.tc = $param.split("=")[1]
break
}
}
break
}
}
return $idObj
}
#####################################################################
#
# GetTestTimeout
#
#####################################################################
function GetTestTimeout([System.Xml.XmlElement] $vm, [XML] $xmlData)
{
<#
.Synopsis
Retrieve timeout value for the VM's current test
.Description
Return the timeout value defined in the .xml file for
the current test, or $null if no timeout is specified.
.Parameter vm
The xml element of the virtual machine
Type : [System.Xml.XmlElement]
.ReturnValue
A string representing the timeout value in seconds,
or $null if not timeout is found.
Output type: [String]
.Example
GetTestTimeout $myVM
#>
$timeout = $null
$testData = GetTestData $vm.currentTest $xmlData
if ($testData.timeout)
{
$timeout = [string] $testData.timeout
}
return $timeout
}
#####################################################################
#
# AbortCurrentTest
#
#####################################################################
function AbortCurrentTest([System.Xml.XmlElement] $vm, [string] $msg)
{
<#
.Synopsis
Mark the current test as aborted.
.Description
Displayed msg if provided, set the VM's testCaseResults to
"False", and set the VM's state to completed, update the
VM's timestamp
.Parameter vm
The xml element of the virtual machine
Type : [System.Xml.XmlElement]
.Parameter msg
A string to be included in the ICA log.
Type : [String]
.ReturnValue
none
.Example
AbortCurrentTest $myVM "This is just a test"
#>
#$TestAborted = "TestAborted"
if ($null -ne $msg)
{
logMsg 0 "Error: $($vm.vmName) $msg"
}
$vm.testCaseResults = $Aborted
$vm.state = $CollectLogFiles
logMsg 2 "Info : $($vm.vmName) transitioned to state $($vm.state)"
$vm.stateTimestamp = [DateTime]::Now.ToString()
}
#####################################################################
#
# SummaryToString
#
#####################################################################
function SummaryToString([XML] $xmlConfig, [DateTime] $startTime, [string] $xmlFilename, [string] $logDir)
{
<#
.Synopsis
Append the summary text from each VM into a single string.
.Description
Append the summary text from each VM one long string. The
string includes line breaks so it can be display on a
console or included in an e-mail message.
.Parameter xmlConfig
The parsed xml from the $xmlFilename file.
Type : [System.Xml]
.Parameter startTime
The date/time the ICA test run was started
Type : [DateTime]
.Parameter xmlFilename
The name of the xml file for the current test run.
Type : [String]
.Parameter logDir
The path of the folder containing the log files
Type : [String]
.ReturnValue
A string containing all the summary message from all
VMs in the current test run.
.Example
SummaryToString $testConfig $myStartTime $myXmlTestFile
#>
$str = "<br />Test Results Summary<br />"
$str += "ESX-LISA test run on " + $startTime
$str += "<br />XML file: $xmlFilename<br /><br />"
#
# Add information about the host running ICA to the e-mail summary
#
$str += "<pre>"
foreach($vm in $xmlConfig.config.VMs.vm)
{
$str += $vm.emailSummary + "<br />"
}
$fname = [System.IO.Path]::GetFilenameWithoutExtension($xmlFilename)
#
# Check to see if the provided log path is absolute
#
if ([System.IO.Path]::IsPathRooted($logDir))
{
$logPath = $logDir
}
else
{
$logPath = (Get-Item -Path ".\" -Verbose).FullName + "\" + $logDir
}
if (-not $suite)
{
$suite = $xmlConfig.config.VMs.vm.suite
}
$str += "Logs can be found at " + $logPath + "\" + $fname + "-" + $suite + "-" + $startTime.ToString("yyyyMMdd-HHmmss") + "<br /><br />"
$str += "</pre><br />"
return $str
}
#####################################################################
#
# SendEmail
#
#####################################################################
function SendEmail([XML] $xmlConfig, [DateTime] $startTime, [string] $xmlFilename, [string] $logDir)
{
<#
.Synopsis
Send an e-mail message with test summary information.
.Description
Collect the test summary information from each VM. Send an
eMail message with this summary information to emailList defined
in the xml config file.
.Parameter xmlConfig
The parsed XML from the test xml file
Type : [System.Xml]
.Parameter logDir
The path of the folder containing the log files
Type : [String]
.ReturnValue
none
.Example
SendEmail $myConfig
#>
$to = @()
foreach($r in $xmlConfig.config.global.email.recipients.to)
{
$to = $to + $r
}
$from = $xmlConfig.config.global.email.Sender
$subject = $xmlConfig.config.global.email.Subject + " " + $startTime
$smtpServer = $xmlConfig.config.global.email.smtpServer
$fname = [System.IO.Path]::GetFilenameWithoutExtension($xmlFilename)
$body = SummaryToString $xmlConfig $startTime $fname
$body = $body.Replace("Aborted", '<em style="background:Aqua; color:Red">Aborted</em>')
$body = $body.Replace("Failed", '<em style="background:Yellow; color:Red">Failed</em>')
#
# Check to see if the provided log path is absolute
#
if ([System.IO.Path]::IsPathRooted($logDir))
{
$logPath = $logDir
}
else
{
$logPath = (Get-Item -Path ".\" -Verbose).FullName + "\" + $logDir
}
$str += "Logs can be found at " + $logPath + "\" + $fname + "-" + $startTime.ToString("yyyyMMdd-HHmmss") + "<br /><br />"
Send-mailMessage -to $to -from $from -subject $subject -body $body -BodyAsHtml -smtpserver $smtpServer
}
#####################################################################
#
# ShutDownVM
#
#####################################################################
function ShutDownVM([System.Xml.XmlElement] $vm)
{
<#
.Synopsis
Stop the VM
.Description
Try to send a halt command to the VM. If this fails,