From aa590e32e045ebd8b45e5abdee765a5d519be10c Mon Sep 17 00:00:00 2001 From: karthik Date: Mar 13 2016 11:58:10 +0000 Subject: t_CheckExitStatus to have optional error message --- diff --git a/tests/0_lib/functions.sh b/tests/0_lib/functions.sh index ff87c62..b4b9e64 100755 --- a/tests/0_lib/functions.sh +++ b/tests/0_lib/functions.sh @@ -14,7 +14,9 @@ function t_CheckExitStatus { [ $1 -eq 0 ] && { t_Log "PASS"; return $PASS; } - t_Log "FAIL" + comment='' + [ "$2" ] && comment=": $2" + t_Log "FAIL" $comment exit $FAIL } diff --git a/tests/p_bzip2/10-bzip2-test.sh b/tests/p_bzip2/10-bzip2-test.sh index ef1aae8..c613599 100755 --- a/tests/p_bzip2/10-bzip2-test.sh +++ b/tests/p_bzip2/10-bzip2-test.sh @@ -18,11 +18,7 @@ bzip2 $FILE #run file through bzcat bzcat $FILE.bz2 | grep -q 'bzip2-test of single file' -if [ $? == 1 ] - then - t_Log 'bzcat failed' - exit -fi +t_CheckExitStatus $? 'bzcat failed' #run file through bunzip2 bunzip2 $FILE.bz2 diff --git a/tests/p_vconfig/10_test_vconfig.sh b/tests/p_vconfig/10_test_vconfig.sh index 900d6bb..2bb21a6 100755 --- a/tests/p_vconfig/10_test_vconfig.sh +++ b/tests/p_vconfig/10_test_vconfig.sh @@ -15,44 +15,22 @@ fi # create VLAN-IF 10 on eth0 vconfig add eth0 10 ip addr list | grep -q eth0.10 -if [ $? == 1 ] - then - t_Log "VLAN-IF creation failed" - ret_val=1 -else - t_Log "VLAN-IF successfully created" -fi +t_CheckExitStatus $? "VLAN-IF creation failed" +t_Log "VLAN-IF successfully created" #assign IP address on VLAN-IF ifconfig eth0.10 172.16.30.1 netmask 255.255.255.255 ip addr list | grep -q 172.16.30.1 -if [ $? == 1 ] - then - t_Log "IP address assignment on eth0.10 failed" - ret_val=1 -else - t_Log "IP address successfully assigned on eth0.10" -fi +t_CheckExitStatus $? "IP address assignment on eth0.10 failed" +t_Log "IP address successfully assigned on eth0.10" #testing address with ping ping -c 4 -q 172.16.30.1 | grep -q '4 received' -if [ $? == 1 ] - then - t_Log "pinging on eth0.10 failed" - ret_val=1 -else - t_Log "local ping on VLAN IF worked" -fi +t_CheckExitStatus $? "pinging on eth0.10 failed" +t_Log "local ping on VLAN IF worked" # delete VLAN-IF 10 on eth0 vconfig rem eth0.10 ip addr list | grep -q eth0.10 -if [ $? == 0 ] - then - t_Log "Removing VLAN IF failed" - ret_val=1 -else - t_Log "Removing of VLAN IF worked" -fi - -t_CheckExitStatus $ret_val +t_CheckExitStatus $? "Removing VLAN IF failed" +t_Log "Removing of VLAN IF worked" diff --git a/tests/r_lamp/50_lamp_check_mysql55.sh b/tests/r_lamp/50_lamp_check_mysql55.sh index d81edd4..1d9398c 100755 --- a/tests/r_lamp/50_lamp_check_mysql55.sh +++ b/tests/r_lamp/50_lamp_check_mysql55.sh @@ -39,14 +39,7 @@ do $SERVICE $D start &>/dev/null - RETVAL=$? - - if [ $RETVAL -ne 0 ]; then - - t_Log "FAIL: service startup for '$D' failed ($RETVAL)" - exit $FAIL - - fi + t_CheckExitStatus $? "FAIL: service startup for '$D' failed ($RETVAL)" done for D in "${DAEMONSPID[@]}" do