-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from HuijingHei/master
Add 2 test cases: vm install by iso; shutdown vm in the guest
- Loading branch information
Showing
3 changed files
with
277 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |