ctdb/tests/integration: Update NFS tickles test and supporting code
authorMartin Schwenke <martin@meltin.net>
Thu, 28 Nov 2013 05:43:55 +0000 (16:43 +1100)
committerMichael Adam <obnox@samba.org>
Wed, 4 Dec 2013 23:39:21 +0000 (00:39 +0100)
This currently requires an eventscript to be dynamically installed.
This eventscript is only used to help determine when a monitor event
has occurred.  This code is horrible and fragile.

A better way is to just monitor the output of "ctdb scriptstatus".
When changes it changes then a monitor event has occurred.

Also remove the old code that checks for tickle information in shared
storage.  CTDB hasn't done things this way for a long time.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Michael Adam <obnox@samba.org>
ctdb/tests/complex/31_nfs_tickle.sh
ctdb/tests/scripts/integration.bash

index ce4ae81c9d5de8f30e1ba0a9095dd0a148c8d446..b5ed47e7e8c8b6bcb2fe5d0c658c2afc180e52eb 100755 (executable)
@@ -52,11 +52,7 @@ cluster_is_healthy
 # Reset configuration
 ctdb_restart_when_done
 
-ctdb_test_exit_hook_add ctdb_test_eventscript_uninstall
-
-ctdb_test_eventscript_install
-
-# We need this for later, so we know how long to sleep.
+# We need this for later, so we know how long to run nc for.
 try_command_on_node any $CTDB getvar MonitorInterval
 monitor_interval="${out#*= }"
 #echo "Monitor interval on node $test_node is $monitor_interval seconds."
@@ -81,27 +77,7 @@ echo "Sleeping until tickles are synchronised across nodes..."
 try_command_on_node $test_node $CTDB getvar TickleUpdateInterval
 sleep_for "${out#*= }"
 
-if try_command_on_node any "test -r /etc/ctdb/events.d/61.nfstickle" ; then
-    echo "Trying to determine NFS_TICKLE_SHARED_DIRECTORY..."
-    if [ -f /etc/sysconfig/nfs ]; then
-       f="/etc/sysconfig/nfs"
-    elif [ -f /etc/default/nfs ]; then
-       f="/etc/default/nfs"
-    elif [ -f /etc/ctdb/sysconfig/nfs ]; then
-       f="/etc/ctdb/sysconfig/nfs"
-    fi
-    try_command_on_node -v any "[ -r $f ] &&  sed -n -e s@^NFS_TICKLE_SHARED_DIRECTORY=@@p $f" || true
-
-    nfs_tickle_shared_directory="${out:-/gpfs/.ctdb/nfs-tickles}"
-
-    try_command_on_node $test_node hostname
-    test_hostname=$out
-
-    try_command_on_node -v any cat "${nfs_tickle_shared_directory}/$test_hostname/$test_ip"
-else
-    echo "That's OK, we'll use \"ctdb gettickles\", which is newer..."
-    try_command_on_node -v any "ctdb -Y gettickles $test_ip $test_port"
-fi
+try_command_on_node -v any "ctdb -Y gettickles $test_ip $test_port"
 
 if [ "${out/${src_socket}/}" != "$out" ] ; then
     echo "GOOD: NFS connection tracked OK."
index c98d5113303fb574e656fdd523e88c2438a4cd2b..14beea112c4b873f7c1dc80602c567688aa7ce9d 100644 (file)
@@ -767,165 +767,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
 
+    echo "Waiting for a monitor event on node ${pnn}..."
 
-# 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
-
-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" ]
 }
 
 #######################################