1 # Hey Emacs, this is a -*- shell-script -*- !!! :-)
3 # Common variables and functions for all CTDB tests.
6 # Commands on different platforms may quote or sort things differently
10 # Print a message and exit.
13 echo "$1" >&2 ; exit "${2:-1}"
16 .
"${TEST_SCRIPTS_DIR}/script_install_paths.sh"
18 if [ -d "$CTDB_SCRIPTS_TOOLS_BIN_DIR" ] ; then
19 PATH
="${CTDB_SCRIPTS_TOOLS_BIN_DIR}:${PATH}"
22 if [ -d "$CTDB_SCRIPTS_TESTS_LIBEXEC_DIR" ] ; then
23 PATH
="${CTDB_SCRIPTS_TESTS_LIBEXEC_DIR}:${PATH}"
28 if [ $# -gt 0 ] ; then
36 if [ $# -gt 0 ] ; then
44 if [ $# -gt 0 ] ; then
50 # "$@" is supported OSes
51 ctdb_test_check_supported_OS
()
55 if [ "$_os" = "$_i" ] ; then
60 ctdb_test_skip
"This test is not supported on ${_os}"
63 # Wait until either timeout expires or command succeeds. The command
64 # will be tried once per second, unless timeout has format T/I, where
65 # I is the recheck interval.
68 _timeout
="$1" ; shift # "$@" is the command...
73 _interval
="${_timeout#*/}"
74 _timeout
="${_timeout%/*}"
78 if [ "$1" = "!" ] ; then
83 printf '<%d|' "$_timeout"
85 while [ "$_t" -gt 0 ] ; do
88 if { ! $_negate && [ $_rc -eq 0 ] ; } || \
89 { $_negate && [ $_rc -ne 0 ] ; } ; then
90 echo "|$((_timeout - _t))|"
94 for _i
in $
(seq 1 "$_interval") ; do
97 _t
=$
((_t
- _interval
))
106 # setup_ctdb_base <parent> <subdir> [item-to-copy]...
109 [ $# -ge 2 ] || die
"usage: setup_ctdb_base <parent> <subdir> [item]..."
110 # If empty arguments are passed then we attempt to remove /
111 # (i.e. the root directory) below
112 if [ -z "$1" ] ||
[ -z "$2" ] ; then
113 die
"usage: setup_ctdb_base <parent> <subdir> [item]..."
119 # Other arguments are files/directories to copy
122 export CTDB_BASE
="${_parent}/${_subdir}"
123 if [ -d "$CTDB_BASE" ] ; then
126 mkdir
-p "$CTDB_BASE" || die
"Failed to create CTDB_BASE=$CTDB_BASE"
127 mkdir
-p "${CTDB_BASE}/run" || die
"Failed to create ${CTDB_BASE}/run"
128 mkdir
-p "${CTDB_BASE}/var" || die
"Failed to create ${CTDB_BASE}/var"
131 cp -pr "${CTDB_SCRIPTS_BASE}/${_i}" "${CTDB_BASE}/"
134 mkdir
-p "${CTDB_BASE}/events/legacy"
136 if [ -z "$CTDB_TEST_SUITE_DIR" ] ; then
140 for _i
in "${CTDB_TEST_SUITE_DIR}/etc-ctdb/"* ; do
141 # No/empty etc-ctdb directory
142 [ -e "$_i" ] ||
break
144 cp -pr "$_i" "${CTDB_BASE}/"