ctdb-server: Use find_public_ip_vnn() in a couple of extra places
[samba4-gss.git] / ctdb / tests / scripts / common.sh
blob5bc5869802c3b166bfa3e370bce6995f1890c58e
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
7 # without this
8 export LANG=C
10 # Print a message and exit.
11 die ()
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}"
26 ctdb_test_error ()
28 if [ $# -gt 0 ] ; then
29 echo "$*"
31 exit 99
34 ctdb_test_fail ()
36 if [ $# -gt 0 ] ; then
37 echo "$*"
39 exit 1
42 ctdb_test_skip ()
44 if [ $# -gt 0 ] ; then
45 echo "$*"
47 exit 77
50 # "$@" is supported OSes
51 ctdb_test_check_supported_OS ()
53 _os=$(uname -s)
54 for _i ; do
55 if [ "$_os" = "$_i" ] ; then
56 return
58 done
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.
66 wait_until ()
68 _timeout="$1" ; shift # "$@" is the command...
70 _interval=1
71 case "$_timeout" in
72 */*)
73 _interval="${_timeout#*/}"
74 _timeout="${_timeout%/*}"
75 esac
77 _negate=false
78 if [ "$1" = "!" ] ; then
79 _negate=true
80 shift
83 printf '<%d|' "$_timeout"
84 _t="$_timeout"
85 while [ "$_t" -gt 0 ] ; do
86 _rc=0
87 "$@" || _rc=$?
88 if { ! $_negate && [ $_rc -eq 0 ] ; } || \
89 { $_negate && [ $_rc -ne 0 ] ; } ; then
90 echo "|$((_timeout - _t))|"
91 echo "OK"
92 return 0
94 for _i in $(seq 1 "$_interval") ; do
95 printf '.'
96 done
97 _t=$((_t - _interval))
98 sleep "$_interval"
99 done
101 echo "*TIMEOUT*"
103 return 1
106 # setup_ctdb_base <parent> <subdir> [item-to-copy]...
107 setup_ctdb_base ()
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]..."
116 _parent="$1"
117 _subdir="$2"
119 # Other arguments are files/directories to copy
120 shift 2
122 export CTDB_BASE="${_parent}/${_subdir}"
123 if [ -d "$CTDB_BASE" ] ; then
124 rm -r "$CTDB_BASE"
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"
130 for _i ; do
131 cp -pr "${CTDB_SCRIPTS_BASE}/${_i}" "${CTDB_BASE}/"
132 done
134 mkdir -p "${CTDB_BASE}/events/legacy"
136 if [ -z "$CTDB_TEST_SUITE_DIR" ] ; then
137 return
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}/"
145 done