ctdb/tests/simple: Move the local daemons code to its own file
[bbaumbach/samba-autobuild/.git] / ctdb / tests / scripts / integration.bash
index c98d5113303fb574e656fdd523e88c2438a4cd2b..0f1af3ae35b6fd20c43172c6d95c5464b65cd317 100644 (file)
@@ -2,24 +2,6 @@
 
 . "${TEST_SCRIPTS_DIR}/common.sh"
 
-# If we're not running on a real cluster then we need a local copy of
-# ctdb (and other stuff) in $PATH and we will use local daemons.
-if [ -n "$TEST_LOCAL_DAEMONS" ] ; then
-    export CTDB_NODES_SOCKETS=""
-    for i in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
-       CTDB_NODES_SOCKETS="${CTDB_NODES_SOCKETS}${CTDB_NODES_SOCKETS:+ }${TEST_VAR_DIR}/sock.${i}"
-    done
-
-    # Use in-tree binaries if running against local daemons.
-    # Otherwise CTDB need to be installed on all nodes.
-    if [ -n "$ctdb_dir" -a -d "${ctdb_dir}/bin" ] ; then
-       PATH="${ctdb_dir}/bin:${PATH}"
-        export CTDB_LOCK_HELPER="${ctdb_dir}/bin/ctdb_lock_helper"
-    fi
-
-    export CTDB_NODES="${TEST_VAR_DIR}/nodes.txt"
-fi
-
 ######################################################################
 
 export CTDB_TIMEOUT=60
@@ -499,112 +481,6 @@ wait_until_node_has_some_ips ()
 
 #######################################
 
-daemons_stop ()
-{
-    echo "Attempting to politely shutdown daemons..."
-    onnode 1 $CTDB shutdown -n all || true
-
-    echo "Sleeping for a while..."
-    sleep_for 1
-
-    local pat="ctdbd --socket=${TEST_VAR_DIR}/.* --nlist .* --nopublicipcheck"
-    if pgrep -f "$pat" >/dev/null ; then
-       echo "Killing remaining daemons..."
-       pkill -f "$pat"
-
-       if pgrep -f "$pat" >/dev/null ; then
-           echo "Once more with feeling.."
-           pkill -9 -f "$pat"
-       fi
-    fi
-
-    rm -rf "${TEST_VAR_DIR}/test.db"
-}
-
-daemons_setup ()
-{
-    mkdir -p "${TEST_VAR_DIR}/test.db/persistent"
-
-    local public_addresses_all="${TEST_VAR_DIR}/public_addresses_all"
-    local no_public_addresses="${TEST_VAR_DIR}/no_public_addresses.txt"
-    rm -f $CTDB_NODES $public_addresses_all $no_public_addresses
-
-    # If there are (strictly) greater than 2 nodes then we'll randomly
-    # choose a node to have no public addresses.
-    local no_public_ips=-1
-    [ $TEST_LOCAL_DAEMONS -gt 2 ] && no_public_ips=$(($RANDOM % $TEST_LOCAL_DAEMONS))
-    echo "$no_public_ips" >$no_public_addresses
-
-    # When running certain tests we add and remove eventscripts, so we
-    # need to be able to modify the events.d/ directory.  Therefore,
-    # we use a temporary events.d/ directory under $TEST_VAR_DIR.  We
-    # copy the actual test eventscript(s) in there from the original
-    # events.d/ directory that sits alongside $TEST_SCRIPT_DIR.
-    local top=$(dirname "$TEST_SCRIPTS_DIR")
-    local events_d="${top}/events.d"
-    mkdir -p "${TEST_VAR_DIR}/events.d"
-    cp -p "${events_d}/"* "${TEST_VAR_DIR}/events.d/"
-
-    local i
-    for i in $(seq 1 $TEST_LOCAL_DAEMONS) ; do
-       if [ "${CTDB_USE_IPV6}x" != "x" ]; then
-           echo ::$i >>"$CTDB_NODES"
-           ip addr add ::$i/128 dev lo
-       else
-           echo 127.0.0.$i >>"$CTDB_NODES"
-           # 2 public addresses on most nodes, just to make things interesting.
-           if [ $(($i - 1)) -ne $no_public_ips ] ; then
-               echo "192.168.234.$i/24 lo" >>"$public_addresses_all"
-               echo "192.168.234.$(($i + $TEST_LOCAL_DAEMONS))/24 lo" >>"$public_addresses_all"
-           fi
-       fi
-    done
-}
-
-daemons_start_1 ()
-{
-    local pnn="$1"
-    shift # "$@" gets passed to ctdbd
-
-    local public_addresses_all="${TEST_VAR_DIR}/public_addresses_all"
-    local public_addresses_mine="${TEST_VAR_DIR}/public_addresses.${pnn}"
-    local no_public_addresses="${TEST_VAR_DIR}/no_public_addresses.txt"
-
-    local no_public_ips=-1
-    [ -r $no_public_addresses ] && read no_public_ips <$no_public_addresses
-
-    if  [ "$no_public_ips" = $pnn ] ; then
-       echo "Node $no_public_ips will have no public IPs."
-    fi
-
-    local node_ip=$(sed -n -e "$(($pnn + 1))p" "$CTDB_NODES")
-    local ctdb_options="--sloppy-start --reclock=${TEST_VAR_DIR}/rec.lock --nlist $CTDB_NODES --nopublicipcheck --listen=${node_ip} --event-script-dir=${TEST_VAR_DIR}/events.d --logfile=${TEST_VAR_DIR}/daemon.${pnn}.log -d 3 --log-ringbuf-size=10000 --dbdir=${TEST_VAR_DIR}/test.db --dbdir-persistent=${TEST_VAR_DIR}/test.db/persistent --dbdir-state=${TEST_VAR_DIR}/test.db/state"
-
-    if [ $pnn -eq $no_public_ips ] ; then
-       ctdb_options="$ctdb_options --public-addresses=/dev/null"
-    else
-       cp "$public_addresses_all" "$public_addresses_mine"
-       ctdb_options="$ctdb_options --public-addresses=$public_addresses_mine"
-    fi
-
-    # We'll use "pkill -f" to kill the daemons with
-    # "--socket=.* --nlist .* --nopublicipcheck" as context.
-    $VALGRIND ctdbd --socket="${TEST_VAR_DIR}/sock.$pnn" $ctdb_options "$@" ||return 1
-}
-
-daemons_start ()
-{
-    # "$@" gets passed to ctdbd
-
-    echo "Starting $TEST_LOCAL_DAEMONS ctdb daemons..."
-
-    for i in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
-       daemons_start_1 $i "$@"
-    done
-}
-
-#######################################
-
 _ctdb_hack_options ()
 {
     local ctdb_options="$*"
@@ -767,165 +643,30 @@ get_ctdbd_command_line_option ()
 
 #######################################
 
-install_eventscript ()
-{
-    local script_name="$1"
-    local script_contents="$2"
-
-    if [ -z "$TEST_LOCAL_DAEMONS" ] ; then
-       # The quoting here is *very* fragile.  However, we do
-       # experience the joy of installing a short script using
-       # onnode, and without needing to know the IP addresses of the
-       # nodes.
-       onnode all "f=\"\${CTDB_BASE:-/etc/ctdb}/events.d/${script_name}\" ; echo \"Installing \$f\" ; echo '${script_contents}' > \"\$f\" ; chmod 755 \"\$f\""
-    else
-       f="${TEST_VAR_DIR}/events.d/${script_name}"
-       echo "$script_contents" >"$f"
-       chmod 755 "$f"
-    fi
-}
-
-uninstall_eventscript ()
-{
-    local script_name="$1"
-
-    if [ -z "$TEST_LOCAL_DAEMONS" ] ; then
-       onnode all "rm -vf \"\${CTDB_BASE:-/etc/ctdb}/events.d/${script_name}\""
-    else
-       rm -vf "${TEST_VAR_DIR}/events.d/${script_name}"
-    fi
-}
-
-#######################################
-
-# This section deals with the 99.ctdb_test eventscript.
-
-# Metafunctions: Handle a ctdb-test file on a node.
-# given event.
-ctdb_test_eventscript_file_create ()
-{
-    local pnn="$1"
-    local type="$2"
-
-    try_command_on_node $pnn touch "/tmp/ctdb-test-${type}.${pnn}"
-}
-
-ctdb_test_eventscript_file_remove ()
-{
-    local pnn="$1"
-    local type="$2"
-
-    try_command_on_node $pnn rm -f "/tmp/ctdb-test-${type}.${pnn}"
-}
-
-ctdb_test_eventscript_file_exists ()
+wait_for_monitor_event ()
 {
     local pnn="$1"
-    local type="$2"
-
-    try_command_on_node $pnn test -f "/tmp/ctdb-test-${type}.${pnn}" >/dev/null 2>&1
-}
-
-
-# Handle a flag file on a node that is removed by 99.ctdb_test on the
-# given event.
-ctdb_test_eventscript_flag ()
-{
-    local cmd="$1"
-    local pnn="$2"
-    local event="$3"
-
-    ctdb_test_eventscript_file_${cmd} "$pnn" "flag-${event}"
-}
-
+    local timeout=120
 
-# Handle a trigger that causes 99.ctdb_test to fail it's monitor
-# event.
-ctdb_test_eventscript_unhealthy_trigger ()
-{
-    local cmd="$1"
-    local pnn="$2"
-
-    ctdb_test_eventscript_file_${cmd} "$pnn" "unhealthy-trigger"
-}
-
-# Handle the file that 99.ctdb_test created to show that it has marked
-# a node unhealthy because it detected the above trigger.
-ctdb_test_eventscript_unhealthy_detected ()
-{
-    local cmd="$1"
-    local pnn="$2"
-
-    ctdb_test_eventscript_file_${cmd} "$pnn" "unhealthy-detected"
-}
-
-# Handle a trigger that causes 99.ctdb_test to timeout it's monitor
-# event.  This should cause the node to be banned.
-ctdb_test_eventscript_timeout_trigger ()
-{
-    local cmd="$1"
-    local pnn="$2"
-    local event="$3"
-
-    ctdb_test_eventscript_file_${cmd} "$pnn" "${event}-timeout"
-}
-
-# Note that the eventscript can't use the above functions!
-ctdb_test_eventscript_install ()
-{
-
-    local script='#!/bin/sh
-out=$(ctdb pnn)
-pnn="${out#PNN:}"
-
-rm -vf "/tmp/ctdb-test-flag-${1}.${pnn}"
-
-trigger="/tmp/ctdb-test-unhealthy-trigger.${pnn}"
-detected="/tmp/ctdb-test-unhealthy-detected.${pnn}"
-timeout_trigger="/tmp/ctdb-test-${1}-timeout.${pnn}"
-case "$1" in
-    monitor)
-        if [ -e "$trigger" ] ; then
-            echo "${0}: Unhealthy because \"$trigger\" detected"
-            touch "$detected"
-            exit 1
-        elif [ -e "$detected" -a ! -e "$trigger" ] ; then
-            echo "${0}: Healthy again, \"$trigger\" no longer detected"
-            rm "$detected"
-        fi
-
-       ;;
-    *)
-        if [ -e "$timeout_trigger" ] ; then
-            echo "${0}: Sleeping for a long time because \"$timeout_trigger\" detected"
-            sleep 9999
-        fi
-       ;;
-       *)
-
-esac
+    echo "Waiting for a monitor event on node ${pnn}..."
 
-exit 0
-'
-    install_eventscript "99.ctdb_test" "$script"
-}
+    try_command_on_node "$pnn" $CTDB scriptstatus || {
+       echo "Unable to get scriptstatus from node $pnn"
+       return 1
+    }
 
-ctdb_test_eventscript_uninstall ()
-{
-    uninstall_eventscript "99.ctdb_test"
+    local ctdb_scriptstatus_original="$out"
+    wait_until 120 _ctdb_scriptstatus_changed
 }
 
-# Note that this only works if you know all other monitor events will
-# succeed.  You also need to install the eventscript before using it.
-wait_for_monitor_event ()
+_ctdb_scriptstatus_changed ()
 {
-    local pnn="$1"
-
-    echo "Waiting for a monitor event on node ${pnn}..."
-    ctdb_test_eventscript_flag create $pnn "monitor"
-
-    wait_until 120 ! ctdb_test_eventscript_flag exists $pnn "monitor"
+    try_command_on_node "$pnn" $CTDB scriptstatus || {
+       echo "Unable to get scriptstatus from node $pnn"
+       return 1
+    }
 
+    [ "$out" != "$ctdb_scriptstatus_original" ]
 }
 
 #######################################