Skip to content

Commit

Permalink
Merge pull request #22 from henrywang/master
Browse files Browse the repository at this point in the history
ESX-LISA 2.1.0 Release
  • Loading branch information
VirtQE-S1 authored Feb 27, 2017
2 parents 10b374a + 595858c commit fb22e3b
Show file tree
Hide file tree
Showing 3 changed files with 215 additions and 253 deletions.
52 changes: 52 additions & 0 deletions OSAbstractions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
## v1.0 - xiaofwan - 11/25/2016 - Fork from github.com/LIS/lis-test.
## Incorporate VMware PowerCLI with framework
## v1.1 - xiaofwan - 2/3/2017 - $True will be $true and $False will be $false.
## v1.2 - xiaofwan - 2/21/2017 - Two new functions to fetch kernel and firmware
## version info.
##
###############################################################################

Expand Down Expand Up @@ -251,6 +253,56 @@ function GetOSType ([System.Xml.XmlElement] $vm)
return $os
}

#####################################################################
#
# GetKernelVersion()
#
#####################################################################
function GetKernelVersion ()
{
<#
.Synopsis
Ask the OS to provide Kernel version.
.Description
Use SSH to send a uname command to the VM. Use the
returned name as Kernel version.
#>

# plink will pending at waiting password if sshkey failed auth, so
# pipe a 'y' to response
$ver = echo y | bin\plink -i ssh\${sshKey} root@${hostname} "uname -r"

return $ver
}


#####################################################################
#
# GetFirmwareVersion()
#
#####################################################################
function GetFirmwareVersion ()
{
<#
.Synopsis
Ask the OS to provide firmware version.
.Description
Use SSH to send a uname command to the VM. The firmware is
based on shell command result.
#>

# plink will pending at waiting password if sshkey failed auth, so
# pipe a 'y' to response
$cmdResult = echo y | bin\plink -i ssh\${sshKey} root@${hostname} "ls /sys/firmware/efi"

$firmware = "BIOS"
if ($cmdResult -eq 0)
{
$firmware = "EFI"
}
return $firmware
}


#####################################################################
#
Expand Down
104 changes: 34 additions & 70 deletions stateEngine.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
## v1.6 - xiaofwan - 2/3/2017 - Add test case running time support.
## v1.7 - xiaofwan - 2/3/2017 - $True will be $true and $False will be $false.
## v1.8 - xiaofwan - 2/4/2017 - Test result can be exported as JUnix XML file.
## v1.9 - xiaofwan - 2/21/2017 - ESX host version, kernel and firmware version
## are visable in XML result.
## v2.0 - xiaofwan - 2/21/2017 - Iteration related code has been removed.
## v2.1 - xiaofwan - 2/21/2017 - Add test case running date and time in XML.
## v2.2 - xiaofwan - 2/21/2017 - Add SetRunningTime in ForceShutDown to support
## time calculation in force shut down scenario.
##
###############################################################################

Expand Down Expand Up @@ -320,7 +326,7 @@ function RunICTests([XML] $xmlConfig)
#
# Add the state related xml elements to each VM xml node
#
$xmlElementsToAdd = @("currentTest", "stateTimeStamp", "caseStartTime", "state", "emailSummary", "jobID", "testCaseResults", "iteration", "isRebooted")
$xmlElementsToAdd = @("currentTest", "stateTimeStamp", "caseStartTime", "state", "emailSummary", "jobID", "testCaseResults", "isRebooted")
foreach($element in $xmlElementsToAdd)
{
if (-not $vm.${element})
Expand All @@ -336,14 +342,10 @@ function RunICTests([XML] $xmlConfig)
$vm.AppendChild($newElement);

#
# Correct the default iteration value
# Add test suite and test date time into test result XML
#
$vm.iteration = "-1"

#
# Add test suite into test result XML
#
SetResultSuite $vm.suite $testResult
SetTimeStamp $testStartTime.toString()
SetResultSuite $vm.suite

#
# Add some information to the email summary text
Expand All @@ -353,7 +355,7 @@ function RunICTests([XML] $xmlConfig)
$outGetCliVer = Get-PowerCLIVersion
$vm.emailSummary += " PowerCLI : $($outGetCliVer.UserFriendlyVersion) <br />"
$outGlobalVar = $global:DefaultVIServer
$vm.emailSummary += " vCenter : version $($outGlobalVar.Version) build $($outGlobalVar.Build) <br />"
$vm.emailSummary += " vCenter : version $($outGlobalVar.Version) build $($outGlobalVar.Build) <br />"
#
# Verify the ESXi serer is on and connected.
#
Expand All @@ -372,6 +374,11 @@ function RunICTests([XML] $xmlConfig)
$vm.emailSummary += " Host : $($vm.hvServer) with ESXi $($vmhostOut.Version) build $($vmhostOut.Build)<br />"
$vm.emailSummary += "<br /><br />"

#
# Add ESX host version into result XML
#
SetESXVersion "$($vmhostOut.Version) build $($vmhostOut.Build)"

#
# Make sure the VM actually exists
#
Expand Down Expand Up @@ -847,13 +854,6 @@ function DoSystemDown([System.Xml.XmlElement] $vm, [XML] $xmlData)
#
$vm.isRebooted = $true.ToString()

$iterationMsg = $null
if ($vm.iteration -ne "-1")
{
$iterationMsg = " (iteration $($vm.iteration))"
}
LogMsg 0 "Info : $($vm.vmName) currentTest updated to $($vm.currentTest) ${iterationMsg}"

$vm.caseStartTime = [DateTime]::Now.ToString()

if ($($vm.currentTest) -eq "done")
Expand Down Expand Up @@ -1127,7 +1127,6 @@ function DoRunSetupScript([System.Xml.XmlElement] $vm, [XML] $xmlData)
#
LogMsg 0 "Error : VM $($vm.vmName) setup script ${script} for test ${testName} failed"
$vm.emailSummary += (" Test {0, -25} : {1}<br />" -f ${testName}, "Failed - setup script failed")
#$vm.emailSummary += (" Test {0,-25} : {2}<br />" -f $($vm.currentTest), $iterationMsg, $completionCode)
if ($abortOnError)
{
$vm.currentTest = "done"
Expand Down Expand Up @@ -1591,6 +1590,13 @@ function DoSystemUp([System.Xml.XmlElement] $vm, [XML] $xmlData)
$os = (GetOSType $vm).ToString()
LogMsg 9 "INFO : The OS type is $os"

#
# Add guest kernel version and firmware info int result XML
#
$kernelVer = GetKernelVersion
$firmwareVer = GetFirmwareVersion
SetOSInfo $kernelVer $firmwareVer

UpdateState $vm $PushTestFiles

}
Expand Down Expand Up @@ -1707,24 +1713,6 @@ function DoPushTestFiles([System.Xml.XmlElement] $vm, [XML] $xmlData)
"ipv4=$($vm.ipv4)" | out-file -encoding ASCII -append -filePath $constFile
}

#
# Add the iteration information if test case is being iterated
#
if ($vm.iteration -ne "-1")
{
"iteration=$($vm.iteration)" | out-file -encoding ASCII -append -filePath $constFile

if ($testData.iterationParams)
{
$iterationParam = GetIterationParam $vm $xmlData

if ($iterationParam -and $iterationparam -ne "")
{
"iterationParam=${iterationParam}" | out-file -encoding ASCII -append -filePath $constFile
}
}
}

#
# Push the constants file to the VM is it was created
#
Expand Down Expand Up @@ -2332,11 +2320,6 @@ function DoCollectLogFiles([System.Xml.XmlElement] $vm, [XML] $xmlData)
}

$currentTest = $vm.currentTest
$iterationNum = $null
if ($vm.iteration -ne "-1")
{
$iterationNum = $($vm.iteration)
}

#
# Update the e-mail summary
Expand All @@ -2355,21 +2338,15 @@ function DoCollectLogFiles([System.Xml.XmlElement] $vm, [XML] $xmlData)
$completionCode = $Aborted
}

$iterationMsg = $null
if ($vm.iteration -ne "-1")
{
$iterationMsg = "($($vm.iteration))"
}

$testID = GetTestID $currentTest $xmlData
SetTestResult $currentTest $testID $completionCode

$vm.emailSummary += (" Test {0,-25} : {2}<br />" -f $($vm.currentTest), $iterationMsg, $completionCode)
$vm.emailSummary += (" Test {0,-25} : {1}<br />" -f $($vm.currentTest), $completionCode)

#
# Collect test results
#
$logFilename = "$($vm.vmName)_${currentTest}_${iterationNum}.log"
$logFilename = "$($vm.vmName)_${currentTest}.log"
LogMsg 4 "Info : $($vm.vmName) collecting logfiles"
if (-not (GetFileFromVM $vm "${currentTest}.log" "${testDir}\${logFilename}") )
{
Expand Down Expand Up @@ -2417,7 +2394,7 @@ function DoCollectLogFiles([System.Xml.XmlElement] $vm, [XML] $xmlData)
#
SendCommandToVM $vm "rm -f state.txt"

LogMsg 0 "Info : $($vm.vmName) Status for test $currentTest $iterationMsg = $completionCode"
LogMsg 0 "Info : $($vm.vmName) Status for test $currentTest - $completionCode"


if ( $($testData.postTest) )
Expand Down Expand Up @@ -2645,24 +2622,15 @@ function DoDetermineReboot([System.Xml.XmlElement] $vm, [XML] $xmlData)

UpdateCurrentTest $vm $xmlData

$iterationMsg = $null
if ($vm.iteration -ne "-1")
{
$iterationMsg = "(iteration $($vm.iteration))"
}
LogMsg 0 "Info : $($vm.vmName) currentTest updated to $($vm.currentTest) ${iterationMsg}"
LogMsg 0 "Info : $($vm.vmName) currentTest updated to $($vm.currentTest)"

if ($vm.currentTest -eq "done")
{
UpdateState $vm $ShutDownSystem
}
else
{
$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."

SetRunningTime $vm.currentTest $deltaTime.TotalMinutes
SetRunningTime $vm.currentTest $vm

#
# Mark next test not rebooted
Expand Down Expand Up @@ -2803,11 +2771,7 @@ function DoShuttingDown([System.Xml.XmlElement] $vm, [XML] $xmlData)
}
else
{
$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."

SetRunningTime $vm.currentTest $deltaTime.TotalMinutes
SetRunningTime $vm.currentTest $vm

UpdateState $vm $SystemDown
}
Expand Down Expand Up @@ -2912,11 +2876,7 @@ function DoRunCleanUpScript([System.Xml.XmlElement] $vm, [XML] $xmlData)
LogMsg 0 "Error : $($vm.vmName) entered RunCleanupScript state when test $($vm.currentTest) does not have a cleanup script"
$vm.emailSummary += "Entered RunCleanupScript but test does not have a cleanup script<br />"
}
$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."

SetRunningTime $vm.currentTest $deltaTime.TotalMinutes
SetRunningTime $vm.currentTest $vm

UpdateState $vm $SystemDown
}
Expand Down Expand Up @@ -2983,6 +2943,8 @@ function DoForceShutDown([System.Xml.XmlElement] $vm, [XML] $xmlData)

if ($v.PowerState -eq "PoweredOff")
{
SetRunningTime $vm.currentTest $vm

UpdateState $vm $nextState
}
else
Expand Down Expand Up @@ -3012,6 +2974,8 @@ function DoForceShutDown([System.Xml.XmlElement] $vm, [XML] $xmlData)

if ($v.PowerState -eq "PoweredOff")
{
SetRunningTime $vm.currentTest $vm

UpdateState $vm $nextState
break
}
Expand Down
Loading

0 comments on commit fb22e3b

Please sign in to comment.