ctdb-tests: Add dbdir option for creating databases in fake_ctdbd
[Samba.git] / ctdb / tests / takeover_helper / scripts / local.sh
blob2bab8c7a06eafbb46faca61d75af9a4aea55830b
1 # Hey Emacs, this is a -*- shell-script -*- !!! :-)
3 # Augment PATH with stubs/ directory.
5 if "$TEST_VERBOSE" ; then
6 debug () { echo "$@" ; }
7 else
8 debug () { : ; }
9 fi
11 . "${TEST_SCRIPTS_DIR}/script_install_paths.sh"
13 PATH="$PATH:$CTDB_SCRIPTS_TOOLS_HELPER_DIR"
15 ctdbd_socket="${TEST_VAR_DIR}/ctdbd.socket.$$"
16 ctdbd_pidfile="${TEST_VAR_DIR}/ctdbd.pid.$$"
17 ctdbd_dbdir="${TEST_VAR_DIR}/ctdbd.db.$$"
19 define_test ()
21 _f=$(basename "$0" ".sh")
23 printf "%-28s - %s\n" "$_f" "$1"
25 if [ -z "$FAKE_CTDBD_DEBUGLEVEL" ] ; then
26 FAKE_CTDBD_DEBUGLEVEL="ERR"
28 if [ -z "$HELPER_DEBUGLEVEL" ] ; then
29 HELPER_DEBUGLEVEL="NOTICE"
31 if [ -z "$CTDB_DEBUGLEVEL" ] ; then
32 CTDB_DEBUGLEVEL="ERR"
36 cleanup_ctdbd ()
38 debug "Cleaning up fake ctdbd"
40 pid=$(cat "$ctdbd_pidfile" 2>/dev/null || echo)
41 if [ -n "$pid" ] ; then
42 kill $pid || true
43 rm -f "$ctdbd_pidfile"
45 rm -f "$ctdbd_socket"
46 rm -rf "$ctdbd_dbdir"
49 setup_ctdbd ()
51 debug "Setting up fake ctdbd"
53 mkdir -p "$ctdbd_dbdir"
54 $VALGRIND fake_ctdbd -d "$FAKE_CTDBD_DEBUGLEVEL" \
55 -s "$ctdbd_socket" -p "$ctdbd_pidfile" \
56 -D "$ctdbd_dbdir"
57 export CTDB_SOCKET="$ctdbd_socket"
58 # This current translates to a 6 second timeout for the
59 # important controls
60 ctdb setvar TakeoverTimeout 2
61 test_cleanup cleanup_ctdbd
64 ctdbd_getpid ()
66 cat "$ctdbd_pidfile"
69 # Render non-printable characters. The helper prints the status as
70 # binary, so render it for easy comparison.
71 result_filter ()
73 sed -e 's|ctdb-takeover\[[0-9]*\]: ||'
76 ctdb_cmd ()
78 echo Running: ctdb -d "$CTDB_DEBUGLEVEL" "$@"
79 ctdb -d "$CTDB_DEBUGLEVEL" "$@"
82 test_ctdb_ip_all ()
84 unit_test ctdb -d "$CTDB_DEBUGLEVEL" ip all || exit $?
87 takeover_helper_out="${TEST_VAR_DIR}/takover_helper.out"
89 takeover_helper_format_outfd ()
91 od -A n -t d4 "$takeover_helper_out" | sed -e 's|^[[:space:]]*||'
94 test_takeover_helper ()
97 export CTDB_DEBUGLEVEL="$HELPER_DEBUGLEVEL"
98 export CTDB_LOGGING="file:"
99 unit_test ctdb_takeover_helper 3 "$ctdbd_socket" "$@" \
100 3>"$takeover_helper_out"
101 ) || exit $?
103 case "$required_rc" in
104 255) _t="-1" ;;
105 *) _t="$required_rc" ;;
106 esac
107 ok "$_t"
109 unit_test_notrace takeover_helper_format_outfd
110 _ret=$?
111 rm "$takeover_helper_out"
112 [ $? -eq 0 ] || exit $?