From e801dc4e17fa2998d1678d984364e67a2eec7913 Mon Sep 17 00:00:00 2001 From: Steve Barnes Date: May 18 2011 14:29:42 +0000 Subject: Fixed typo in readme. Added package tests for iptraf, screen, sysstat, procinfo, ntp. Tidyed up 0_lib/functions.sh --- diff --git a/readme b/readme index 9d1f4d7..f6adbd8 100644 --- a/readme +++ b/readme @@ -26,7 +26,7 @@ tests/p_/ : Each of the p_ directories would contain tests tests/r_ : Each of the r_ directories should contain the tests specific to a role. eg: 'lamp'. The test harness looks at - a file called 'pacakge_deps' inside each of the role directories + a file called 'package_deps' inside each of the role directories and runs the role tests if any package listed in that file has been changed / built etc. diff --git a/runtests.sh b/runtests.sh index 4b528f4..c31c139 100644 --- a/runtests.sh +++ b/runtests.sh @@ -1,5 +1,8 @@ #!/bin/bash +# Author: Steve Barnes (steve@echo.id.au) +# Description: this script sources our library functions and starts a test run. + export readonly PASS=0 export readonly FAIL=1 @@ -15,8 +18,11 @@ shopt -s nocasematch # exit as soon as any script returns a non-zero exit status set -e -t_ProcessFolder <(/usr/bin/find ./tests/0_common/ -type f|sort) -t_ProcessFolder <(/usr/bin/find ./tests/p_* -type f|sort) -t_ProcessFolder <(/usr/bin/find ./tests/r_* -type f|sort) +# process our test script folders +t_ProcessFolder <(/usr/bin/find ./tests/0_common/ -type f|sort) +t_ProcessFolder <(/usr/bin/find ./tests/p_*/ -type f|sort) +t_ProcessFolder <(/usr/bin/find ./tests/r_*/ -type f|sort) +# and, we're done. t_Log "Finished." + diff --git a/tests/0_lib/functions.sh b/tests/0_lib/functions.sh index cac6b4c..552c52e 100644 --- a/tests/0_lib/functions.sh +++ b/tests/0_lib/functions.sh @@ -1,57 +1,66 @@ #!/bin/bash -# herein lies a set of common library functions -# any recurring code is welcome here - +# Description: call this function whenever you need to log output (preferred to calling echo) +# Arguments: log string to display function t_Log { - printf "[+] `date` -> $*\n" + printf "[+] `date` -> $*\n" } +# Description: call this at the end of your script to assess the exit status +# Arguments: the exit status from whatever you want checked (ie, '$?') function t_CheckExitStatus { - [ $1 -eq 0 ] && { t_Log "PASS"; return $PASS; } + [ $1 -eq 0 ] && { t_Log "PASS"; return $PASS; } - t_Log "FAIL" - exit $FAIL + t_Log "FAIL" + exit $FAIL } +# Description: call this to perform yum-based installs of packages +# Arguments: a space separated list of package names to install. function t_InstallPackage { - for P in $*; do - - t_Log "Attempting yum install of '$P'..." - yum -y -d0 install $P - t_CheckExitStatus $? - done + t_Log "Attempting yum install: $*" + /usr/bin/yum -y -d0 install "$@" + t_CheckExitStatus $? } +# Description: call this to perform a yum-based removal of packages +# Arguments: a space separated list of package names to remove. function t_RemovePackage { - for P in $*; do - - t_Log "Attempting yum remove of '$P'..." - yum -y -d0 remove $P - t_CheckExitStatus $? - done + t_Log "Attempting yum remove: $*" + /usr/bin/yum -y -d0 remove "$@" + t_CheckExitStatus $? } +# Description: call this to process a list of folders containing test scripts +# Arguments: a list of folder paths to process (see example in runtests.sh) function t_ProcessFolder { - while read f - do - # skip files named 'readme' or 'package_deps' - [[ "${f}" =~ (readme|package_deps) ]] && continue; - - # all test scripts have to be executable - # this allows us to enable/disable individual - # tests by adding/removing the executable flag - # the alternative is to have '/bin/bash $f' here - # but I think the executable flag approach gives - # us more flexibility... - [ -x $f ] && $f - - done < $@ + while read f + do + # skip files named readme or those that start with an _ + [[ "${f}" =~ readme|^_ ]] && continue; + + # handy tip: chmod ug-x to disable individual test scripts. + [ -x ${f} ] && ${f} + + done < $@ + + return 0 +} + +# Description: check to see if one or more packages are installed +# return true if they're all installed, false if not. +# Arguments: one or more package names to check for. +function t_CheckDeps +{ + # TODO + + # success, all packages are installed + return 0 } export -f t_Log @@ -59,3 +68,5 @@ export -f t_CheckExitStatus export -f t_InstallPackage export -f t_RemovePackage export -f t_ProcessFolder +export -f t_CheckDeps + diff --git a/tests/p_iptraf/0-install_iptraf.sh b/tests/p_iptraf/0-install_iptraf.sh new file mode 100755 index 0000000..3467feb --- /dev/null +++ b/tests/p_iptraf/0-install_iptraf.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# IPTraf traffic monitoring package +t_InstallPackage iptraf diff --git a/tests/p_ntp/0-install_ntp.sh b/tests/p_ntp/0-install_ntp.sh new file mode 100755 index 0000000..033d897 --- /dev/null +++ b/tests/p_ntp/0-install_ntp.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# NTPd +t_InstallPackage ntpd diff --git a/tests/p_ntp/5-start-check.sh b/tests/p_ntp/5-start-check.sh new file mode 100644 index 0000000..d997fcf --- /dev/null +++ b/tests/p_ntp/5-start-check.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# Start NTPd services and confirm it's running. + +chkconfig ntpd on +service ntpd start + +NTPD_PID=$(pidof ntpd) + +[ -z "$NTPD_PID" ] && { t_Log "FAIL: couldn't find 'ntpd' in the process list."; exit $FAIL; } diff --git a/tests/p_procinfo/0-install_procinfo.sh b/tests/p_procinfo/0-install_procinfo.sh new file mode 100755 index 0000000..ae3f89a --- /dev/null +++ b/tests/p_procinfo/0-install_procinfo.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# ProcInfo Utility Package +t_InstallPackage procinfo diff --git a/tests/p_screen/0-install_screen.sh b/tests/p_screen/0-install_screen.sh new file mode 100755 index 0000000..d8cc705 --- /dev/null +++ b/tests/p_screen/0-install_screen.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# GNU Screen +t_InstallPackage screen diff --git a/tests/p_strace/0-install_strace.sh b/tests/p_strace/0-install_strace.sh new file mode 100755 index 0000000..fa214cb --- /dev/null +++ b/tests/p_strace/0-install_strace.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# Strace stack tracer package +t_InstallPackage strace diff --git a/tests/p_sysstat/0-install_sysstat.sh b/tests/p_sysstat/0-install_sysstat.sh new file mode 100755 index 0000000..f03a7a3 --- /dev/null +++ b/tests/p_sysstat/0-install_sysstat.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# SysStat Performance Monitoring Tools for Linux +t_InstallPackage sysstat diff --git a/tests/r_lamp/0_lamp_install.sh b/tests/r_lamp/0_lamp_install.sh index 8efc904..fd78883 100644 --- a/tests/r_lamp/0_lamp_install.sh +++ b/tests/r_lamp/0_lamp_install.sh @@ -1,10 +1,4 @@ #!/bin/bash - # Author: Steve Barnes (steve@echo.id.au) -# Filename: 0_lamp_install.sh -# Version: 0.1.1 -# Last Updated: Saturday, 30 April 2011 3:52 PM AEST -# Description: A simple Bash script to install a LAMP stack (Apache, MySQL (server + client) and PHP)) via yum. t_InstallPackage httpd mysql-server php -