#!/bin/bash
#------------------------------------------------------------------------------
# Test Suite for Helix Installer
# Declarations and Environment
declare Version="2.0.0"
declare Log=
declare LogSymlink=$PWD/log.run_hi_tests.txt
declare -i HIFastMode=0
declare -i PassCount=0
declare -i FailCount=0
declare -i SkipCount=0
declare -i TestCount=0
declare -i ErrorCount=0
declare -i SilentMode=0
declare -i OverallExitStatus=0
declare -i FullTest=${HIT_FULL:-0}
declare HostList=${HIT_OS_LIST:-ALL}
declare TmpFile="/tmp/tmp.$$.$RANDOM"
# Local Functions
function msg () { echo -e "$*"; }
function pass () { msg "PASS: ${1:-Unknown Passed Test}"; PassCount+=1; }
function fail () { msg "FAIL: ${1:-Unknown Failed Test}"; FailCount+=1; }
function skip () { msg "SKIP: ${1:-Unknown Skipped Test}"; SkipCount+=1; }
function errmsg () { msg "\\nError: ${1-Unknown Error}\\n"; ErrorCount+=1; }
function bail () { errmsg "${1-Unknown Error}"; exit "${2:-1}"; }
#------------------------------------------------------------------------------
# Function: terminate
function terminate
{
# Disable signal trapping.
trap - EXIT SIGINT SIGTERM
dbg "$ThisScript: EXITCODE: $((ErrorCount+FailCount))"
# Stop logging.
[[ "$Log" == off ]] || msg "Log is: $Log${H1}"
# With the trap removed, exit.
exit "$((ErrorCount+FailCount))"
}
#------------------------------------------------------------------------------
# Function: usage (required function)
#
# Input:
# $1 - style, either -h (for short form) or -man (for man-page like format).
# The default is -h.
#
# $2 - error message (optional). Specify this if usage() is called due to
# user error, in which case the given message displayed first, followed by the
# standard usage message (short or long depending on $1). If displaying an
# errror, usually $1 should be -h so that the longer usage message doesn't
# obsure the error message.
#
# Sample Usage:
# usage
# usage -h
# usage -man
# usage -h "Incorrect command line usage."
#------------------------------------------------------------------------------
function usage
{
declare style=${1:--h}
declare errorMessage=${2:-Unset}
if [[ "$errorMessage" != Unset ]]; then
echo -e "\\n\\nUsage Error:\\n\\n$errorMessage\\n\\n"
fi
echo "USAGE for $ThisScript v$Version:
$ThisScript [-b] [-o <os1>[,<os2>,...]] [-hb <helix_installer_branch>] [-sb <sdp_branch>] [-n] [-D] [-L <log>]
or
$ThisScript [-h|-man]
"
if [[ $style == -man ]]; then
echo -e "
DESCRIPTION:
This script manages the Helix Installer Test Suite.
OPTIONS:
-b Build Docker images, and then stop before running tests. By default,
tests are executed after images are built.
-o Specify a comma-delimited list of operating systems to build.
Valid operating system values are:
${TestedOperatingSystems[*]}
-hb <helix_installer_branch>
Specify the Helix Installer branch to test. The default is dev.
-sb <sdp_branch>
Specify the SDP branch to test. The default is main, which always
represents the latest version officially released for general
availability.
-L <log>
Specify the path to a log file, or the special value 'off' to disable
logging. By default, all output (stdout and stderr) goes to
${ThisScript%.sh}.<DateTimeStamp>.log
NOTE: This script is self-logging. That is, output displayed on the
screen is simultaneously captured in the log file. Do not run this
script with redirection operators like '> log' or '2>&1', and do not
use 'tee'.
-si Operate silently. All output (stdout and stderr) is redirected to the
log only; no output appears on the terminal. This cannot be used with
'-L off'.
This is useful when running from cron, as it prevents automatic email
from being sent by cron directly, as cron does when a script called
from cron generates any output. This script is then responsible for
email handling, if any is to be done.
-n No-Op. Prints commands instead of running them.
-D Set extreme debugging verbosity.
HELP OPTIONS:
-h Display short help message
-man Display man-style help message
FILES:
EXAMPLES:
SEE ALSO:
"
fi
exit 1
}
#==============================================================================
# Command Line Processing
declare -i shiftArgs=0
set +u
while [[ $# -gt 0 ]]; do
case $1 in
(-b) RunDockerTests=0;;
(-o) TestedOSList="${2/,/ }"; shiftArgs=1;;
(-hb) HelixInstallerBranch="$2"; shiftArgs=1;;
(-sb) SDPBranch="$2"; shiftArgs=1;;
(-h) usage -h;;
(-man) usage -man;;
(-L) Log="$2"; shiftArgs=1;;
(-si) SilentMode=1;;
(-n) NoOp=1;;
(-d) Debug=1;; # Debug verbosity.
(-D) Debug=1; set -x;; # Extreme Debug; use 'set -x' mode.
(*) usage -h "Unknown arg ($1).";;
esac
# Shift (modify $#) the appropriate number of times.
shift; while [[ $shiftArgs -gt 0 ]]; do
[[ $# -eq 0 ]] && usage -h "Incorrect number of arguments."
shiftArgs=$shiftArgs-1
shift
done
done
set -u
#==============================================================================
# Command Line Verification
[[ "$SilentMode" -eq 1 && "$Log" == off ]] && \
usage -h "Cannot use '-si' with '-L off'."
[[ "${Log:-Unset}" == "Unset" ]] && \
Log="${ThisScript%.sh}.$(date +'%Y%m%d-%H%M%S').log"
#==============================================================================
# Main Program
trap terminate EXIT SIGINT SIGTERM
if [[ "${Log}" != off ]]; then
touch "${Log}" || bail "Couldn't touch log file [${Log}]."
# Redirect stdout and stderr to a log file.
if [[ "$SilentMode" -eq 0 ]]; then
exec > >(tee "${Log}")
exec 2>&1
else
exec >"${Log}"
exec 2>&1
fi
ln -f -s "$Log" "$LogSymlink" ||\
warnmsg "Could not create symlink to log file."
fi
msg "\\nStarted ${0##*/} v$Version as $USER@${HOSTNAME} on $(date)."
for host in $HostList; do
# Test hosts are named 'helix-<os>'. Allow a shorthand in env.sh of
# specifying just the '<os>' name, e.g. centos7 or ubuntu16.
[[ "$host" == "helix-"* ]] || host="helix-$host"
msg "\\n\\n==============================================================================\\nHost=$host\\n"
msg "Calling 'vagrant up $host' to initiate Helix Installer."
if vagrant up $host; then
pass "Helix Installer called OK on $host."
else
fail "Helix Installer NOT happy on $host."
fi
sleep 1
msg "Running: vagrant ssh $host -c 'sudo su - perforce -c \"p4 trust -f -y\"'"
if vagrant ssh "$host" -c 'sudo su - perforce -c "p4 trust -f -y" ||:'; then
pass "Trust done on $host."
else
fail "Trust NOT done on $host."
fi
TestCount+=1
msg "Running: vagrant ssh $host -c 'sudo su - perforce -c \"p4 changes -t -m 3\"'"
if vagrant ssh "$host" -c 'sudo su - perforce -c "p4 changes -t -m 3"'; then
pass "Sample Depot is running on $host."
else
fail "Sample Depot is NOT running on $host."
fi
TestCount+=1
if [[ "$HIFastMode" -eq 0 ]]; then
msg "Checking to see if P4Perl is usable."
vagrant ssh "$host" -c 'sudo su - perforce -c "/p4/common/perl/bin/perl -MP4 -e \"print P4::Identify()\""' > "$TmpFile"
if grep '^Rev' "$TmpFile"; then
pass "P4Perl is accessible on $host."
else
fail "P4Perl IS NOT accessible on $host."
fi
rm -f "$TmpFile"
else
skip "Perl not checked due to '-fast' in $VagrantBootstrap."
fi
TestCount+=1
if [[ "$HIFastMode" -eq 0 ]]; then
msg "Checking to see if P4Python is usable."
vagrant ssh "$host" -c 'echo -e "#!/p4/common/python/bin/python3\\n\\nimport P4\\nprint(P4.P4.identify())\\n" > /tmp/p4pythontest.sh'
vagrant ssh "$host" -c 'chmod 777 /tmp/p4pythontest.sh'
vagrant ssh "$host" -c 'sudo su - perforce -c /tmp/p4pythontest.sh' > "$TmpFile"
if grep '^Rev' "$TmpFile"; then
pass "Python built on $host."
else
fail "Python DID NOT build on $host."
fi
rm -f "$TmpFile"
else
skip "Python not checked due to '-fast' in $VagrantBootstrap."
fi
TestCount+=1
if vagrant ssh "$host" -c "sudo su - root -c $TestDir/hi_test_cleanup.sh"; then
pass "Extreme Cleanup test OK."
else
fail "Extreme Cleanup test failed."
fi
TestCount+=1
if vagrant ssh "$host" -c "sudo su - root -c $TestDir/hi_test_settings.sh"; then
pass "Configured mode with settings.cfg test OK."
else
fail "Configured mode with settings.cfg test failed."
fi
TestCount+=1
if vagrant ssh "$host" -c "sudo su - root -c $TestDir/hi_test_settings2.sh"; then
pass "Configured mode with settings2.cfg test OK."
else
fail "Configured mode with settings2.cfg test failed."
fi
TestCount+=1
done
msg "Summary:\\n Tests Executed:\\t$TestCount\\n Passed:\\t\\t$PassCount\\n Skipped:\\t\\t$SkipCount\\n Failed:\\t\\t$FailCount\\n Test system errors:\\t$ErrorCount"
if [[ "$TestCount" -ge 0 && "$FailCount" -eq 0 && "$ErrorCount" -eq 0 ]]; then
if [[ "$SkipCount" -eq 0 ]]; then
msg "\\nSUCCESS: All tests were executed, and all passed."
else
msg "\\nSUCCESS: All tests passed ($SkipCount skipped)."
fi
else
msg "\\nFAIL: At least one test failed (or none ran)."
OverallExitStatus=1
fi
msg "That took $((SECONDS/3600)) hours $((SECONDS%3600/60)) minutes $((SECONDS%60)) seconds.\n"
exit "$OverallExitStatus"
| # | Change | User | Description | Committed | |
|---|---|---|---|---|---|
| #13 | 27288 | C. Thomas Tyler | Removed old Vagrant Test suite. | ||
| #12 | 27284 | C. Thomas Tyler |
Added Docker test suite to displace Vagrant. Initial version passes with options: hits.sh -o centos7 |
||
| #11 | 26784 | C. Thomas Tyler |
reset_sdp.sh v3.17.0: Made /hx* mount points configurable in settings.cfg, and updated documentation accordingly. Added support for configuring /hxmetadata1 and /hxmetadata2 with different values. Added test coverage for changing /hxdepots from the default. Enhanced test suite. TEST FAIL NOTE: As of this change, tests are succeeding on all platforms except CentOS 6. Failures are in the test suite infrastructure, not related to this change. |
||
| #10 | 26556 | C. Thomas Tyler |
Fixed issue with tests on SSL-enabled servers. Fixed issue with running tests on multiple servers by refactoring the single 'vagrant up' call for all hosts to have a per-host call 'vagrant up <>'. |
||
| #9 | 26405 | C. Thomas Tyler | Automated logging. | ||
| #8 | 26025 | C. Thomas Tyler | Fixed test suite quoting bug. | ||
| #7 | 26021 | C. Thomas Tyler |
Test suite enhancements to better test Configured mode with settings.cfg. |
||
| #6 | 25890 | C. Thomas Tyler |
Enhanced test suite to truly verify that P4Perl and P4Python are usable. |
||
| #5 | 25820 | C. Thomas Tyler |
Enhanced bootstrap test to call Heilx Installer with '-i' to enable testing of scenarios involving newly added files. |
||
| #4 | 25755 | C. Thomas Tyler | Cosmetic output tweak. | ||
| #3 | 25754 | C. Thomas Tyler |
Helix Installer test suite changes: Added new test outcome 'SKIP' to supplement 'PASS'/'FAIL'. Added logic to not bother running P4Perl/P4Python tests if '-fast' is specified in the bootstrap script, as in that case we don't expect those to have been installed. Changed bootstrap method back to '-fast' for now. |
||
| #2 | 25722 | C. Thomas Tyler | Fixed host naming convention issue. | ||
| #1 | 25673 | C. Thomas Tyler |
Added simple test driver and results analysis script. Calls 'vagrant up' to call the Helix Installer on various OS's, and then inspects the installed SDP generated VMs. |