1 # Hey Emacs, this is a -*- shell-script -*- !!! :-)
3 # Augment PATH with relevant stubs/ directories. We do this by actually
4 # setting PATH, and also by setting $EVENTSCRIPTS_PATH and then
5 # prepending that to $PATH in rc.local to avoid the PATH reset in
10 if [ -d "${TEST_SUBDIR}/stubs" ] ; then
11 EVENTSCRIPTS_PATH="${TEST_SUBDIR}/stubs"
14 export EVENTSCRIPTS_PATH
16 PATH="${EVENTSCRIPTS_PATH}:${PATH}"
18 export EVENTSCRIPTS_TESTS_VAR_DIR="${TEST_VAR_DIR}/unit_eventscripts"
19 if [ -d "$EVENTSCRIPTS_TESTS_VAR_DIR" -a \
20 "$EVENTSCRIPTS_TESTS_VAR_DIR" != "/unit_eventscripts" ] ; then
21 rm -r "$EVENTSCRIPTS_TESTS_VAR_DIR"
23 mkdir -p "$EVENTSCRIPTS_TESTS_VAR_DIR"
24 export CTDB_VARDIR="$EVENTSCRIPTS_TESTS_VAR_DIR/ctdb"
26 export CTDB_LOGFILE="${EVENTSCRIPTS_TESTS_VAR_DIR}/log.ctdb"
27 touch "$CTDB_LOGFILE" || die "Unable to create CTDB_LOGFILE=$CTDB_LOGFILE"
29 if [ -d "${TEST_SUBDIR}/etc" ] ; then
30 cp -a "${TEST_SUBDIR}/etc" "$EVENTSCRIPTS_TESTS_VAR_DIR"
31 export CTDB_ETCDIR="${EVENTSCRIPTS_TESTS_VAR_DIR}/etc"
33 die "Unable to setup \$CTDB_ETCDIR"
36 if [ -d "${TEST_SUBDIR}/etc-ctdb" ] ; then
37 cp -prL "${TEST_SUBDIR}/etc-ctdb" "$EVENTSCRIPTS_TESTS_VAR_DIR"
38 export CTDB_BASE="${EVENTSCRIPTS_TESTS_VAR_DIR}/etc-ctdb"
40 die "Unable to set \$CTDB_BASE"
44 if [ ! -d "${CTDB_BASE}/events.d" ] ; then
46 ERROR: Directory ${CTDB_BASE}/events.d does not exist.
48 That means that no eventscripts can be tested.
50 One possible explanation:
52 You have CTDB installed via RPMs (or similar), so the regular
53 CTDB_BASE directory is in /etc/ctdb/
57 You have done a regular "configure" and "make install" so the tests
58 are installed under /usr/local/.
60 If so, one possible hack to fix this is to create a symlink:
62 ln -s /etc/ctdb /usr/local/etc/ctdb
64 This is nasty but it works... :-)
69 ######################################################################
71 if "$TEST_VERBOSE" ; then
72 debug () { echo "$@" ; }
77 eventscripts_tests_cleanup_hooks=""
80 eventscripts_test_add_cleanup ()
82 eventscripts_tests_cleanup_hooks="${eventscripts_tests_cleanup_hooks}${eventscripts_tests_cleanup_hooks:+ ; }$*"
85 trap 'eval $eventscripts_tests_cleanup_hooks' 0
88 ######################################################################
90 # General setup fakery
94 debug "Setting up shares (3 existing shares)"
95 # Create 3 fake shares/exports.
97 for i in $(seq 1 3) ; do
98 _s="${EVENTSCRIPTS_TESTS_VAR_DIR}/shares/${i}_existing"
100 FAKE_SHARES="${FAKE_SHARES}${FAKE_SHARES:+ }${_s}"
103 export FAKE_PROC_NET_BONDING="$EVENTSCRIPTS_TESTS_VAR_DIR/proc-net-bonding"
104 mkdir -p "$FAKE_PROC_NET_BONDING"
105 rm -f "$FAKE_PROC_NET_BONDING"/*
107 export FAKE_ETHTOOL_LINK_DOWN="$EVENTSCRIPTS_TESTS_VAR_DIR/ethtool-link-down"
108 mkdir -p "$FAKE_ETHTOOL_LINK_DOWN"
109 rm -f "$FAKE_ETHTOOL_LINK_DOWN"/*
111 # This can only have 2 levels. We don't want to resort to usings
112 # something dangerous like "rm -r" setup time.
113 export FAKE_IP_STATE="$EVENTSCRIPTS_TESTS_VAR_DIR/fake-ip-state"
114 mkdir -p "$FAKE_IP_STATE"
115 rm -f "$FAKE_IP_STATE"/*/*
116 rm -f "$FAKE_IP_STATE"/* 2>/dev/null || true
117 rmdir "$FAKE_IP_STATE"/* 2>/dev/null || true
120 export CTDB_DBDIR="${EVENTSCRIPTS_TESTS_VAR_DIR}/db"
121 mkdir -p "${CTDB_DBDIR}/persistent"
123 export FAKE_TDBTOOL_SUPPORTS_CHECK="yes"
124 export FAKE_TDB_IS_OK
125 export FAKE_DATE_OUTPUT
127 export FAKE_NETSTAT_TCP_ESTABLISHED FAKE_TCP_LISTEN FAKE_NETSTAT_UNIX_LISTEN
128 export FAKE_NETSTAT_TCP_ESTABLISHED_FILE=$(mktemp --tmpdir="$EVENTSCRIPTS_TESTS_VAR_DIR")
134 debug "Marking TCP port \"${_i}\" as not listening"
135 FAKE_TCP_LISTEN=$(echo "$FAKE_TCP_LISTEN" | sed -r -e "s@[[:space:]]*[\.0-9]+:${_i}@@g")
143 # Replace some shares with non-existent ones.
148 export MISSING_SHARES_TEXT=""
149 for _i in $FAKE_SHARES ; do
150 if [ $_n = "$1" ] ; then
152 _i="${_i%_existing}_missing"
153 debug "Replacing share $_n with missing share \"$_i\""
154 rmdir "$_i" 2>/dev/null || true
155 MISSING_SHARES_TEXT="${MISSING_SHARES_TEXT}${MISSING_SHARES_TEXT:+${_nl}}"$(printf "$_fmt" "${_i}")
157 _t="${_t}${_t:+ }${_i}"
163 # Setup some fake /proc/net/bonding files with just enough info for
166 # arg1 is interface name, arg2 is currently active slave (use "None"
167 # if none), arg3 is MII status ("up" or "down").
171 _slave="${2:-${_iface}_sl_0}"
173 _mii_subs="${4:-${_mii_s:-up}}"
174 echo "Setting $_iface to be a bond with active slave $_slave and MII status $_mii_s"
175 cat >"${FAKE_PROC_NET_BONDING}/$_iface" <<EOF
176 Bonding Mode: IEEE 802.3ad Dynamic link aggregation
177 Currently Active Slave: $_slave
180 # Status of 1st pretend adapter
181 MII Status: $_mii_subs
182 # Status of 2nd pretend adapter
183 MII Status: $_mii_subs
187 ethtool_interfaces_down ()
190 echo "Marking interface $_i DOWN for ethtool"
191 touch "${FAKE_ETHTOOL_LINK_DOWN}/${_i}"
195 ethtool_interfaces_up ()
198 echo "Marking interface $_i UP for ethtool"
199 rm -f "${FAKE_ETHTOOL_LINK_DOWN}/${_i}"
203 setup_nmap_output_filter ()
205 OUT_FILTER="-e 's@^(DEBUG: # Nmap 5.21 scan initiated) .+ (as:)@\1 DATE \2@' -e 's@^(DEBUG: # Nmap done at) .+ (--)@\1 DATE \2@'"
210 echo "# ip rule show"
214 while read _p _x _i _x _t ; do
215 # Remove trailing colon after priority/preference.
217 # Only remove rules that match our priority/preference.
218 [ "$CTDB_PER_IP_ROUTING_RULE_PREF" = "$_p" ] || continue
220 echo "# ip route show table $_t"
221 ip route show table "$_t"
225 # Copied from 13.per_ip_routing for now... so this is lazy testing :-(
226 ipv4_host_addr_to_net ()
231 # Convert the host address to an unsigned long by splitting out
232 # the octets and doing the math.
234 for _o in $(export IFS="." ; echo $_host) ; do
235 _host_ul=$(( ($_host_ul << 8) + $_o)) # work around Emacs color bug
238 # Calculate the mask and apply it.
239 _mask_ul=$(( 0xffffffff << (32 - $_maskbits) ))
240 _net_ul=$(( $_host_ul & $_mask_ul ))
242 # Now convert to a network address one byte at a time.
244 for _o in $(seq 1 4) ; do
245 _net="$(($_net_ul & 255))${_net:+.}${_net}"
246 _net_ul=$(($_net_ul >> 8))
249 echo "${_net}/${_maskbits}"
252 ######################################################################
256 # Evaluate an expression that probably calls functions or uses
257 # variables from the CTDB functions file. This is used for test
262 . "$CTDB_BASE/functions"
267 # Set output for ctdb command. Option 1st argument is return code.
270 _out="$EVENTSCRIPTS_TESTS_VAR_DIR/ctdb.out"
273 _rc="$EVENTSCRIPTS_TESTS_VAR_DIR/ctdb.rc"
274 echo "${1:-0}" >"$_rc"
276 eventscripts_test_add_cleanup "rm -f $_out $_rc"
283 export FAKE_CTDB_NUMNODES="${1:-3}"
284 echo "Setting up CTDB with ${FAKE_CTDB_NUMNODES} fake nodes"
286 export FAKE_CTDB_PNN="${2:-0}"
287 echo "Setting up CTDB with PNN ${FAKE_CTDB_PNN}"
289 export CTDB_PUBLIC_ADDRESSES="${CTDB_BASE}/public_addresses"
290 if [ -n "$3" ] ; then
291 echo "Setting up CTDB_PUBLIC_ADDRESSES: $3"
292 CTDB_PUBLIC_ADDRESSES=$(mktemp)
296 echo "${_ip} ${_ifaces}" >>"$CTDB_PUBLIC_ADDRESSES"
298 eventscripts_test_add_cleanup "rm -f $CTDB_PUBLIC_ADDRESSES"
301 export FAKE_CTDB_STATE="$EVENTSCRIPTS_TESTS_VAR_DIR/fake-ctdb"
303 export FAKE_CTDB_IFACES_DOWN="$FAKE_CTDB_STATE/ifaces-down"
304 mkdir -p "$FAKE_CTDB_IFACES_DOWN"
305 rm -f "$FAKE_CTDB_IFACES_DOWN"/*
307 export FAKE_CTDB_SCRIPTSTATUS="$FAKE_CTDB_STATE/scriptstatus"
308 mkdir -p "$FAKE_CTDB_SCRIPTSTATUS"
309 rm -f "$FAKE_CTDB_SCRIPTSTATUS"/*
311 export CTDB_PARTIALLY_ONLINE_INTERFACES
314 ctdb_get_interfaces ()
316 # The echo/subshell forces all the output onto 1 line.
317 echo $(ctdb ifaces -Y | awk -F: 'FNR > 1 {print $2}')
320 ctdb_get_1_interface ()
322 _t=$(ctdb_get_interfaces)
326 # Print all public addresses as: interface IP maskbits
327 # Each line is suitable for passing to takeip/releaseip
328 ctdb_get_all_public_addresses ()
330 _f="${CTDB_PUBLIC_ADDRESSES:-${CTDB_BASE}/public_addresses}"
331 while IFS="/$IFS" read _ip _maskbits _ifaces ; do
332 echo "$_ifaces $_ip $_maskbits"
336 # Print public addresses on this node as: interface IP maskbits
337 # Each line is suitable for passing to takeip/releaseip
338 ctdb_get_my_public_addresses ()
341 read _x # skip header line
343 while IFS=":" read _x _ip _x _iface _x ; do
344 [ -n "$_iface" ] || continue
345 while IFS="/$IFS" read _i _maskbits _x ; do
346 if [ "$_ip" = "$_i" ] ; then
347 echo $_iface $_ip $_maskbits
350 done <"${CTDB_PUBLIC_ADDRESSES:-${CTDB_BASE}/public_addresses}"
355 # Prints the 1st public address as: interface IP maskbits
356 # This is suitable for passing to takeip/releaseip
357 ctdb_get_1_public_address ()
359 ctdb_get_my_public_addresses | head -n 1
362 ctdb_not_implemented ()
364 export CTDB_NOT_IMPLEMENTED="$1"
365 ctdb_not_implemented="\
366 DEBUG: ctdb: command \"$1\" not implemented in stub"
369 ctdb_fake_scriptstatus ()
378 echo "$_code $_status $_err_out" >"$FAKE_CTDB_SCRIPTSTATUS/$script"
381 ######################################################################
383 setup_ctdb_policy_routing ()
385 service_name="per_ip_routing"
387 export CTDB_PER_IP_ROUTING_CONF="$CTDB_BASE/policy_routing"
388 export CTDB_PER_IP_ROUTING_RULE_PREF=100
389 export CTDB_PER_IP_ROUTING_TABLE_ID_LOW=1000
390 export CTDB_PER_IP_ROUTING_TABLE_ID_HIGH=2000
392 # Tests need to create and populate this file
393 rm -f "$CTDB_PER_IP_ROUTING_CONF"
396 # Create policy routing configuration in $CTDB_PER_IP_ROUTING_CONF.
397 # $1 is the number of assigned IPs to use (<num>, all), defaulting to
398 # 1. If $2 is "default" then a default route is also added.
399 create_policy_routing_config ()
402 _should_add_default="$2"
404 ctdb_get_my_public_addresses |
405 if [ "$_num_ips" = "all" ] ; then
410 while read _dev _ip _bits ; do
411 _net=$(ipv4_host_addr_to_net "$_ip" "$_bits")
412 _gw="${_net%.*}.1" # a dumb, calculated default
416 if [ "$_should_add_default" = "default" ] ; then
417 echo "$_ip 0.0.0.0/0 $_gw"
419 done >"$CTDB_PER_IP_ROUTING_CONF"
422 # Check the routes against those that are expected. $1 is the number
423 # of assigned IPs to use (<num>, all), defaulting to 1. If $2 is
424 # "default" then expect default routes to have been added.
428 _should_add_default="$2"
433 ctdb_get_my_public_addresses |
434 if [ "$_num_ips" = "all" ] ; then
439 while read _dev _ip _bits ; do
440 _net=$(ipv4_host_addr_to_net "$_ip" "$_bits")
441 _gw="${_net%.*}.1" # a dumb, calculated default
443 _policy_rules="${_policy_rules}
444 ${CTDB_PER_IP_ROUTING_RULE_PREF}: from $_ip lookup ctdb.$_ip "
445 _policy_routes="${_policy_routes}
446 # ip route show table ctdb.$_ip
447 $_net dev $_dev scope link "
449 if [ "$_should_add_default" = "default" ] ; then
450 _policy_routes="${_policy_routes}
451 default via $_gw dev $_dev "
457 0: from all lookup local ${_policy_rules}
458 32766: from all lookup main
459 32767: from all lookup default ${_policy_routes}
462 simple_test_command dump_routes
466 ######################################################################
468 # Samba/winbind fakery
476 if [ "$1" != "down" ] ; then
478 debug "Marking Samba services as up, listening and managed by CTDB"
479 # Get into known state.
480 eventscript_call ctdb_service_managed
482 # All possible service names for all known distros.
483 for i in "smb" "nmb" "samba" ; do
484 service "$i" force-started
487 export CTDB_SAMBA_SKIP_SHARE_CHECK="no"
488 export CTDB_MANAGED_SERVICES="foo samba bar"
490 export FAKE_TCP_LISTEN="0.0.0.0:445 0.0.0.0:139"
491 export FAKE_WBINFO_FAIL="no"
493 # Some things in 50.samba are backgrounded and waited for. If
494 # we don't sleep at all then timeouts can happen. This avoids
496 export FAKE_SLEEP_FORCE=0.1
498 debug "Marking Samba services as down, not listening and not managed by CTDB"
499 # Get into known state.
500 eventscript_call ctdb_service_unmanaged
502 # All possible service names for all known distros.
503 for i in "smb" "nmb" "samba" ; do
504 service "$i" force-stopped
507 export CTDB_SAMBA_SKIP_SHARE_CHECK="no"
508 export CTDB_MANAGED_SERVICES="foo bar"
509 unset CTDB_MANAGES_SAMBA
511 export FAKE_TCP_LISTEN=""
512 export FAKE_WBINFO_FAIL="yes"
515 # This is ugly but if this file isn't removed before each test
516 # then configuration changes between tests don't stick.
517 rm -f "$CTDB_VARDIR/state/samba/smb.conf.cache"
524 service_name="winbind"
526 if [ "$1" != "down" ] ; then
528 debug "Marking Winbind service as up and managed by CTDB"
529 # Get into known state.
530 eventscript_call ctdb_service_managed
532 service "winbind" force-started
534 export CTDB_MANAGED_SERVICES="foo winbind bar"
536 export FAKE_WBINFO_FAIL="no"
539 debug "Marking Winbind service as down and not managed by CTDB"
540 # Get into known state.
541 eventscript_call ctdb_service_unmanaged
543 service "winbind" force-stopped
545 export CTDB_MANAGED_SERVICES="foo bar"
546 unset CTDB_MANAGES_WINBIND
548 export FAKE_WBINFO_FAIL="yes"
554 debug "Making wbinfo commands fail"
555 FAKE_WBINFO_FAIL="yes"
558 ######################################################################
568 export FAKE_RPCINFO_SERVICES=""
570 export CTDB_NFS_SKIP_SHARE_CHECK="no"
572 export CTDB_MONITOR_NFS_THREAD_COUNT RPCNFSDCOUNT FAKE_NFSD_THREAD_PIDS
573 export CTDB_NFS_DUMP_STUCK_THREADS
575 # Reset the failcounts for nfs services.
576 eventscript_call eval rm -f '$ctdb_fail_dir/nfs_*'
578 if [ "$1" != "down" ] ; then
579 debug "Setting up NFS environment: all RPC services up, NFS managed by CTDB"
581 eventscript_call ctdb_service_managed
582 service "nfs" force-started # might not be enough
584 export CTDB_MANAGED_SERVICES="foo nfs bar"
586 rpc_services_up "nfs" "mountd" "rquotad" "nlockmgr" "status"
588 debug "Setting up NFS environment: all RPC services down, NFS not managed by CTDB"
590 eventscript_call ctdb_service_unmanaged
591 service "nfs" force-stopped # might not be enough
592 eventscript_call startstop_nfs stop
594 export CTDB_MANAGED_SERVICES="foo bar"
595 unset CTDB_MANAGES_NFS
602 export NFS_SERVER_MODE="ganesha"
603 if [ "$1" != "down" ] ; then
604 export CTDB_MANAGES_NFS="yes"
607 # We do not support testing the Ganesha-nfsd-specific part of the
609 export CTDB_SKIP_GANESHA_NFSD_CHECK="yes"
610 export CTDB_NFS_SKIP_SHARE_CHECK="yes"
616 debug "Marking RPC service \"${_i}\" as unavailable"
617 FAKE_RPCINFO_SERVICES=$(echo "$FAKE_RPCINFO_SERVICES" | sed -r -e "s@[[:space:]]*${_i}:[0-9]+:[0-9]+@@g")
624 debug "Marking RPC service \"${_i}\" as available"
629 nlockmgr) _t="3:4" ;;
631 *) die "Internal error - unsupported RPC service \"${_i}\"" ;;
634 FAKE_RPCINFO_SERVICES="${FAKE_RPCINFO_SERVICES}${FAKE_RPCINFO_SERVICES:+ }${_i}:${_t}"
638 # Set the required result for a particular RPC program having failed
639 # for a certain number of iterations. This is probably still a work
640 # in progress. Note that we could hook aggressively
641 # nfs_check_rpc_service() to try to implement this but we're better
642 # off testing nfs_check_rpc_service() using independent code... even
643 # if it is incomplete and hacky. So, if the 60.nfs eventscript
644 # changes and the tests start to fail then it may be due to this
645 # function being incomplete.
646 rpc_set_service_failure_response ()
649 # The number of failures defaults to the iteration number. This
650 # will be true when we fail from the 1st iteration... but we need
651 # the flexibility to set the number of failures.
652 _numfails="${2:-${iteration}}"
654 _etc="$CTDB_ETCDIR" # shortcut for readability
655 for _c in "$_etc/sysconfig/nfs" "$_etc/default/nfs" "$_etc/ctdb/sysconfig/nfs" ; do
656 if [ -r "$_c" ] ; then
662 # A handy newline. :-)
669 _file=$(ls "${CTDB_BASE}/nfs-rpc-checks.d/"[0-9][0-9]."${_progname}.check")
670 [ -r "$_file" ] || die "RPC check file \"$_file\" does not exist or is not unique"
672 while read _op _li _actions ; do
678 if [ "$_numfails" "$_op" "$_li" ] ; then
681 for _action in $_actions ; do
687 nfsd) _ver=3 ; _pn="nfs" ;;
688 lockd) _ver=4 ; _pn="nlockmgr" ;;
689 statd) _pn="status" ;;
692 ERROR: $_pn failed RPC check:
693 rpcinfo: RPC: Program not registered
694 program $_pn version $_ver is not available"
698 _p="rpc.${_progname}"
701 _opts="${STATD_HOSTNAME:+ -n }${STATD_HOSTNAME}"
711 Trying to restart NFS service"
713 if [ -n "$CTDB_NFS_DUMP_STUCK_THREADS" ] ; then
714 for _pid in $FAKE_NFSD_THREAD_PIDS ; do
717 ${_bg}Stack trace for stuck nfsd thread [${_pid}]:
718 ${_bg}[<ffffffff87654321>] fake_stack_trace_for_pid_${_pid}/stack+0x0/0xff"
724 ${_bg}Starting nfslock: OK
725 ${_bg}Starting nfs: OK"
729 Trying to restart lock manager service
730 ${_bg}Starting nfslock: OK"
733 _t="Trying to restart $_progname [${_p}${_opts}]"
735 _out="${_out}${_out:+${_nl}}${_t}"
741 required_result $_rc "$_out"
747 ######################################################################
753 service_name="vsftpd"
755 if [ "$1" != "down" ] ; then
756 die "setup_vsftpd up not implemented!!!"
758 debug "Setting up VSFTPD environment: service down, not managed by CTDB"
760 eventscript_call ctdb_service_unmanaged
761 service vsftpd force-stopped
763 export CTDB_MANAGED_SERVICES="foo"
764 unset CTDB_MANAGES_VSFTPD
768 ######################################################################
774 if [ "$1" != "down" ] ; then
775 die "setup_httpd up not implemented!!!"
777 debug "Setting up HTTPD environment: service down, not managed by CTDB"
779 for service_name in "apache2" "httpd" ; do
780 eventscript_call ctdb_service_unmanaged
781 service "$service_name" force-stopped
784 export CTDB_MANAGED_SERVICES="foo"
785 unset CTDB_MANAGES_HTTPD
789 ######################################################################
791 # Result and test functions
793 # Set some globals and print the summary.
798 _f=$(basename "$0" ".sh")
800 # Remaining format should be NN.service.event.NNN or NN.service.NNN:
813 die "Internal error - unknown testcase filename format"
816 printf "%-17s %-10s %-4s - %s\n\n" "$script" "$event" "$_num" "$desc"
822 CTDB_BASE="$CTDB_BASE"
823 CTDB_ETCDIR="$CTDB_ETCDIR"
824 ctdb client is "$(which ctdb)"
828 # Run an eventscript once. The test passes if the return code and
829 # output match those required.
831 # Any args are passed to the eventscript.
835 [ -n "$event" ] || die 'simple_test: $event not set'
837 _extra_header=$(_extra_header)
839 echo "Running eventscript \"$script $event${1:+ }$*\""
841 if $TEST_COMMAND_TRACE ; then
844 _out=$($_trace "${CTDB_BASE}/events.d/$script" "$event" "$@" 2>&1)
846 result_check "$_extra_header"
851 # If something has previously failed then don't continue.
856 echo "=================================================="
860 simple_test_command ()
862 # If something has previously failed then don't continue.
866 echo "=================================================="
867 echo "Running command \"$*\""
873 check_ctdb_logfile ()
875 # If something has previously failed then don't continue.
879 echo "=================================================="
880 echo "Checking CTDB_LOGFILE=\"${CTDB_LOGFILE}\""
881 _out=$(cat "$CTDB_LOGFILE" 2>&1)
886 # Run an eventscript iteratively.
887 # - 1st argument is the number of iterations.
888 # - 2nd argument is something to eval to do setup for every iteration.
889 # The easiest thing to do here is to define a function and pass it
891 # - Subsequent arguments come in pairs: an iteration number and
892 # something to eval for that iteration. Each time an iteration
893 # number is matched the associated argument is given to eval after
894 # the default setup is done. The iteration numbers need to be given
895 # in ascending order.
897 # Some optional args can be given *before* these, surrounded by extra
898 # "--" args. These args are passed to the eventscript. Quoting is
901 # One use of the 2nd and further arguments is to call
902 # required_result() to change what is expected of a particular
906 [ -n "$event" ] || die 'simple_test: $event not set'
909 if [ "$1" = "--" ] ; then
911 while [ "$1" != "--" ] ; do
912 args="${args}${args:+ }$1"
922 echo "Running $_repeats iterations of \"$script $event\" $args"
926 for iteration in $(seq 1 $_repeats) ; do
927 # This is inefficient because the iteration-specific setup
928 # might completely replace the default one. However, running
929 # the default is good because it allows you to revert to a
930 # particular result without needing to specify it explicitly.
932 if [ $iteration = "$1" ] ; then
938 if $TEST_COMMAND_TRACE ; then
941 _out=$($_trace "${CTDB_BASE}/events.d/$script" "$event" $args 2>&1)
944 if [ -n "$OUT_FILTER" ] ; then
945 _fout=$(echo "$_out" | eval sed -r $OUT_FILTER)
950 if [ "$_fout" = "$required_output" -a $_rc = $required_rc ] ; then
957 result_print "$_passed" "$_out" "$_rc" "Iteration $iteration"
960 result_footer "$_result" "$(_extra_header)"