From 95328f4b30101b05b9740ea8a5dd1d8cac33975f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zden=C4=9Bk=20=C5=A0ustr?= Date: Wed, 15 Apr 2009 14:39:10 +0000 Subject: [PATCH] Notification switch test -- initial (working) version. --- .../LB/tests/lb-test-notif-switch.sh | 230 +++++++++++++++++++++ 1 file changed, 230 insertions(+) create mode 100755 org.glite.testsuites.ctb/LB/tests/lb-test-notif-switch.sh diff --git a/org.glite.testsuites.ctb/LB/tests/lb-test-notif-switch.sh b/org.glite.testsuites.ctb/LB/tests/lb-test-notif-switch.sh new file mode 100755 index 0000000..f5a7871 --- /dev/null +++ b/org.glite.testsuites.ctb/LB/tests/lb-test-notif-switch.sh @@ -0,0 +1,230 @@ +#!/bin/bash + +# show help and usage +progname=`basename $0` +showHelp() +{ +cat << EndHelpHeader +Script for testing notification delivery + +Prerequisities: + - LB server + - Event logging chain + - Notification delivery chain (notification interlogger) + - environment variables set: + + GLITE_LOCATION + GLITE_WMS_QUERY_SERVER + GLITE_WMS_LOG_DESTINATION + GLITE_WMS_NOTIF_SERVER + +Tests called: + + job registration + notification registration + logging events + receiving notifications + +Returned values: + Exit TEST_OK: Test Passed + Exit TEST_ERROR: Test Failed + Exit 2: Wrong Input + +EndHelpHeader + + echo "Usage: $progname [OPTIONS]" + echo "Options:" + echo " -h | --help Show this help message." + echo " -o | --output 'file' Redirect all output to the 'file' (stdout by default)." + echo " -t | --text Format output as plain ASCII text." + echo " -c | --color Format output as text with ANSI colours (autodetected by default)." + echo " -x | --html Format output as html." +} + +# read common definitions and functions +COMMON=lb-common.sh +if [ ! -r ${COMMON} ]; then + printf "Common definitions '${COMMON}' missing!" + exit 2 +fi +source ${COMMON} + +logfile=$$.tmp +flag=0 +while test -n "$1" +do + case "$1" in + "-h" | "--help") showHelp && exit 2 ;; + "-o" | "--output") shift ; logfile=$1 flag=1 ;; + "-t" | "--text") setOutputASCII ;; + "-c" | "--color") setOutputColor ;; + "-x" | "--html") setOutputHTML ;; + esac + shift +done + +# redirecting all output to $logfile +touch $logfile +if [ ! -w $logfile ]; then + echo "Cannot write to output file $logfile" + exit $TEST_ERROR +fi + +DEBUG=2 + +## +# Starting the test +##################### + +{ +test_start + + +# check_binaries +printf "Testing if all binaries are available" +check_binaries $GRIDPROXYINFO $SYS_GREP $SYS_SED $SYS_AWK +if [ $? -gt 0 ]; then + test_failed +else + test_done +fi + +printf "Testing credentials" + +timeleft=`${GRIDPROXYINFO} | ${SYS_GREP} -E "^timeleft" | ${SYS_SED} "s/timeleft\s*:\s//"` + +if [ "$timeleft" = "" ]; then + test_failed + print_error "No credentials" +else + if [ "$timeleft" = "0:00:00" ]; then + test_failed + print_error "Credentials expired" + else + test_done + + + # Register job: + printf "Registering testing jobs" + jobid=`${LBJOBREG} -m ${GLITE_WMS_QUERY_SERVER} -s application 2>&1 | $SYS_GREP "new jobid" | ${SYS_AWK} '{ print $3 }'` + otherjobid=`${LBJOBREG} -m ${GLITE_WMS_QUERY_SERVER} -s application 2>&1 | $SYS_GREP "new jobid" | ${SYS_AWK} '{ print $3 }'` + + if [ -z $jobid ] || [ -z $otherjobid ] ; then + test_failed + print_error "Failed to register job" + else + printf "\nold: ${jobid}\nnew:$otherjobid" + test_done + fi + + # Register notification: + printf "Registering notification " + + notifid=`${LBNOTIFY} new -j ${jobid} | $SYS_GREP "notification ID" | ${SYS_AWK} '{ print $3 }'` + + if [ -z $notifid ]; then + test_failed + print_error "Failed to register notification" + else + printf "(${notifid}) " + test_done + + #Start listening for notifications + ${LBNOTIFY} receive -i 5 ${notifid} > $$_notifications.txt & + recpid=$! + + printf "Logging events resulting in RUNNING state\n" + $LB_RUNNING_SH -j ${jobid} > /dev/null 2> /dev/null + + sleep 10 + + kill $recpid + + $SYS_GREP ${jobid} $$_notifications.txt > /dev/null + + if [ $? = 0 ]; then + printf "Notifications were delivered" + test_done + else + printf "Notifications were NOT delivered" + test_failed + fi + + rm $$_notifications.txt + + printf "Changing notification ... " + $LBNOTIFY change ${notifid} ${otherjobid} + + if [ $? = 0 ]; then + printf "$LBNOTIFY change returned OK" + test_done + else + printf "Error on return from $LBNOTIFY change" + test_failed + fi + + #Start listening for notifications + ${LBNOTIFY} receive -i 5 ${notifid} > $$_notifications.txt & + recpid=$! + + printf "Logging events resulting in DONE state for both jobs\n" + $LB_DONE_SH -j ${jobid} > /dev/null 2> /dev/null + $LB_DONE_SH -j ${otherjobid} > /dev/null 2> /dev/null + + sleep 10 + + kill $recpid + + #There should be no notifications for the 1st job + $SYS_GREP ${jobid} $$_notifications.txt >> /dev/null + + if [ $? = 0 ]; then + printf "Notifications for the old job were delivered" + test_failed + else + printf "Notifications for the old job were not delivered" + test_done + fi + + #There should be notifications for the 2nd job + $SYS_GREP ${otherjobid} $$_notifications.txt >> /dev/null + + if [ $? = 0 ]; then + printf "Notifications for the new job were delivered" + test_done + else + printf "Notifications for the new job were NOT delivered" + test_failed + fi + + rm $$_notifications.txt + + #Drop notification + printf "Dropping the test notification (${notifid})" + dropresult=`${LBNOTIFY} drop ${notifid} 2>&1` + if [ -z $dropresult ]; then + test_done + else + test_failed + print_error "Failed to drop notification ${dropresult}" + fi + + #Purge test job + joblist=$$_jobs_to_purge.txt + echo $jobid > ${joblist} + echo $otherjobid >> ${joblist} + try_purge ${joblist} + + fi + fi +fi + +test_end +} &> $logfile + +if [ $flag -ne 1 ]; then + cat $logfile + rm $logfile +fi +exit $TEST_OK + -- 1.8.2.3