From aa5803e0e3368172d7674ff760983c568118df16 Mon Sep 17 00:00:00 2001 From: Reto Buerki Date: Mon, 19 Nov 2012 10:43:42 +0100 Subject: testing: Switch to Debian based guest images Instead of extracting a downloaded Gentoo filesystem tree into a file containing a reiserfs filesystem, create an ext3 filesystem inside a sparse file, mount it and debootstrap an up-to-date Debian system. Use this image as base for all UML guest images. Also, drop support for the various consoles and use xterm unconditionally. --- testing/scripts/function.sh | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) (limited to 'testing/scripts/function.sh') diff --git a/testing/scripts/function.sh b/testing/scripts/function.sh index e7ecbcf83..04723f105 100755 --- a/testing/scripts/function.sh +++ b/testing/scripts/function.sh @@ -55,13 +55,6 @@ function searchandreplace { [ -d "$DESTDIR" ] || die "$DESTDIR is not a directory!" - ######################### - # create a temporary file - # - - TMPFILE="/tmp/sr.$$" - - ########################################### # search and replace in each found file the # given string @@ -69,17 +62,9 @@ function searchandreplace { for eachfoundfile in `find $DESTDIR -type f` do - sed -e "s/$SEARCHSTRING/$REPLACESTRING/g" "$eachfoundfile" > "$TMPFILE" - cp -f "$TMPFILE" "$eachfoundfile" + sed -i -e "s/$SEARCHSTRING/$REPLACESTRING/g" "$eachfoundfile" done - - ########################### - # delete the temporary file - # - - rm -f "$TMPFILE" - } ############################################# -- cgit v1.2.3 From c120f25e60415bda8d8cce752e34a0bfff264ff5 Mon Sep 17 00:00:00 2001 From: Reto Buerki Date: Thu, 6 Dec 2012 15:48:14 +0100 Subject: Provide log_action and log_status functions These two functions are used to log action descriptions and the corresponding command exit status in a consistent way. --- testing/scripts/function.sh | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'testing/scripts/function.sh') diff --git a/testing/scripts/function.sh b/testing/scripts/function.sh index 04723f105..daf56486b 100755 --- a/testing/scripts/function.sh +++ b/testing/scripts/function.sh @@ -16,9 +16,11 @@ ############################################ -# print output in color +# output functions # +export TERM=xterm + function cecho { echo -e "\033[1;31m$1\033[0m" } @@ -30,6 +32,29 @@ function cecho-n { echo -en "\033[1;31m$1\033[0m" } +# log an action +# $1 - current action description +log_action() +{ + /bin/echo -n "[....] $1 " +} + +# log an action status +# $1 - exit status of action +log_status() +{ + RED=$(tput setaf 1) + GREEN=$(tput setaf 2) + NORMAL=$(tput op) + + tput hpa 0 + if [ $1 -eq 0 ]; then + /bin/echo -ne "[${GREEN} ok ${NORMAL}" + else + /bin/echo -ne "[${RED}FAIL${NORMAL}" + fi + echo +} ############################################# # output all args to stderr and exit with -- cgit v1.2.3 From b86866579ab3054a21120bca00b4bdfe8c8e575d Mon Sep 17 00:00:00 2001 From: Reto Buerki Date: Thu, 6 Dec 2012 16:58:37 +0100 Subject: Move execute wrappers to function.sh file --- testing/scripts/function.sh | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'testing/scripts/function.sh') diff --git a/testing/scripts/function.sh b/testing/scripts/function.sh index daf56486b..4ee9b24b8 100755 --- a/testing/scripts/function.sh +++ b/testing/scripts/function.sh @@ -14,10 +14,31 @@ # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. +# execute command +# $1 - command to execute +# $2 - whether or not to log command exit status +# (0 -> disable exit status logging) +execute() +{ + cmd=${1} + echo $cmd >>$LOGFILE 2>&1 + $cmd >>$LOGFILE 2>&1 + status=$? + [ "$2" != 0 ] && log_status $status + if [ $status != 0 ]; then + echo + echo "! Command $cmd failed, exiting (status $status)" + echo "! Check why here $LOGFILE" + exit 1 + fi +} -############################################ -# output functions -# +# execute command in chroot +# $1 - command to execute +execute_chroot() +{ + execute "chroot $LOOPDIR $@" +} export TERM=xterm -- cgit v1.2.3 From fb2aab414af644a73e0dcca99215fa18f57a503f Mon Sep 17 00:00:00 2001 From: Reto Buerki Date: Thu, 6 Dec 2012 17:00:15 +0100 Subject: Use red color in die() function This is the function where red color SHOULD be used. --- testing/scripts/function.sh | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'testing/scripts/function.sh') diff --git a/testing/scripts/function.sh b/testing/scripts/function.sh index 4ee9b24b8..a04490aec 100755 --- a/testing/scripts/function.sh +++ b/testing/scripts/function.sh @@ -41,6 +41,9 @@ execute_chroot() } export TERM=xterm +RED=$(tput setaf 1) +GREEN=$(tput setaf 2) +NORMAL=$(tput op) function cecho { echo -e "\033[1;31m$1\033[0m" @@ -64,10 +67,6 @@ log_action() # $1 - exit status of action log_status() { - RED=$(tput setaf 1) - GREEN=$(tput setaf 2) - NORMAL=$(tput op) - tput hpa 0 if [ $1 -eq 0 ]; then /bin/echo -ne "[${GREEN} ok ${NORMAL}" @@ -77,14 +76,11 @@ log_status() echo } -############################################# -# output all args to stderr and exit with -# return code 1 -# - +# exit with given error message +# $1 - error message die() { - echo $* 1>&2 - exit 1 + echo -e "${RED}$1${NORMAL}" + exit 1 } ############################################# -- cgit v1.2.3 From 7c2ef58e86c10e0cf9846dc9211cc68c7e908f7f Mon Sep 17 00:00:00 2001 From: Reto Buerki Date: Thu, 6 Dec 2012 19:03:45 +0100 Subject: Import testing.conf file in function.sh This is needed to have access to $LOGFILE and possibly other config settings. --- testing/scripts/function.sh | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'testing/scripts/function.sh') diff --git a/testing/scripts/function.sh b/testing/scripts/function.sh index a04490aec..3e0560a46 100755 --- a/testing/scripts/function.sh +++ b/testing/scripts/function.sh @@ -14,6 +14,21 @@ # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. +export TERM=xterm +RED=$(tput setaf 1) +GREEN=$(tput setaf 2) +NORMAL=$(tput op) + +# exit with given error message +# $1 - error message +die() { + echo -e "${RED}$1${NORMAL}" + exit 1 +} + +[ -f testing.conf ] || die "Configuration file 'testing.conf' not found" +. testing.conf + # execute command # $1 - command to execute # $2 - whether or not to log command exit status @@ -40,11 +55,6 @@ execute_chroot() execute "chroot $LOOPDIR $@" } -export TERM=xterm -RED=$(tput setaf 1) -GREEN=$(tput setaf 2) -NORMAL=$(tput op) - function cecho { echo -e "\033[1;31m$1\033[0m" } @@ -76,13 +86,6 @@ log_status() echo } -# exit with given error message -# $1 - error message -die() { - echo -e "${RED}$1${NORMAL}" - exit 1 -} - ############################################# # search and replace strings throughout a # whole directory -- cgit v1.2.3 From 9a045eef8e003b46fb93369a7888d65b01730a1d Mon Sep 17 00:00:00 2001 From: Reto Buerki Date: Thu, 6 Dec 2012 19:17:30 +0100 Subject: Provide do_on_exit() function This function allows to register an exit action which executes when the calling script terminates. --- testing/scripts/function.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'testing/scripts/function.sh') diff --git a/testing/scripts/function.sh b/testing/scripts/function.sh index 3e0560a46..d9f2054ef 100755 --- a/testing/scripts/function.sh +++ b/testing/scripts/function.sh @@ -86,6 +86,34 @@ log_status() echo } +# the following two functions are stolen from [1] +# [1] - http://www.linuxjournal.com/content/use-bash-trap-statement-cleanup-temporary-files + +declare -a on_exit_items + +# perform registered actions on exit +on_exit() +{ + for i in "${on_exit_items[@]}" + do + eval $i >>$LOGFILE 2>&1 + done + on_exit_items="" + trap - EXIT +} + +# register a command to execute when the calling script terminates. The +# registered commands are called in FIFO order. +# $* - command to register +do_on_exit() +{ + local n=${#on_exit_items[*]} + on_exit_items[$n]="$*" + if [ $n -eq 0 ]; then + trap on_exit EXIT + fi +} + ############################################# # search and replace strings throughout a # whole directory -- cgit v1.2.3 From 8cb4628ff95bf2afbe10668f6725cc2265a292a9 Mon Sep 17 00:00:00 2001 From: Reto Buerki Date: Fri, 7 Dec 2012 12:31:11 +0100 Subject: Use log_action function in do-tests script --- testing/scripts/function.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'testing/scripts/function.sh') diff --git a/testing/scripts/function.sh b/testing/scripts/function.sh index d9f2054ef..b510d755c 100755 --- a/testing/scripts/function.sh +++ b/testing/scripts/function.sh @@ -55,6 +55,20 @@ execute_chroot() execute "chroot $LOOPDIR $@" } +# write green status message to console +# $1 - msg +echo_ok() +{ + echo -e "${GREEN}$1${NORMAL}" +} + +# write red status message to console +# $1 - msg +echo_failed() +{ + echo -e "${RED}$1${NORMAL}" +} + function cecho { echo -e "\033[1;31m$1\033[0m" } -- cgit v1.2.3 From 36a3fe90d88a53ba5c4f69e089697a6298527505 Mon Sep 17 00:00:00 2001 From: Reto Buerki Date: Fri, 7 Dec 2012 12:33:31 +0100 Subject: Drop cecho functions --- testing/scripts/function.sh | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'testing/scripts/function.sh') diff --git a/testing/scripts/function.sh b/testing/scripts/function.sh index b510d755c..0d4ecb484 100755 --- a/testing/scripts/function.sh +++ b/testing/scripts/function.sh @@ -69,17 +69,6 @@ echo_failed() echo -e "${RED}$1${NORMAL}" } -function cecho { - echo -e "\033[1;31m$1\033[0m" -} -function cgecho { - echo -e "\033[1;32m$1\033[0m" -} - -function cecho-n { - echo -en "\033[1;31m$1\033[0m" -} - # log an action # $1 - current action description log_action() -- cgit v1.2.3 From 8ed98c137321c3f92fb06b58e69aaecf4e531cdc Mon Sep 17 00:00:00 2001 From: Reto Buerki Date: Fri, 7 Dec 2012 17:54:19 +0100 Subject: Switch from raw images to qcow2 format This allows to use minimal copy-on-write clones of the base image as guest images, which in turn saves a lot of disk space. --- testing/scripts/function.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'testing/scripts/function.sh') diff --git a/testing/scripts/function.sh b/testing/scripts/function.sh index 0d4ecb484..d72708246 100755 --- a/testing/scripts/function.sh +++ b/testing/scripts/function.sh @@ -117,6 +117,37 @@ do_on_exit() fi } +# wait for a mount to disappear +# $1 - device/image to wait for +# $2 - maximum time to wait in seconds, default is 5 seconds +graceful_umount() +{ + secs=$2 + [ ! $secs ] && secs=5 + + let steps=$secs*100 + for i in `seq 1 $steps` + do + umount $1 >>$LOGFILE 2>&1 + mount | grep $1 >/dev/null 2>&1 + [ $? -eq 0 ] || return 0 + sleep 0.01 + done + + return 1 +} + +# load qemu NBD kernel module, if not already loaded +load_qemu_nbd() +{ + lsmod | grep ^nbd[[:space:]]* >/dev/null 2>&1 + if [ $? != 0 ] + then + log_action "Loading NBD kernel module" + execute "modprobe nbd max_part=16" + fi +} + ############################################# # search and replace strings throughout a # whole directory -- cgit v1.2.3 From b24d3ed5fc5ad891d7d210bba9b94dbe0a1468ff Mon Sep 17 00:00:00 2001 From: Reto Buerki Date: Sun, 9 Dec 2012 09:49:04 +0100 Subject: Test availability of required commands --- testing/scripts/function.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'testing/scripts/function.sh') diff --git a/testing/scripts/function.sh b/testing/scripts/function.sh index d72708246..2a801a7a5 100755 --- a/testing/scripts/function.sh +++ b/testing/scripts/function.sh @@ -148,6 +148,16 @@ load_qemu_nbd() fi } +# check if given commands exist in $PATH +# $* - commands to check +check_commands() +{ + for i in $* + do + command -v $i >/dev/null || { die "Required command $i not found"; exit 1; } + done +} + ############################################# # search and replace strings throughout a # whole directory -- cgit v1.2.3 From 74c0839ad6e0da6f299b65ed39fe2f21fa19caf9 Mon Sep 17 00:00:00 2001 From: Reto Buerki Date: Sun, 9 Dec 2012 10:50:28 +0100 Subject: Run on_exit commands in FILO order --- testing/scripts/function.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'testing/scripts/function.sh') diff --git a/testing/scripts/function.sh b/testing/scripts/function.sh index 2a801a7a5..649e32b65 100755 --- a/testing/scripts/function.sh +++ b/testing/scripts/function.sh @@ -97,16 +97,17 @@ declare -a on_exit_items # perform registered actions on exit on_exit() { - for i in "${on_exit_items[@]}" + for ((onex=${#on_exit_items[@]}-1; onex>=0; onex--)) do - eval $i >>$LOGFILE 2>&1 + echo "On_Exit: ${on_exit_items[$onex]}" >>$LOGFILE + ${on_exit_items[$onex]} >>$LOGFILE 2>&1 done on_exit_items="" trap - EXIT } # register a command to execute when the calling script terminates. The -# registered commands are called in FIFO order. +# registered commands are called in FILO order. # $* - command to register do_on_exit() { @@ -126,7 +127,7 @@ graceful_umount() [ ! $secs ] && secs=5 let steps=$secs*100 - for i in `seq 1 $steps` + for st in `seq 1 $steps` do umount $1 >>$LOGFILE 2>&1 mount | grep $1 >/dev/null 2>&1 -- cgit v1.2.3 From aba43136c262151b3f213a2253eddc62a07c7e88 Mon Sep 17 00:00:00 2001 From: Reto Buerki Date: Sun, 9 Dec 2012 21:03:29 +0100 Subject: Drop now obsolete UML helper functions --- testing/scripts/function.sh | 44 -------------------------------------------- 1 file changed, 44 deletions(-) (limited to 'testing/scripts/function.sh') diff --git a/testing/scripts/function.sh b/testing/scripts/function.sh index 649e32b65..a0afee83e 100755 --- a/testing/scripts/function.sh +++ b/testing/scripts/function.sh @@ -184,47 +184,3 @@ function searchandreplace { done } - -############################################# -# add a bridge -# - -function umlbr_add { - brctl addbr "umlbr$1" - brctl setfd "umlbr$1" 0 - brctl setageing "umlbr$1" 3600 - brctl stp "umlbr$1" off - ifconfig "umlbr$1" "$2" netmask "$3" up -} - -############################################# -# delete a bridge -# - -function umlbr_del { - ifconfig "umlbr$1" down &> /dev/null 2>&1 - brctl delbr "umlbr$1" &> /dev/null 2>&1 -} - -############################################# -# add a tap interface to a bridge -# - -function umlbr_add_tap { - tunctl -t "tap$1_$2" &> /dev/null 2>&1 - ifconfig "tap$1_$2" 0.0.0.0 promisc up &> /dev/null 2>&1 - brctl addif "umlbr$1" "tap$1_$2" &> /dev/null 2>&1 - cecho-n "$2.." - } - -############################################# -# delete a tap interface from a bridge -# - -function umlbr_del_tap { - ifconfig "umlbr$2" down &> /dev/null 2>&1 - brctl delif "umlbr$1" "tap$1_$2" &> /dev/null 2>&1 - tunctl -d "tap$1_$2" &> /dev/null 2>&1 - cecho-n "$2.." - } - -- cgit v1.2.3 From aafc0a179901c8a224e5e473cbab5f13ae7ad134 Mon Sep 17 00:00:00 2001 From: Reto Buerki Date: Tue, 18 Dec 2012 16:44:21 +0100 Subject: Make test scripts callable from any path --- testing/scripts/function.sh | 3 --- 1 file changed, 3 deletions(-) (limited to 'testing/scripts/function.sh') diff --git a/testing/scripts/function.sh b/testing/scripts/function.sh index a0afee83e..c4769678c 100755 --- a/testing/scripts/function.sh +++ b/testing/scripts/function.sh @@ -26,9 +26,6 @@ die() { exit 1 } -[ -f testing.conf ] || die "Configuration file 'testing.conf' not found" -. testing.conf - # execute command # $1 - command to execute # $2 - whether or not to log command exit status -- cgit v1.2.3