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}"
205 echo "# ip rule show"
209 while read _p _x _i _x _t
; do
210 # Remove trailing colon after priority/preference.
212 # Only remove rules that match our priority/preference.
213 [ "$CTDB_PER_IP_ROUTING_RULE_PREF" = "$_p" ] ||
continue
215 echo "# ip route show table $_t"
216 ip route show table
"$_t"
220 # Copied from 13.per_ip_routing for now... so this is lazy testing :-(
221 ipv4_host_addr_to_net
()
226 # Convert the host address to an unsigned long by splitting out
227 # the octets and doing the math.
229 for _o
in $
(export IFS
="." ; echo $_host) ; do
230 _host_ul
=$
(( ($_host_ul << 8) + $_o)) # work around Emacs color bug
233 # Calculate the mask and apply it.
234 _mask_ul=$(( 0xffffffff << (32 - $_maskbits) ))
235 _net_ul=$(( $_host_ul & $_mask_ul ))
237 # Now convert to a network address one byte at a time.
239 for _o in $(seq 1 4) ; do
240 _net="$(($_net_ul & 255))${_net:+.}${_net}"
241 _net_ul=$(($_net_ul >> 8))
244 echo "${_net}/${_maskbits}"
247 ######################################################################
251 # Evaluate an expression that probably calls functions or uses
252 # variables from the CTDB functions file. This is used for test
257 .
"$CTDB_BASE/functions"
262 # Set output for ctdb command. Option 1st argument is return code.
265 _out
="$EVENTSCRIPTS_TESTS_VAR_DIR/ctdb.out"
268 _rc
="$EVENTSCRIPTS_TESTS_VAR_DIR/ctdb.rc"
269 echo "${1:-0}" >"$_rc"
271 eventscripts_test_add_cleanup
"rm -f $_out $_rc"
278 export FAKE_CTDB_NUMNODES
="${1:-3}"
279 echo "Setting up CTDB with ${FAKE_CTDB_NUMNODES} fake nodes"
281 export FAKE_CTDB_PNN
="${2:-0}"
282 echo "Setting up CTDB with PNN ${FAKE_CTDB_PNN}"
284 export CTDB_PUBLIC_ADDRESSES
="${CTDB_BASE}/public_addresses"
285 if [ -n "$3" ] ; then
286 echo "Setting up CTDB_PUBLIC_ADDRESSES: $3"
287 CTDB_PUBLIC_ADDRESSES
=$
(mktemp
)
291 echo "${_ip} ${_ifaces}" >>"$CTDB_PUBLIC_ADDRESSES"
293 eventscripts_test_add_cleanup
"rm -f $CTDB_PUBLIC_ADDRESSES"
296 export FAKE_CTDB_STATE
="$EVENTSCRIPTS_TESTS_VAR_DIR/fake-ctdb"
298 export FAKE_CTDB_IFACES_DOWN
="$FAKE_CTDB_STATE/ifaces-down"
299 mkdir
-p "$FAKE_CTDB_IFACES_DOWN"
300 rm -f "$FAKE_CTDB_IFACES_DOWN"/*
302 export FAKE_CTDB_SCRIPTSTATUS
="$FAKE_CTDB_STATE/scriptstatus"
303 mkdir
-p "$FAKE_CTDB_SCRIPTSTATUS"
304 rm -f "$FAKE_CTDB_SCRIPTSTATUS"/*
306 export CTDB_PARTIALLY_ONLINE_INTERFACES
313 _swap_total
="5857276"
315 if [ "$1" = "bad" ] ; then
320 _swap_free
="$_swap_total"
325 export FAKE_PROC_MEMINFO
="\
333 Active(anon): 1917580 kB
334 Inactive(anon): 523080 kB
335 Active(file): 504524 kB
336 Inactive(file): 496848 kB
339 SwapTotal: ${_swap_total} kB
340 SwapFree: ${_swap_free} kB
343 export FAKE_FREE_M
="\
344 total used free shared buffers cached
345 Mem: 3848 3634 213 0 142 ${_mem_cached}
346 -/+ buffers/cache: 2379 ${_mem_free}
349 export CTDB_MONITOR_FREE_MEMORY
350 export CTDB_MONITOR_FREE_MEMORY_WARN
351 export CTDB_CHECK_SWAP_IS_NOT_USED
354 ctdb_get_interfaces
()
356 # The echo/subshell forces all the output onto 1 line.
357 echo $
(ctdb ifaces
-Y |
awk -F: 'FNR > 1 {print $2}')
360 ctdb_get_1_interface
()
362 _t
=$
(ctdb_get_interfaces
)
366 # Print all public addresses as: interface IP maskbits
367 # Each line is suitable for passing to takeip/releaseip
368 ctdb_get_all_public_addresses
()
370 _f
="${CTDB_PUBLIC_ADDRESSES:-${CTDB_BASE}/public_addresses}"
371 while IFS
="/$IFS" read _ip _maskbits _ifaces
; do
372 echo "$_ifaces $_ip $_maskbits"
376 # Print public addresses on this node as: interface IP maskbits
377 # Each line is suitable for passing to takeip/releaseip
378 ctdb_get_my_public_addresses
()
381 read _x
# skip header line
383 while IFS
=":" read _x _ip _x _iface _x
; do
384 [ -n "$_iface" ] ||
continue
385 while IFS
="/$IFS" read _i _maskbits _x
; do
386 if [ "$_ip" = "$_i" ] ; then
387 echo $_iface $_ip $_maskbits
390 done <"${CTDB_PUBLIC_ADDRESSES:-${CTDB_BASE}/public_addresses}"
395 # Prints the 1st public address as: interface IP maskbits
396 # This is suitable for passing to takeip/releaseip
397 ctdb_get_1_public_address
()
399 ctdb_get_my_public_addresses |
{ head -n 1 ; cat >/dev
/null
; }
402 ctdb_not_implemented
()
404 export CTDB_NOT_IMPLEMENTED
="$1"
405 ctdb_not_implemented
="\
406 DEBUG: ctdb: command \"$1\" not implemented in stub"
409 ctdb_fake_scriptstatus
()
418 echo "$_code $_status $_err_out" >"$FAKE_CTDB_SCRIPTSTATUS/$script"
421 ######################################################################
423 setup_ctdb_policy_routing
()
425 service_name
="per_ip_routing"
427 export CTDB_PER_IP_ROUTING_CONF
="$CTDB_BASE/policy_routing"
428 export CTDB_PER_IP_ROUTING_RULE_PREF
=100
429 export CTDB_PER_IP_ROUTING_TABLE_ID_LOW
=1000
430 export CTDB_PER_IP_ROUTING_TABLE_ID_HIGH
=2000
432 # Tests need to create and populate this file
433 rm -f "$CTDB_PER_IP_ROUTING_CONF"
436 # Create policy routing configuration in $CTDB_PER_IP_ROUTING_CONF.
437 # $1 is the number of assigned IPs to use (<num>, all), defaulting to
438 # 1. If $2 is "default" then a default route is also added.
439 create_policy_routing_config
()
442 _should_add_default
="$2"
444 ctdb_get_my_public_addresses |
445 if [ "$_num_ips" = "all" ] ; then
448 { head -n "$_num_ips" ; cat >/dev
/null
; }
450 while read _dev _ip _bits
; do
451 _net
=$
(ipv4_host_addr_to_net
"$_ip" "$_bits")
452 _gw
="${_net%.*}.1" # a dumb, calculated default
456 if [ "$_should_add_default" = "default" ] ; then
457 echo "$_ip 0.0.0.0/0 $_gw"
459 done >"$CTDB_PER_IP_ROUTING_CONF"
462 # Check the routes against those that are expected. $1 is the number
463 # of assigned IPs to use (<num>, all), defaulting to 1. If $2 is
464 # "default" then expect default routes to have been added.
468 _should_add_default
="$2"
473 ctdb_get_my_public_addresses |
474 if [ "$_num_ips" = "all" ] ; then
477 { head -n "$_num_ips" ; cat >/dev
/null
; }
479 while read _dev _ip _bits
; do
480 _net
=$
(ipv4_host_addr_to_net
"$_ip" "$_bits")
481 _gw
="${_net%.*}.1" # a dumb, calculated default
483 _policy_rules
="${_policy_rules}
484 ${CTDB_PER_IP_ROUTING_RULE_PREF}: from $_ip lookup ctdb.$_ip "
485 _policy_routes
="${_policy_routes}
486 # ip route show table ctdb.$_ip
487 $_net dev $_dev scope link "
489 if [ "$_should_add_default" = "default" ] ; then
490 _policy_routes
="${_policy_routes}
491 default via $_gw dev $_dev "
497 0: from all lookup local ${_policy_rules}
498 32766: from all lookup main
499 32767: from all lookup default ${_policy_routes}
502 simple_test_command dump_routes
506 ######################################################################
508 # Samba/winbind fakery
516 if [ "$1" != "down" ] ; then
518 debug
"Marking Samba services as up, listening and managed by CTDB"
519 # Get into known state.
520 eventscript_call ctdb_service_managed
522 # All possible service names for all known distros.
523 for i
in "smb" "nmb" "samba" ; do
524 service
"$i" force-started
527 export CTDB_SAMBA_SKIP_SHARE_CHECK
="no"
528 export CTDB_MANAGED_SERVICES
="foo samba bar"
530 export FAKE_TCP_LISTEN
="0.0.0.0:445 0.0.0.0:139"
531 export FAKE_WBINFO_FAIL
="no"
533 # Some things in 50.samba are backgrounded and waited for. If
534 # we don't sleep at all then timeouts can happen. This avoids
536 export FAKE_SLEEP_FORCE
=0.1
538 debug
"Marking Samba services as down, not listening and not managed by CTDB"
539 # Get into known state.
540 eventscript_call ctdb_service_unmanaged
542 # All possible service names for all known distros.
543 for i
in "smb" "nmb" "samba" ; do
544 service
"$i" force-stopped
547 export CTDB_SAMBA_SKIP_SHARE_CHECK
="no"
548 export CTDB_MANAGED_SERVICES
="foo bar"
549 unset CTDB_MANAGES_SAMBA
551 export FAKE_TCP_LISTEN
=""
552 export FAKE_WBINFO_FAIL
="yes"
555 # This is ugly but if this file isn't removed before each test
556 # then configuration changes between tests don't stick.
557 rm -f "$CTDB_VARDIR/state/samba/smb.conf.cache"
564 service_name
="winbind"
566 if [ "$1" != "down" ] ; then
568 debug
"Marking Winbind service as up and managed by CTDB"
569 # Get into known state.
570 eventscript_call ctdb_service_managed
572 service
"winbind" force-started
574 export CTDB_MANAGED_SERVICES
="foo winbind bar"
576 export FAKE_WBINFO_FAIL
="no"
579 debug
"Marking Winbind service as down and not managed by CTDB"
580 # Get into known state.
581 eventscript_call ctdb_service_unmanaged
583 service
"winbind" force-stopped
585 export CTDB_MANAGED_SERVICES
="foo bar"
586 unset CTDB_MANAGES_WINBIND
588 export FAKE_WBINFO_FAIL
="yes"
594 debug
"Making wbinfo commands fail"
595 FAKE_WBINFO_FAIL
="yes"
598 ######################################################################
608 export FAKE_RPCINFO_SERVICES
=""
610 export CTDB_NFS_SKIP_SHARE_CHECK
="no"
612 export CTDB_MONITOR_NFS_THREAD_COUNT RPCNFSDCOUNT FAKE_NFSD_THREAD_PIDS
613 export CTDB_NFS_DUMP_STUCK_THREADS
615 # Reset the failcounts for nfs services.
616 eventscript_call
eval rm -f '$ctdb_fail_dir/nfs_*'
618 if [ "$1" != "down" ] ; then
619 debug
"Setting up NFS environment: all RPC services up, NFS managed by CTDB"
621 eventscript_call ctdb_service_managed
622 service
"nfs" force-started
# might not be enough
624 export CTDB_MANAGED_SERVICES
="foo nfs bar"
626 rpc_services_up
"nfs" "mountd" "rquotad" "nlockmgr" "status"
628 debug
"Setting up NFS environment: all RPC services down, NFS not managed by CTDB"
630 eventscript_call ctdb_service_unmanaged
631 service
"nfs" force-stopped
# might not be enough
632 eventscript_call startstop_nfs stop
634 export CTDB_MANAGED_SERVICES
="foo bar"
635 unset CTDB_MANAGES_NFS
642 export CTDB_NFS_SERVER_MODE
="ganesha"
643 if [ "$1" != "down" ] ; then
644 export CTDB_MANAGES_NFS
="yes"
647 # We do not support testing the Ganesha-nfsd-specific part of the
649 export CTDB_SKIP_GANESHA_NFSD_CHECK
="yes"
650 export CTDB_NFS_SKIP_SHARE_CHECK
="yes"
656 debug
"Marking RPC service \"${_i}\" as unavailable"
657 FAKE_RPCINFO_SERVICES
=$
(echo "$FAKE_RPCINFO_SERVICES" |
sed -r -e "s@[[:space:]]*${_i}:[0-9]+:[0-9]+@@g")
664 debug
"Marking RPC service \"${_i}\" as available"
669 nlockmgr
) _t
="3:4" ;;
671 *) die
"Internal error - unsupported RPC service \"${_i}\"" ;;
674 FAKE_RPCINFO_SERVICES
="${FAKE_RPCINFO_SERVICES}${FAKE_RPCINFO_SERVICES:+ }${_i}:${_t}"
678 # Set the required result for a particular RPC program having failed
679 # for a certain number of iterations. This is probably still a work
680 # in progress. Note that we could hook aggressively
681 # nfs_check_rpc_service() to try to implement this but we're better
682 # off testing nfs_check_rpc_service() using independent code... even
683 # if it is incomplete and hacky. So, if the 60.nfs eventscript
684 # changes and the tests start to fail then it may be due to this
685 # function being incomplete.
686 rpc_set_service_failure_response
()
689 # The number of failures defaults to the iteration number. This
690 # will be true when we fail from the 1st iteration... but we need
691 # the flexibility to set the number of failures.
692 _numfails
="${2:-${iteration}}"
694 _etc
="$CTDB_ETCDIR" # shortcut for readability
695 for _c
in "$_etc/sysconfig/nfs" "$_etc/default/nfs" "$_etc/ctdb/sysconfig/nfs" ; do
696 if [ -r "$_c" ] ; then
702 # A handy newline. :-)
709 _file
=$
(ls "${CTDB_BASE}/nfs-rpc-checks.d/"[0-9][0-9].
"${_progname}.check")
710 [ -r "$_file" ] || die
"RPC check file \"$_file\" does not exist or is not unique"
712 while read _op _li _actions
; do
719 if [ "$_op" != "%" ] ; then
720 if [ $_numfails $_op $_li ] ; then
724 if [ $
(($_numfails $_op $_li)) -eq 0 ] ; then
731 for _action
in $_actions ; do
737 nfsd
) _ver
=3 ; _pn
="nfs" ;;
738 lockd
) _ver
=4 ; _pn
="nlockmgr" ;;
739 statd
) _pn
="status" ;;
742 ERROR: $_pn failed RPC check:
743 rpcinfo: RPC: Program not registered
744 program $_pn version $_ver is not available"
747 _p
="rpc.${_progname}"
755 Trying to restart NFS service"
757 if [ -n "$CTDB_NFS_DUMP_STUCK_THREADS" ] ; then
758 for _pid
in $FAKE_NFSD_THREAD_PIDS ; do
761 ${_bg}Stack trace for stuck nfsd thread [${_pid}]:
762 ${_bg}[<ffffffff87654321>] fake_stack_trace_for_pid_${_pid}/stack+0x0/0xff"
768 ${_bg}Starting nfslock: OK
769 ${_bg}Starting nfs: OK"
773 Trying to restart lock manager service
774 ${_bg}Starting nfslock: OK"
777 _t
="Trying to restart $_progname [${_p}]"
779 _out
="${_out}${_out:+${_nl}}${_t}"
785 required_result
$_rc "$_out"
791 ######################################################################
797 service_name
="vsftpd"
799 if [ "$1" != "down" ] ; then
800 die
"setup_vsftpd up not implemented!!!"
802 debug
"Setting up VSFTPD environment: service down, not managed by CTDB"
804 eventscript_call ctdb_service_unmanaged
805 service vsftpd force-stopped
807 export CTDB_MANAGED_SERVICES
="foo"
808 unset CTDB_MANAGES_VSFTPD
812 ######################################################################
818 if [ "$1" != "down" ] ; then
819 die
"setup_httpd up not implemented!!!"
821 debug
"Setting up HTTPD environment: service down, not managed by CTDB"
823 for service_name
in "apache2" "httpd" ; do
824 eventscript_call ctdb_service_unmanaged
825 service
"$service_name" force-stopped
828 export CTDB_MANAGED_SERVICES
="foo"
829 unset CTDB_MANAGES_HTTPD
833 ######################################################################
843 echo "Marking ${_t} as having no active paths"
844 FAKE_MULTIPATH_FAILURES
="${FAKE_MULTIPATH_FAILURES}${FAKE_MULTIPATH+FAILURES:+ }${_t}"
849 CTDB_MONITOR_MPDEVICES
="${CTDB_MONITOR_MPDEVICES}${CTDB_MONITOR_MPDEVICES:+ }${_t}"
852 export CTDB_MONITOR_MPDEVICES FAKE_MULTIPATH_FAILURES
853 export FAKE_SLEEP_FORCE
=0.1
856 ######################################################################
858 # Result and test functions
860 # Set some globals and print the summary.
865 _f
=$
(basename "$0" ".sh")
867 # Remaining format should be NN.service.event.NNN or NN.service.NNN:
880 die
"Internal error - unknown testcase filename format"
883 printf "%-17s %-10s %-4s - %s\n\n" "$script" "$event" "$_num" "$desc"
889 CTDB_BASE="$CTDB_BASE"
890 CTDB_ETCDIR="$CTDB_ETCDIR"
891 ctdb client is "$(which ctdb)"
892 ip command is "$(which ip)"
896 # Run an eventscript once. The test passes if the return code and
897 # output match those required.
899 # Any args are passed to the eventscript.
903 [ -n "$event" ] || die
'simple_test: $event not set'
905 _extra_header
=$
(_extra_header
)
907 echo "Running eventscript \"$script $event${1:+ }$*\""
909 if $TEST_COMMAND_TRACE ; then
914 _out
=$
($_shell "${CTDB_BASE}/events.d/$script" "$event" "$@" 2>&1)
916 result_check
"$_extra_header"
921 # If something has previously failed then don't continue.
926 echo "=================================================="
930 simple_test_command
()
932 # If something has previously failed then don't continue.
936 echo "=================================================="
937 echo "Running command \"$*\""
943 check_ctdb_logfile
()
945 # If something has previously failed then don't continue.
949 echo "=================================================="
950 echo "Checking CTDB_LOGFILE=\"${CTDB_LOGFILE}\""
951 _out
=$
(cat "$CTDB_LOGFILE" 2>&1)
956 # Run an eventscript iteratively.
957 # - 1st argument is the number of iterations.
958 # - 2nd argument is something to eval to do setup for every iteration.
959 # The easiest thing to do here is to define a function and pass it
961 # - Subsequent arguments come in pairs: an iteration number and
962 # something to eval for that iteration. Each time an iteration
963 # number is matched the associated argument is given to eval after
964 # the default setup is done. The iteration numbers need to be given
965 # in ascending order.
967 # Some optional args can be given *before* these, surrounded by extra
968 # "--" args. These args are passed to the eventscript. Quoting is
971 # One use of the 2nd and further arguments is to call
972 # required_result() to change what is expected of a particular
976 [ -n "$event" ] || die
'simple_test: $event not set'
979 if [ "$1" = "--" ] ; then
981 while [ "$1" != "--" ] ; do
982 args
="${args}${args:+ }$1"
992 echo "Running $_repeats iterations of \"$script $event\" $args"
996 for iteration
in $
(seq 1 $_repeats) ; do
997 # This is inefficient because the iteration-specific setup
998 # might completely replace the default one. However, running
999 # the default is good because it allows you to revert to a
1000 # particular result without needing to specify it explicitly.
1001 eval $_setup_default
1002 if [ $iteration = "$1" ] ; then
1008 if $TEST_COMMAND_TRACE ; then
1013 _out
=$
($_shell "${CTDB_BASE}/events.d/$script" "$event" $args 2>&1)
1016 _fout
=$
(echo "$_out" | result_filter
)
1018 if [ "$_fout" = "$required_output" -a $_rc = $required_rc ] ; then
1025 result_print
"$_passed" "$_out" "$_rc" "Iteration $iteration"
1028 result_footer
"$_result" "$(_extra_header)"