A very simple test to change job ACL
authorZdeněk Šustr <sustr4@cesnet.cz>
Fri, 19 Mar 2010 15:46:22 +0000 (15:46 +0000)
committerZdeněk Šustr <sustr4@cesnet.cz>
Fri, 19 Mar 2010 15:46:22 +0000 (15:46 +0000)
org.glite.testsuites.ctb/LB/tests/lb-test-changeacl.sh [new file with mode: 0755]

diff --git a/org.glite.testsuites.ctb/LB/tests/lb-test-changeacl.sh b/org.glite.testsuites.ctb/LB/tests/lb-test-changeacl.sh
new file mode 100755 (executable)
index 0000000..f86be13
--- /dev/null
@@ -0,0 +1,165 @@
+#!/bin/bash
+#
+# Copyright (c) Members of the EGEE Collaboration. 2004-2010.
+# See http://www.eu-egee.org/partners/ for details on the copyright holders.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+#     http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# show help and usage
+progname=`basename $0`
+showHelp()
+{
+cat << EndHelpHeader
+Script for testing correct interpretation of ChangeACL events
+
+Prerequisities:
+   - LB server, logger, interlogger
+   - environment variables set:
+
+     GLITE_WMS_QUERY_SERVER
+
+Tests called:
+
+    job registration
+    sending a ChangeACL-type event
+    chcking result
+
+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 $LBLOGEVENT $LBJOBREG
+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
+
+               identity=`${GRIDPROXYINFO} | ${SYS_GREP} -E "^identity" | ${SYS_SED} "s/identity\s*:\s//"`
+
+               # Register job:
+               printf "Registering testing job "
+                jobid=`${LBJOBREG} -m ${GLITE_WMS_QUERY_SERVER} -s application | $SYS_GREP "new jobid" | ${SYS_AWK} '{ print $3 }'`
+
+               if [ -z $jobid  ]; then
+                       test_failed
+                       print_error "Failed to register job"
+               else
+                       test_done
+
+                       # Poor man solution. Dummy DN used to avoid escaping
+                       printf "Changing ACL...\n"
+                       $LBLOGEVENT -e ChangeACL -s UserInterface -p -j $jobid --user_id "ThisIsJustATestingIdentity" --user_id_type DN --permission READ --permission_type ALLOW --operation ADD > /dev/null
+
+                       sleep 10
+
+                       printf "Checking acl for new value... "
+                       $LBJOBSTATUS $jobid | grep -E "^acl :.*<auri>dn:ThisIsJustATestingIdentity</auri>" > /dev/null
+
+                       if [ "$?" = "0" ]; then
+                               test_done
+                       else
+                               printf "Not in there!"
+                                test_failed
+                                print_error "ACL not modified properly"
+                        fi
+
+                       #Purge test job
+                       joblist=$$_jobs_to_purge.txt
+                       echo $jobid > ${joblist}
+                       try_purge ${joblist}
+
+               fi
+
+               
+               
+       fi
+fi
+
+test_end
+} &> $logfile
+
+if [ $flag -ne 1 ]; then
+       cat $logfile
+       $SYS_RM $logfile
+fi
+exit $TEST_OK
+