1 # Hey Emacs, this is a -*- shell-script -*- !!! :-)
3 # Common variables and functions for all CTDB tests.
5 # Print a message and exit.
8 echo "$1" >&2 ; exit ${2:-1}
11 # This expands the most probable problem cases like "." and "..".
12 TEST_SUBDIR=$(dirname "$0")
13 if [ $(dirname "$TEST_SUBDIR") = "." ] ; then
14 TEST_SUBDIR=$(cd "$TEST_SUBDIR" ; pwd)
17 # If we are running from within the source tree then, depending on the
18 # tests that we're running, we may need to add the top level bin/ and
19 # tools/ subdirectories to $PATH. In this case, sanity check that
20 # run_tests.sh is in the expected place. If the tests are installed
21 # then sanity check that TEST_BIN_DIR is set.
22 if $CTDB_TESTS_ARE_INSTALLED ; then
23 if [ -z "$TEST_BIN_DIR" ] ; then
24 die "CTDB_TESTS_ARE_INSTALLED but TEST_BIN_DIR not set"
27 _test_bin_dir="$TEST_BIN_DIR"
29 if [ ! -f "${CTDB_TEST_DIR}/run_tests.sh" ] ; then
30 die "Tests not installed but can't find run_tests.sh"
33 ctdb_dir=$(dirname "$CTDB_TEST_DIR")
35 _tools_dir="${ctdb_dir}/tools"
36 if [ -d "$_tools_dir" ] ; then
37 PATH="${_tools_dir}:$PATH"
40 _test_bin_dir="${ctdb_dir}/bin"
43 case "$_test_bin_dir" in
45 *) _test_bin_dir="${PWD}/${_test_bin_dir}" ;;
47 if [ -d "$_test_bin_dir" ] ; then
48 PATH="${_test_bin_dir}:$PATH"
51 . "${TEST_SCRIPTS_DIR}/script_install_paths.sh"
53 # Wait until either timeout expires or command succeeds. The command
54 # will be tried once per second, unless timeout has format T/I, where
55 # I is the recheck interval.
58 local timeout="$1" ; shift # "$@" is the command...
63 interval="${timeout#*/}"
64 timeout="${timeout%/*}"
68 if [ "$1" = "!" ] ; then
73 echo -n "<${timeout}|"
75 while [ $t -gt 0 ] ; do
78 if { ! $negate && [ $rc -eq 0 ] ; } || \
79 { $negate && [ $rc -ne 0 ] ; } ; then
80 echo "|$(($timeout - $t))|"
85 for i in $(seq 1 $interval) ; do
97 # setup_ctdb_base <parent> <subdir> [item-to-copy]...
100 [ $# -ge 2 ] || die "usage: setup_ctdb_base <parent> <subdir> [item]..."
101 # If empty arguments are passed then we attempt to remove /
102 # (i.e. the root directory) below
103 [ -n "$1" -a -n "$2" ] || \
104 die "usage: setup_ctdb_base <parent> <subdir> [item]..."
109 # Other arguments are files/directories to copy
112 export CTDB_BASE="${_parent}/${_subdir}"
113 if [ -d "$CTDB_BASE" ] ; then
116 mkdir -p "$CTDB_BASE" || die "Failed to create CTDB_BASE=$CTDB_BASE"
117 mkdir -p "${CTDB_BASE}/run" || die "Failed to create ${CTDB_BASE}/run"
118 mkdir -p "${CTDB_BASE}/var" || die "Failed to create ${CTDB_BASE}/var"
121 cp -pr "${CTDB_SCRIPTS_BASE}/${_i}" "${CTDB_BASE}/"
124 for _i in "${TEST_SUBDIR}/etc-ctdb/"* ; do
125 # No/empty etc-ctdb directory
126 [ -e "$_i" ] || break
128 cp -pr "$_i" "${CTDB_BASE}/"