ctdb-tests: Add local_daemons.sh option for recovery lock recheck interval
[metze/samba/wip.git] / ctdb / tests / local_daemons.sh
index 4934783ff9a863ab6956670e84897a870e174876..6ae1f1c2441801e952b71149079e49c124eb4398 100755 (executable)
@@ -13,14 +13,6 @@ export TEST_SCRIPTS_DIR="${CTDB_TEST_DIR}/scripts"
 
 . "${TEST_SCRIPTS_DIR}/common.sh"
 
-# common.sh will set TEST_SUBDIR to a stupid value when installed
-# because common.sh is usually sourced by a test.  TEST_SUBDIR needs
-# to be correctly set so setup_ctdb_base() finds the etc-ctdb/
-# subdirectory and the test event script is correctly installed, so
-# fix it.
-# shellcheck disable=SC2034
-TEST_SUBDIR="$CTDB_TEST_DIR"
-
 if ! $CTDB_TESTS_ARE_INSTALLED ; then
        hdir="$CTDB_SCRIPTS_HELPER_BINDIR"
        export CTDB_EVENTD="${hdir}/ctdb-eventd"
@@ -136,6 +128,7 @@ Options:
   -n <num>      Number of nodes (default: 3)
   -P <file>     Public addresses file (default: automatically generated)
   -R            Use a command for the recovery lock (default: use a file)
+  -r <time>     Like -R and set recheck interval to <time> (default: use a file)
   -S <library>  Socket wrapper shared library to preload (default: none)
   -6            Generate IPv6 IPs for nodes, public addresses (default: IPv4)
 EOF
@@ -150,18 +143,22 @@ local_daemons_setup ()
        _num_nodes=3
        _public_addresses_file=""
        _recovery_lock_use_command=false
+       _recovery_lock_recheck_interval=""
        _socket_wrapper=""
        _use_ipv6=false
 
        set -e
 
-       while getopts "FN:n:P:RS:6h?" _opt ; do
+       while getopts "FN:n:P:Rr:S:6h?" _opt ; do
                case "$_opt" in
                F) _disable_failover=true ;;
                N) _nodes_file="$OPTARG" ;;
                n) _num_nodes="$OPTARG" ;;
                P) _public_addresses_file="$OPTARG" ;;
                R) _recovery_lock_use_command=true ;;
+               r) _recovery_lock_use_command=true
+                  _recovery_lock_recheck_interval="$OPTARG"
+                  ;;
                S) _socket_wrapper="$OPTARG" ;;
                6) _use_ipv6=true ;;
                \?|h) local_daemons_setup_usage ;;
@@ -197,7 +194,11 @@ local_daemons_setup ()
        _recovery_lock="${directory}/rec.lock"
        if $_recovery_lock_use_command ; then
                _helper="${CTDB_SCRIPTS_HELPER_BINDIR}/ctdb_mutex_fcntl_helper"
-               _recovery_lock="! ${_helper} ${_recovery_lock}"
+               _t="! ${_helper} ${_recovery_lock}"
+               if [ -n "$_recovery_lock_recheck_interval" ] ; then
+                       _t="${_t} ${_recovery_lock_recheck_interval}"
+               fi
+               _recovery_lock="$_t"
        fi
 
        if [ -n "$_socket_wrapper" ] ; then
@@ -205,7 +206,12 @@ local_daemons_setup ()
        fi
 
        for _n in $(seq 0 $((_num_nodes - 1))) ; do
-               setup_ctdb_base "$directory" "node.${_n}" \
+               # CTDB_TEST_SUITE_DIR needs to be correctly set so
+               # setup_ctdb_base() finds the etc-ctdb/ subdirectory
+               # and the test event script is correctly installed
+               # shellcheck disable=SC2034
+               CTDB_TEST_SUITE_DIR="$CTDB_TEST_DIR" \
+                          setup_ctdb_base "$directory" "node.${_n}" \
                                functions notify.sh debug-hung-script.sh
 
                cp "$_nodes_all" "${CTDB_BASE}/nodes"
@@ -359,7 +365,7 @@ local_daemons_stop ()
 
        onnode_common
 
-       onnode -p "$_nodes" "${VALGRIND:-} ${CTDB:-ctdb} shutdown"
+       onnode -p "$_nodes" "${CTDB:-${VALGRIND:-} ctdb} shutdown"
 }
 
 local_daemons_onnode_usage ()