ctdb-tests: Use fake_ctdbd for ctdb tool tests instead of ctdb stub
authorAmitay Isaacs <amitay@gmail.com>
Tue, 26 Apr 2016 15:42:33 +0000 (01:42 +1000)
committerAmitay Isaacs <amitay@samba.org>
Tue, 10 May 2016 20:51:23 +0000 (22:51 +0200)
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/tests/tool/scripts/local.sh
ctdb/tests/tool/stubs/ctdb [deleted file]

index c1d6ad134011f1589c3147cd615fd7694c5c5342..89e256e840c35c2c258736f35683526df5eb1fd9 100644 (file)
@@ -2,16 +2,15 @@
 
 # Augment PATH with stubs/ directory.
 
-if [ -d "${TEST_SUBDIR}/stubs" ] ; then
-    PATH="${TEST_SUBDIR}/stubs:$PATH"
-fi
-
 if "$TEST_VERBOSE" ; then
     debug () { echo "$@" ; }
 else
     debug () { : ; }
 fi
 
+ctdbd_socket="${TEST_VAR_DIR}/ctdbd.socket.$$"
+ctdbd_pidfile="${TEST_VAR_DIR}/ctdbd.pid.$$"
+
 define_test ()
 {
     _f=$(basename "$0" ".sh")
@@ -20,7 +19,8 @@ define_test ()
        stubby.*)
            _cmd="${_f#stubby.}"
            _cmd="${_cmd%.*}" # Strip test number
-           export CTDB_TEST_PROG="ctdb_stubtest"
+           export CTDB="ctdb --socket $ctdbd_socket"
+           export CTDB_DEBUGLEVEL=3
            test_args="$_cmd"
            ;;
        *)
@@ -30,6 +30,26 @@ define_test ()
     printf "%-28s - %s\n" "$_f" "$1"
 }
 
+cleanup_ctdbd ()
+{
+       debug "Cleaning up fake ctdbd"
+
+       pid=$(cat "$ctdbd_pidfile" 2>/dev/null || echo)
+       if [ -n "$pid" ] ; then
+               kill $pid || true
+               rm -f "$ctdbd_pidfile"
+       fi
+       rm -f "$ctdbd_socket"
+}
+
+setup_ctdbd ()
+{
+       debug "Setting up fake ctdbd"
+
+       cat | fake_ctdbd -s "$ctdbd_socket" -p "$ctdbd_pidfile"
+       #test_cleanup cleanup_ctdbd
+}
+
 setup_natgw ()
 {
        debug "Setting up NAT gateway"
@@ -104,8 +124,9 @@ setup_nodes ()
 
 simple_test ()
 {
-    : ${CTDB_DEBUGLEVEL:=3}
-    export CTDB_DEBUGLEVEL
-
-    unit_test ctdb $test_args "$@"
+    setup_ctdbd
+    (unit_test $CTDB -d $CTDB_DEBUGLEVEL $test_args "$@")
+    status=$?
+    cleanup_ctdbd
+    [ $status -eq 0 ] || exit $status
 }
diff --git a/ctdb/tests/tool/stubs/ctdb b/ctdb/tests/tool/stubs/ctdb
deleted file mode 100755 (executable)
index c6e1e70..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/bin/sh
-
-# If "ctdb" is called several time in a test then it must always get
-# the same input.  So, it is read here the first time and then fed to
-# all future instances.
-if [ -z "$_CTDB_TOOL_STUB_INPUT" ] ; then
-    if ! tty -s ; then
-       _CTDB_TOOL_STUB_INPUT=$(cat)
-    else
-       _CTDB_TOOL_STUB_INPUT=""
-    fi
-    # Let's not try being subtle about whether this variable is unset
-    # or empty.  If we've been here then it is set, even if input was
-    # empty.
-    if [ -z "$_CTDB_TOOL_STUB_INPUT" ] ; then
-       _CTDB_TOOL_STUB_INPUT="@@@EMPTY@@@"
-    fi
-    export _CTDB_TOOL_STUB_INPUT
-fi
-
-if [ "$_CTDB_TOOL_STUB_INPUT" != "@@@EMPTY@@@" ] ; then
-    exec "$CTDB_TEST_PROG" "$@" <<EOF
-$_CTDB_TOOL_STUB_INPUT
-EOF
-else
-    exec "$CTDB_TEST_PROG" "$@" </dev/null
-fi