Skip to content

Commit

Permalink
Merge pull request #21 from HuijingHei/master
Browse files Browse the repository at this point in the history
Add 2 test cases: vm install by iso; shutdown vm in the guest
  • Loading branch information
henrywang authored Feb 27, 2017
2 parents c71982b + 2ac45fd commit 10b374a
Show file tree
Hide file tree
Showing 3 changed files with 277 additions and 1 deletion.
2 changes: 1 addition & 1 deletion testscripts/go_check_reboot.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ else
}

# Note: start sleep for few seconds to wait for vm start, then exit
Start-Sleep -seconds 5
Start-Sleep -seconds 20
}

DisconnectWithVIServer
Expand Down
114 changes: 114 additions & 0 deletions testscripts/go_vm_install_by_iso.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
###############################################################################
##
## Description:
## Check vm, because vm is already installed by iso, so only check vm exists
## Return passed, case is passed; return failed, case is failed
##
###############################################################################
##
## Revision:
## v1.0 - hhei - 2/21/2017 - Check vm.
##
###############################################################################

<#
.Synopsis
reboot in vm.
.Description
Check reboot in vm.
.Parameter vmName
Name of the test VM.
.Parameter testParams
Semicolon separated list of test parameters.
#>

param([String] $vmName, [String] $hvServer, [String] $testParams)
#
# Checking the input arguments
#
if (-not $vmName)
{
"Error: VM name cannot be null!"
exit
}

if (-not $hvServer)
{
"Error: hvServer cannot be null!"
exit
}

if (-not $testParams)
{
Throw "Error: No test parameters specified"
}

#
# Display the test parameters so they are captured in the log file
#
"TestParams : '${testParams}'"

#
# Parse the test parameters
#
$rootDir = $null
$sshKey = $null
$ipv4 = $null

$params = $testParams.Split(";")
foreach ($p in $params)
{
$fields = $p.Split("=")
switch ($fields[0].Trim())
{
"sshKey" { $sshKey = $fields[1].Trim() }
"rootDir" { $rootDir = $fields[1].Trim() }
"ipv4" { $ipv4 = $fields[1].Trim() }
default {}
}
}

if (-not $rootDir)
{
"Warn : no rootdir was specified"
}
else
{
if ( (Test-Path -Path "${rootDir}") )
{
cd $rootDir
}
else
{
"Warn : rootdir '${rootDir}' does not exist"
}
}

#
# Source the tcutils.ps1 file
#
. .\setupscripts\tcutils.ps1

PowerCLIImport
ConnectToVIServer $env:ENVVISIPADDR `
$env:ENVVISUSERNAME `
$env:ENVVISPASSWORD `
$env:ENVVISPROTOCOL

$result = $Failed
$vmOut = Get-VMHost -Name $hvServer | Get-VM -Name $vmName
if (-not $vmOut)
{
Write-Error -Message "go_vm_install_by_iso: Unable to create VM object for VM $vmName" -Category ObjectNotFound -ErrorAction SilentlyContinue
}
else
{
"Info : Find $vmName"
$result = $Passed
}

DisconnectWithVIServer
return $result
162 changes: 162 additions & 0 deletions testscripts/go_vm_shutdown.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
###############################################################################
##
## Description:
## shutdown vm, in the guest, execute command: shutdown
## Return passed, case is passed; return failed, case is failed
##
###############################################################################
##
## Revision:
## v1.0 - hhei - 2/21/2017 - shutdown vm.
##
###############################################################################

<#
.Synopsis
reboot in vm.
.Description
Check reboot in vm.
.Parameter vmName
Name of the test VM.
.Parameter testParams
Semicolon separated list of test parameters.
#>

param([String] $vmName, [String] $hvServer, [String] $testParams)
#
# Checking the input arguments
#
if (-not $vmName)
{
"Error: VM name cannot be null!"
exit
}

if (-not $hvServer)
{
"Error: hvServer cannot be null!"
exit
}

if (-not $testParams)
{
Throw "Error: No test parameters specified"
}

#
# Display the test parameters so they are captured in the log file
#
"TestParams : '${testParams}'"

#
# Parse the test parameters
#
$rootDir = $null
$sshKey = $null
$ipv4 = $null

$params = $testParams.Split(";")
foreach ($p in $params)
{
$fields = $p.Split("=")
switch ($fields[0].Trim())
{
"sshKey" { $sshKey = $fields[1].Trim() }
"rootDir" { $rootDir = $fields[1].Trim() }
"ipv4" { $ipv4 = $fields[1].Trim() }
default {}
}
}

if (-not $rootDir)
{
"Warn : no rootdir was specified"
}
else
{
if ( (Test-Path -Path "${rootDir}") )
{
cd $rootDir
}
else
{
"Warn : rootdir '${rootDir}' does not exist"
}
}

#
# Source the tcutils.ps1 file
#
. .\setupscripts\tcutils.ps1

PowerCLIImport
ConnectToVIServer $env:ENVVISIPADDR `
$env:ENVVISUSERNAME `
$env:ENVVISPASSWORD `
$env:ENVVISPROTOCOL

$Result = $Failed
$vmOut = Get-VMHost -Name $hvServer | Get-VM -Name $vmName
if (-not $vmOut)
{
Write-Error -Message "go_vm_shutdown: Unable to create VM object for VM $vmName" -Category ObjectNotFound -ErrorAction SilentlyContinue
}
else
{
$DISTRO = ""
$command = ""
$DISTRO = GetLinuxDistro ${ipv4} ${sshKey}
if ( -not $DISTRO )
{
"Error : Guest OS version is NULL"
$Result = $Failed
}
elseif ( $DISTRO -eq "RedHat6" )
{
$command = "poweroff"
$Result = $Passed
}
elseif ( $DISTRO -eq "RedHat7" )
{
$command = "systemctl poweroff"
$Result = $Passed
}
else
{
"Error : Guest OS version is $DISTRO"
$Result = $Failed
}

"Info : Guest OS version is $DISTRO"

if ( $Result -eq $Passed )
{
"Info : Poweroff $vmName now"
bin\plink.exe -i ssh\${sshKey} root@${ipv4} "$command"
Start-Sleep -seconds 5

$timeout = 300
while ( $timeout -gt 0 )
{
$vmObj = Get-VMHost -Name $hvServer | Get-VM -Name $vmName
if ($vmObj.PowerState -ne "PoweredOff")
{
Start-Sleep -seconds 1
$timeout -= 1
}
else
{
$Result = $Passed
break
}
}

}

}

DisconnectWithVIServer
return $result

0 comments on commit 10b374a

Please sign in to comment.