From f90f6e19952d58b8590fe550ecf2308bd9b065dc Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Mon, 15 Dec 2008 17:52:12 +1100 Subject: [PATCH] 3 new tests. 24_ctdb_getdbmap.sh is only 1/2 implemented but does something vaguely useful. ctdb_test_exit unsets $ctdb_test_exit_hook. Fix bug in 17_ctdb_config_delete_ip.sh. Signed-off-by: Martin Schwenke --- tests/scripts/ctdb_test_functions.bash | 1 + tests/simple/06_ctdb_getpid.sh | 2 - tests/simple/17_ctdb_config_delete_ip.sh | 2 +- tests/simple/22_ctdb_enablemonitor.sh | 101 ++++++++++++++++++++++ tests/simple/23_ctdb_moveip.sh | 103 +++++++++++++++++++++++ tests/simple/24_ctdb_getdbmap.sh | 67 +++++++++++++++ 6 files changed, 273 insertions(+), 3 deletions(-) create mode 100755 tests/simple/22_ctdb_enablemonitor.sh create mode 100755 tests/simple/23_ctdb_moveip.sh create mode 100755 tests/simple/24_ctdb_getdbmap.sh diff --git a/tests/scripts/ctdb_test_functions.bash b/tests/scripts/ctdb_test_functions.bash index 60b8e9de..b086b7fb 100644 --- a/tests/scripts/ctdb_test_functions.bash +++ b/tests/scripts/ctdb_test_functions.bash @@ -64,6 +64,7 @@ ctdb_test_exit () [ $(($testfailures+0)) -eq 0 -a $status -ne 0 ] && testfailures=$status eval "$ctdb_test_exit_hook" + unset ctdb_test_exit_hook if ! onnode 0 $CTDB_TEST_WRAPPER cluster_is_healthy ; then echo "Restarting ctdb on all nodes to get back into known state..." diff --git a/tests/simple/06_ctdb_getpid.sh b/tests/simple/06_ctdb_getpid.sh index b94aad6e..b12a2964 100755 --- a/tests/simple/06_ctdb_getpid.sh +++ b/tests/simple/06_ctdb_getpid.sh @@ -35,9 +35,7 @@ onnode 0 $CTDB_TEST_WRAPPER cluster_is_healthy # This is an attempt at being independent of the number of nodes # reported by "ctdb getpid -n all". try_command_on_node 0 "ctdb listnodes | wc -l" - num_nodes="$out" - echo "There are $num_nodes nodes..." # Call getpid a few different ways and make sure the answer is always the same. diff --git a/tests/simple/17_ctdb_config_delete_ip.sh b/tests/simple/17_ctdb_config_delete_ip.sh index ac47f631..56586492 100755 --- a/tests/simple/17_ctdb_config_delete_ip.sh +++ b/tests/simple/17_ctdb_config_delete_ip.sh @@ -47,7 +47,7 @@ num_to_remove=$(($RANDOM % $num_ips)) # Find the details in the list. i=0 -while [ $i -lt $num_to_remove ] ; do +while [ $i -le $num_to_remove ] ; do read ip_to_remove test_node i=$(($i + 1)) done <<<"$out" diff --git a/tests/simple/22_ctdb_enablemonitor.sh b/tests/simple/22_ctdb_enablemonitor.sh new file mode 100755 index 00000000..995a8ae2 --- /dev/null +++ b/tests/simple/22_ctdb_enablemonitor.sh @@ -0,0 +1,101 @@ +#!/bin/bash + +test_info() +{ + cat <. +3. Create a file called /tmp/ctdb-test-unhealthy-trigger. on the + node. +4. Verify that the status of the node does not change to unhealthy + within the interval indicated by the MonitorInterval variable, + since monitoring is disabled. +5. Now enable monitoring on the node using 'ctdb enablemonitor -n . +6. Verify that the status of the node changes to unhealthy within the + interval indicated by the MonitorInterval variable. +7. Check that the file /tmp/ctdb-test-unhealthy-detected. is + created, indicating that the event script is the reason the node + has been marked as unhealthy. + +Expected results: + +* When monitoring is enabled on a node, event scripts are executed and + status changes are monitored. +EOF +} + +. ctdb_test_functions.bash + +ctdb_test_init "$@" + +set -e + +onnode 0 $CTDB_TEST_WRAPPER cluster_is_healthy + +test_node=1 + +# We need this for later, so we know how long to sleep. +try_command_on_node -v 0 ctdb getvar MonitorInterval -n $test_node +monitor_interval="${out#*= }" +echo "Monitor interval on node $test_node is $monitor_interval seconds." + +try_command_on_node -v 0 ctdb disablemonitor -n $test_node + +sanity_check_output \ + 1 \ + '^Monitoring mode:DISABLED$' \ + "$out" + +onnode 0 $CTDB_TEST_WRAPPER wait_until_node_has_status $test_node monoff + +trigger="/tmp/ctdb-test-unhealthy-trigger.${test_node}" +detected="/tmp/ctdb-test-unhealthy-detected.${test_node}" + +recovered_flag="/tmp/ctdb-test-flag.recovered.${test_node}" +try_command_on_node $test_node touch "$recovered_flag" + +ctdb_test_exit_hook="onnode $test_node rm -vf $trigger; restart_ctdb" + +echo "Creating trigger file on node $test_node to see if it goes unhealthy..." +try_command_on_node $test_node touch "$trigger" + +sleep_for $monitor_interval + +try_command_on_node 0 $CTDB_TEST_WRAPPER node_has_status $test_node healthy + +try_command_on_node $test_node test ! -e "$detected" + +echo "OK: flag file was not created so monitoring must be disabled." + +try_command_on_node -v 0 ctdb enablemonitor -n $test_node + +sanity_check_output \ + 1 \ + '^Monitoring mode:ACTIVE$' \ + "$out" + +onnode 0 $CTDB_TEST_WRAPPER wait_until_node_has_status $test_node monon + +sleep_for $monitor_interval + +try_command_on_node $test_node test -e "$detected" + +echo "OK: flag file was created so monitoring must be enabled." + +onnode 0 $CTDB_TEST_WRAPPER wait_until_node_has_status $test_node unhealthy $monitor_interval + +try_command_on_node -v $test_node ls -l "$detected" + +echo "OK, that all worked. Expect a restart..." + +ctdb_test_exit diff --git a/tests/simple/23_ctdb_moveip.sh b/tests/simple/23_ctdb_moveip.sh new file mode 100755 index 00000000..cb775be3 --- /dev/null +++ b/tests/simple/23_ctdb_moveip.sh @@ -0,0 +1,103 @@ +#!/bin/bash + +test_info() +{ + cat </dev/null | + md5sum | + awk '{printf "%s.tdb\n", $1}' +} + +try_command_on_node -v 0 "ctdb getdbmap" +num_db_init=$(echo "$out" | sed -n -e '1s/.*://p') + +for i in $(seq 1 5) ; do + f=$(make_temp_db_filename) + echo "Attempting to create test database \"$f\"..." + try_command_on_node 0 ctdb attach "$f" + try_command_on_node 0 ctdb getdbmap + num=$(echo "$out" | sed -n -e '1s/^.*://p') + if [ $num = $(($num_db_init + $i)) ] ; then + echo "OK: seem to have the right number of databases" + else + echo "BAD: we didn't get an additional database" + exit 1 + fi + + # Add check to make sure we have the database we actually added! + # Probably do a sanity check on the overall output of getdbmap + # each time too. +done + +ctdb_test_exit -- 2.34.1