run_hi_tests.sh #1

  • //
  • guest/
  • perforce_software/
  • helix-installer/
  • azure-quickstart/
  • test/
  • run_hi_tests.sh
  • View
  • Commits
  • Open Download .zip Download (6 KB)
#!/bin/bash
#------------------------------------------------------------------------------

# Test Suite for Helix Installer
# Calls 'vagrant up' to call the Helix Installer on various OS's,
# and then inspects the installed SDP on each generated VM.

# Usage:
# cd <HelixInstallRoot>/test
### Review env.sh, source if desired, modify to change defaults.
# source ./env.sh
# ./run_hi_tests.sh

# Warning: Be prepared to enter password if 'vagrant up' goes interactive while
# doing 'sudo', as it might if you haven't used 'sudo' recently.

# 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}"; }

# Variables
declare Version="1.5.1"
declare VagrantCfg="helix_installer_test.json"
declare VagrantBootstrap="bootstrap-linux.sh"
declare Log=$PWD/log.run_hi_tests.$(date +'%Y%m%d-%H%M').txt
declare LogSymlink=$PWD/log.run_hi_tests.txt

# This is the dir on test VMs where the test scripts and supplememntal filse, including
# this file, appear on launched VMs (per the Vagrantfile).
declare TestDir=/tmp/test-files

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"

# Main Program

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 on host ${HOSTNAME%%.*} at $(date)."

if [[ -r "$VagrantBootstrap" ]]; then
   if grep -Eq '^HelixInstallerArgs=.*-fast' "$VagrantBootstrap"; then
      msg "The Vagrant boostrap file uses Helix Installer fast mode.\\nP4Perl/P4Python tests will be skipped."
      HIFastMode=1
   else
      msg "The Vagrant boostrap file uses Helix Installer without -fast.\\nP4Perl/P4Python tests will be run."
      HIFastMode=0
   fi
else
   bail "Missing Vagrant bootsrap file: $VagrantBootstrap"
fi

if [[ "$FullTest" -eq 1 ]]; then
   msg "Calling 'vagrant destroy --force' to to blast VMs."
   vagrant destroy --force
else
   msg "Skipping 'vagrant up'."
fi

if [[ $HostList == "ALL" ]]; then
   HostList="$(grep :nodename "$VagrantCfg"|cut -d '"' -f 4)"
fi

msg "Operating systems: $HostList"

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
#1 27421 Robert Cowham Branching

//guest/perforce_software/helix-installer/main/...

to //guest/perforce_software/helix-installer/azure-quickstart/...
//guest/perforce_software/helix-installer/main/test/run_hi_tests.sh
#6 26793 C. Thomas Tyler Released HelixInstaller/MultiArch/2020.1/26784 (2020/09/25).
#5 26578 C. Thomas Tyler Released Helix Installer 2020.1.26576 (2020/06/17).
#4 26031 C. Thomas Tyler Released Helix Installer 2019.4.26026 (2019/08/22).
#3 25900 C. Thomas Tyler Released HelixInstaller 2019.3.25890 (2019/07/24).
#2 25822 C. Thomas Tyler Released HelixInstaller/MultiArch/2019.3/25820 (2019/07/11).
#1 25725 C. Thomas Tyler Released HelixInstaller/MultiArch/2019.2/25723 (2019/06/19).
//guest/perforce_software/helix-installer/dev/test/run_hi_tests.sh
#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.