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 top_dir=$(cd -P "$ctdb_dir" && echo "$PWD") # real path
42 _test_bin_dir="${top_dir}/bin"
43 if [ ! -d "$_test_bin_dir" ] ; then
44 top_dir=$(dirname "$top_dir")
45 _test_bin_dir="${top_dir}/bin"
49 if [ -d "$_test_bin_dir" ] ; then
50 PATH="${_test_bin_dir}:$PATH"
53 . "${TEST_SCRIPTS_DIR}/script_install_paths.sh"
55 # Wait until either timeout expires or command succeeds. The command
56 # will be tried once per second, unless timeout has format T/I, where
57 # I is the recheck interval.
60 local timeout="$1" ; shift # "$@" is the command...
65 interval="${timeout#*/}"
66 timeout="${timeout%/*}"
70 if [ "$1" = "!" ] ; then
75 echo -n "<${timeout}|"
77 while [ $t -gt 0 ] ; do
80 if { ! $negate && [ $rc -eq 0 ] ; } || \
81 { $negate && [ $rc -ne 0 ] ; } ; then
82 echo "|$(($timeout - $t))|"
87 for i in $(seq 1 $interval) ; do
99 # setup_ctdb_base <parent> <subdir> [item-to-copy]...
102 [ $# -ge 2 ] || die "usage: setup_ctdb_base <parent> <subdir> [item]..."
103 # If empty arguments are passed then we attempt to remove /
104 # (i.e. the root directory) below
105 [ -n "$1" -a -n "$2" ] || \
106 die "usage: setup_ctdb_base <parent> <subdir> [item]..."
111 # Other arguments are files/directories to copy
114 export CTDB_BASE="${_parent}/${_subdir}"
115 if [ -d "$CTDB_BASE" ] ; then
118 mkdir -p "$CTDB_BASE" || die "Failed to create CTDB_BASE=$CTDB_BASE"
119 mkdir -p "${CTDB_BASE}/run" || die "Failed to create ${CTDB_BASE}/run"
120 mkdir -p "${CTDB_BASE}/var" || die "Failed to create ${CTDB_BASE}/var"
123 cp -pr "${CTDB_SCRIPTS_BASE}/${_i}" "${CTDB_BASE}/"
126 for _i in "${TEST_SUBDIR}/etc-ctdb/"* ; do
127 # No/empty etc-ctdb directory
128 [ -e "$_i" ] || break
130 cp -pr "$_i" "${CTDB_BASE}/"