--- /dev/null
+# $Header$
+#
+# 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.
+#
+# ------------------------------------------------------------------------------
+# Definitions of functions and variables common to LB test scripts
+#
+# ping_host() - basic network ping
+# check_binaries() - check for binary executables, calls check_exec()
+# check_socket() - TCPecho to host:port
+#
+# ------------------------------------------------------------------------------
+
+# read common definitions and functions
+TEST_COMMON=test-common.sh
+if [ ! -r ${TEST_COMMON} ]; then
+ printf "Common definitions '${TEST_COMMON}' not found!\n"
+ exit 2
+fi
+source ${TEST_COMMON}
+
+
+# define variables
+GLITE_LOCATION=${GLITE_LOCATION:-/opt/glite}
+SAME_SENSOR_HOME=${SAME_SENSOR_HOME:-.}
+PATH=$GLITE_LOCATION/bin:$GLITE_LOCATION/examples:$PATH
+export PATH
+
+GRIDPROXYINFO=grid-proxy-info
+
+# binaries
+SYS_LSOF=lsof
+SYS_GREP=grep
+SYS_SED=sed
+SYS_PS=ps
+SYS_PIDOF=pidof
+SYS_APACHE=apache2
+SYS_APACHECTL=apache2ctl
+SYS_PING=ping
+SYS_AWK=awk
+SYS_ECHO=echo
+SYS_DOMAINNAME=domainname
+SYS_CURL=curl
+SYS_RM="rm -f"
+SYS_CHMOD=chmod
+SYS_CAT=cat
+SYS_NL=nl
+SYS_TAIL=tail
+SYS_DATE=date
+SYS_EXPR=expr
+SYS_BC=bc
+SYS_SCP=scp
+SYS_NC=nc
+SYS_CURL=curl
+VOMSPROXYINFO=voms-proxy-info
+
+# not used at the moment
+DEBUG=2
+
+# ping host
+function ping_host()
+{
+ if [ -z $1 ]; then
+ set_error "No host to ping"
+ return $TEST_ERROR
+ fi
+ PING_HOST=$1
+ # XXX: there might be a better way to test the network reachability
+ result=`${SYS_PING} -c 3 $PING_HOST 2>/dev/null | ${SYS_GREP} " 0% packet loss"| wc -l`
+ if [ $result -gt 0 ]; then
+ return $TEST_OK
+ else
+ return $TEST_ERROR
+ fi
+}
+
+
+# check the binaries
+function check_exec()
+{
+ if [ -z $1 ]; then
+ set_error "No binary to check"
+ return $TEST_ERROR
+ fi
+ # XXX: maybe use bash's command type?
+ local ret=`which $1 2> /dev/null`
+ if [ -n "$ret" -a -x "$ret" ]; then
+ return $TEST_OK
+ else
+ return $TEST_ERROR
+ fi
+}
+
+function check_binaries()
+{
+# TODO: test only the binaries that are needed - it can differ in each test
+ local ret=$TEST_OK
+ for file in $@
+ do
+ check_exec $file
+ if [ $? -gt 0 ]; then
+ update_error "file $file not found"
+ ret=$TEST_ERROR
+ fi
+ done
+ return $ret
+}
+
+# check socket
+function check_socket()
+{
+ if [ $# -lt 2 ]; then
+ set_error "No host:port to check"
+ return $TEST_ERROR
+ fi
+ $SYS_NC -z $1 $2 > $testerrfile
+ if [ $? -eq 0 ]; then
+ return $TEST_OK
+ else
+ return $TEST_ERROR
+ fi
+}
+
+# Check listener
+# Arguments:
+# $1: program expected to listen on the given port
+# $2: TCP port to check
+function check_listener()
+{
+ req_program=$1
+ req_port=$2
+ if [ -z $1 ]; then
+ set_error "No program name entered"
+ return $TEST_ERROR
+ fi
+
+ pid=`lsof -F p -i TCP:$req_port | sed "s/^p//"`
+ if [ -z $pid ]; then
+ return $TEST_ERROR
+ fi
+ program=`ps -p ${pid} -o args= | grep -E "[\/]*$req_program[ \t]*"`
+ if [ -z "$program" ]; then
+ return $TEST_ERROR
+ else
+ return $TEST_OK
+ fi
+}
+
+# make HTTP request using curl
+# Arguments: Options to be passed to curl, at least the URL
+# return http_code containing resulting code
+
+function call_curl()
+{
+ http_code=`curl --cert ${X509_USER_PROXY} --key ${X509_USER_PROXY} \
+ --capath ${X509_CERT_DIR} \
+ --output /dev/null --silent --write-out '%{http_code}\n' \
+ "$@"`
+}
--- /dev/null
+#!/bin/bash
+# $Id$
+
+# show help and usage
+progname=`basename $0`
+showHelp()
+{
+cat << EndHelpHeader
+Script for testing the GridSite components locally
+
+Prerequisities:
+ - Apache with the GridSite module enabled running on local machine
+
+Tests:
+ - Checks that Apache is running and listening to port 443.
+ - Checks that the GridSite module is loaded in the Apache configuration
+
+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=gridsite-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 $SYS_LSOF $SYS_GREP $SYS_SED $SYS_PS $SYS_PIDOF
+if [ $? -gt 0 ]; then
+ test_failed
+else
+ test_done
+fi
+
+# Apache running:
+printf "Testing if Apache is running"
+if [ "$(${SYS_PIDOF} ${SYS_APACHE})" ]; then
+ test_done
+else
+ test_failed
+ print_error "Apache server is not running"
+fi
+
+# GridSite module loaded:
+printf "Testing if GridSite is loaded"
+${SYS_APACHECTL} -t -D DUMP_MODULES 2>&1| grep mod_gridsite >/dev/null 2>&1
+if [ $? -eq 0 ]; then
+ test done
+else
+ test_failed
+ print_error "GridSite is not loaded in Apache"
+fi
+
+# Server listening:
+printf "Testing if Apache is listening on port 443"
+check_listener ${SYS_APACHE} 443
+if [ $? -eq 0 ]; then
+ test_done
+else
+ test_failed
+ print_error "Apache server is not listening on port 443"
+fi
+
+test_end
+} &> $logfile
+
+if [ $flag -ne 1 ]; then
+ cat $logfile
+ $SYS_RM $logfile
+fi
+exit $TEST_OK
+
--- /dev/null
+#!/bin/bash
+# $Id$
+
+# show help and usage
+progname=`basename $0`
+showHelp()
+{
+cat << EndHelpHeader
+Script for testing The GridSite components remotely
+
+Prerequisities:
+ - Apache with the GridSite module enabled running on remote machine
+
+Tests:
+ - ping_host() - network ping to Apache server host
+ - check_socket() - simple tcp echo to port 443 of the host
+
+Returned values:
+ Exit TEST_OK: Test Passed
+ Exit TEST_ERROR: Test Failed
+ Exit 2: Wrong Input
+
+EndHelpHeader
+
+ echo "Usage: $progname [OPTIONS] host"
+ 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."
+ echo ""
+ echo "where host is the Apache server host, it must be specified everytime."
+}
+if [ -z "$1" ]; then
+ showHelp
+ exit 2
+fi
+
+# read common definitions and functions
+COMMON=gridsite-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 ;;
+ *) APACHE_HOST=$1 ;;
+ 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 $SYS_NC $SYS_PING $SYS_GREP
+if [ $? -gt 0 ]; then
+ test_failed
+ print_error "Some binaries are missing"
+else
+ test_done
+fi
+
+# ping_host:
+printf "Testing ping to Apache server ${APACHE_HOST}"
+ping_host ${APACHE_HOST}
+if [ $? -gt 0 ]; then
+ test_failed
+ print_error "Destination host might be unreachable"
+else
+ test_done
+fi
+
+# check_services
+printf "Testing Apache server at ${APACHE_HOST}:443"
+check_socket ${APACHE_HOST} 443
+if [ $? -gt 0 ]; then
+ test_failed
+ print_error "Apache server at ${APACHE_HOST}:443 might be unreachable"
+else
+ test_done
+fi
+
+test_end
+} &> $logfile
+
+if [ $flag -ne 1 ]; then
+ cat $logfile
+ $SYS_RM $logfile
+fi
+exit $TEST_OK
+
--- /dev/null
+# $Header$
+#
+# 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.
+#
+# ------------------------------------------------------------------------------
+# Definition of test script return messages
+#
+# The test scripts should use the variables test_done and test_failed to
+# report whether they failed or succeeded.
+#
+# The variable test_reset is used to turn off all attributes and switch
+# to the standard character set.
+#
+# \033 ascii ESCape
+# \033[<NUM>G move to column <NUM> (linux console, xterm, not vt100)
+# \033[<NUM>C move <NUM> columns forward but only upto last column
+# \033[<NUM>D move <NUM> columns backward but only upto first column
+# \033[<NUM>A move <NUM> rows up
+# \033[<NUM>B move <NUM> rows down
+# \033[1m switch on bold
+# \033[31m switch on red
+# \033[32m switch on green
+# \033[33m switch on yellow
+# \033[m switch off color/bold
+# \017 exit alternate mode (xterm, vt100, linux console)
+# \033[10m exit alternate mode (linux console)
+# \015 carriage return (without newline)
+#
+# See also United Linux or OpenSUSE /etc/rc.status script
+#
+# ------------------------------------------------------------------------------
+
+# Do _not_ be fooled by non POSIX locale
+LC_ALL=POSIX
+export LC_ALL
+
+# Seek for terminal size and, if needed, set default size
+if [ -z "${LINES}" -o -z "${COLUMNS}" ]; then
+ stty_size=`stty size 2> /dev/null`
+ if [ $? = 0 ]; then
+ LINES=`echo ${stty_size} | awk '{print $1}'`
+ COLUMNS=`echo ${stty_size} | awk '{print $2}'`
+ else
+ LINES=24
+ if [ $LBTSTCOLS -gt 0 ]; then
+ COLUMNS=$LBTSTCOLS
+ else
+ COLUMNS=80
+ fi
+ fi
+fi
+if [ ! $LINES -ge 0 ]; then LINES=24; fi
+if [ ! $COLUMNS -ge 0 ]; then COLUMNS=80; fi
+export LINES COLUMNS
+
+# default return values
+TEST_ERROR=1
+TEST_OK=0
+
+# test error file
+testerrfile=$$.err
+
+function set_test()
+{
+test_done="${spacefill}${begin_green}done${end_green}"
+test_running="${spacefill}${begin_green}running${end_green}"
+test_failed="${spacefill}${begin_red}-TEST FAILED-${end_red}"
+test_missed="${spacefill}${begin_red}missing${end_red}"
+test_skipped="${spacefill}${begin_yellow}skipped${end_yellow}"
+test_dead="${spacefill}${begin_red}dead${end_red}"
+test_unused="${spacefill}${begin_bold}unused${end_bold}"
+test_unknown="${spacefill}${begin_yellow}unknown${end_yellow}"
+
+test_start="${spacefill}${begin_green}start${end_green}"
+test_end="${spacefill}${begin_green}end${end_green}"
+}
+
+function test_done() { printf "${test_done}${lf}"; }
+function test_running() { printf "${test_running}${lf}"; }
+function test_failed() { printf "${test_failed}${lf}"; }
+function test_missed() { printf "${test_missed}${lf}"; }
+function test_skipped() { printf "${test_skipped}${lf}"; }
+function test_dead() { printf "${test_dead}${lf}"; }
+function test_unused() { printf "${test_unused}${lf}"; }
+function test_unknown { printf "${test_unknown}${lf}"; }
+function test_start() {
+ syslog "${test_start}";
+ reset_error
+}
+function test_end() {
+ syslog "${test_end}";
+ reset_error
+}
+
+# set output to ASCII (without colors)
+function setOutputASCII()
+{
+lf="\n"
+spacefill="..."
+
+begin_bold=""
+begin_black=""
+begin_red=""
+begin_green=""
+begin_yellow=""
+begin_blue=""
+begin_magenta=""
+begin_cyan=""
+begin_white=""
+
+end_bold=""
+end_black=""
+end_red=""
+end_green=""
+end_yellow=""
+end_blue=""
+end_magenta=""
+end_cyan=""
+end_white=""
+
+set_test
+}
+
+# set output to ASCII with ANSI colors
+function setOutputColor()
+{
+local esc=`echo -en "\033"`
+local normal="${esc}[0m" # unsets color to term's fg color
+lf="\n"
+spacefill=`echo -en "\015${esc}[${COLUMNS}C${esc}[15D"`
+
+begin_bold="${esc}[0;1m"
+begin_black="${esc}[0;30m"
+begin_red="${esc}[0;31m"
+begin_green="${esc}[0;32m"
+begin_yellow="${esc}[0;33m"
+begin_blue="${esc}[0;34m"
+begin_magenta="${esc}[0;35m"
+begin_cyan="${esc}[0;36m"
+begin_white="${esc}[0;37m"
+
+end_bold="$normal"
+end_black="$normal"
+end_red="$normal"
+end_green="$normal"
+end_yellow="$normal"
+end_blue="$normal"
+end_magenta="$normal"
+end_cyan="$normal"
+end_white="$normal"
+
+set_test
+}
+
+# set output to HTML
+function setOutputHTML()
+{
+local ENDFONT="</font>"
+lf="<br />\n"
+spacefill=" "
+is_html=1
+
+begin_bold="<b>"
+begin_black="<font color=\"black\">"
+begin_red="<font color=\"red\">"
+begin_green="<font color=\"green\">"
+begin_yellow="<font color=\"yellow\">"
+begin_blue="<font color=\"blue\">"
+begin_magenta="<font color=\"magenta\">"
+begin_cyan="<font color=\"cyan\">"
+begin_white="<font color=\"white\">"
+
+end_bold="</b>"
+end_black="$ENDFONT"
+end_red="$ENDFONT"
+end_green="$ENDFONT"
+end_yellow="$ENDFONT"
+end_blue="$ENDFONT"
+end_magenta="$ENDFONT"
+end_cyan="$ENDFONT"
+end_white="$ENDFONT"
+
+set_test
+}
+
+function reset_error()
+{
+ rm -f $testerrfile
+}
+
+function set_error()
+{
+ printf "%s ${lf}" "$*" > $testerrfile
+}
+
+function update_error()
+{
+ printf "%s; " "$*" >> $testerrfile
+}
+
+function print_error()
+{
+ printf "${begin_red}Error${end_red}: %s ${lf}" "$*"
+
+ if [ -f $testerrfile ]; then
+ printf "${begin_red}Error${end_red}: %s ${lf}" "`cat $testerrfile`"
+ fi
+ reset_error
+}
+
+function print_warning()
+{
+ printf "${begin_magenta}Warning${end_magenta}: %s ${lf}" "$*"
+}
+
+function print_info()
+{
+ printf "${begin_blue}Info${end_blue}: %s ${lf}" "$*"
+}
+
+function print_newline()
+{
+ printf "${lf}"
+}
+
+function syslog()
+{
+ local tmp="`date +'%b %d %H:%M:%S'` `hostname` $progname"
+ printf "${begin_bold}${tmp}${end_bold}: %s ${lf}" "$*"
+}
+
+function dprintf()
+{
+ if [ $DEBUG -gt 0 ]; then
+ printf "%s${lf}" "$*"
+ fi
+}
+
+# by default set output to color if possible
+if test -t 1 -a "$TERM" != "raw" -a "$TERM" != "dumb" && stty size <&1 > /dev/null 2>&1 ; then
+ setOutputColor
+else
+ setOutputASCII
+fi
+