1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-08 04:58:40 +03:00

Added use of $ctdb_test_exit_hook to function ctdb_test_exit. Removed

sleeps from ban/unban tests.  Now expect "ctdb ping" to return false
if it fails, so made relevant change to 09_ctdb_ping.sh.  New
functions install_eventscript and uninstall_eventscript.  New
setup/cleanup tests 00_ctdb_install_eventscript.sh and
99_ctdb_uninstall_eventscript.sh.  New test 21_ctdb_disablemonitor.sh,
which is incredibly complex.

Signed-off-by: Martin Schwenke <martin@meltin.net>

(This used to be ctdb commit 23bffef2295772f5b795236d60b7fb6ea754b7fb)
This commit is contained in:
Martin Schwenke 2008-12-09 18:20:11 +11:00
parent 370cd5e819
commit 60f86400ac
7 changed files with 216 additions and 10 deletions

View File

@ -63,6 +63,8 @@ ctdb_test_exit ()
[ $(($testfailures+0)) -eq 0 -a $status -ne 0 ] && testfailures=$status
eval "$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..."
restart_ctdb
@ -280,6 +282,8 @@ node_has_status ()
local bits fpat mpat
case "$status" in
(unhealthy) bits="?:?:?:1" ;;
(healthy) bits="?:?:?:0" ;;
(disconnected) bits="1:?:?:?" ;;
(connected) bits="0:?:?:?" ;;
(banned) bits="?:1:?:?" ;;
@ -462,3 +466,31 @@ restart_ctdb ()
echo "ctdb is ready"
}
install_eventscript ()
{
local script_name="$1"
local script_contents="$2"
if [ -n "$CTDB_TEST_REAL_CLUSTER" ] ; 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="${CTDB_DIR}/tests/events.d/${script_name}"
echo "$script_contents" >"$f"
chmod 755 "$f"
fi
}
uninstall_eventscript ()
{
local script_name="$1"
if [ -n "$CTDB_TEST_REAL_CLUSTER" ] ; then
onnode all "rm -vf \"\${CTDB_BASE:-/etc/ctdb}/events.d/${script_name}\""
else
rm -vf "${CTDB_DIR}/tests/events.d/${script_name}"
fi
}

View File

@ -0,0 +1,58 @@
#!/bin/bash
test_info()
{
cat <<EOF
Install an event script on all nodes that helps detect ctdb events.
We could install separate scripts for particular events later as
needed. However, the script installed here will allow detection of
all events. It also allows a file to be created to indicate that a
node should be marked as unhealthy.
Prerequisites:
* Nodes must be accessible via 'onnode'.
Steps:
1. Use the install_eventscript to install the eventscript.
Expected results:
* The script is successfully installed on all nodes.
EOF
}
. ctdb_test_functions.bash
script='#!/bin/sh
out=$(ctdb pnn)
pnn="${out#PNN:}"
# Allow creation of flag files that are removed to confirm that events
# are taking place.
rm -f "/tmp/ctdb-test-flag.${1}.${pnn}"
# Allow creation of a trigger file to make a monitor event fail and
# force a node to be marked as unhealthy. This avoids having to look
# at log files to confirm that monitoring is working. Note that
# ${pnn} is needed in the filename if we are testing using local
# daemons so we put in there regardless.
trigger="/tmp/ctdb-test-unhealthy-trigger.${pnn}"
detected="/tmp/ctdb-test-unhealthy-detected.${pnn}"
if [ "$1" = "monitor" ] ; then
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
fi
exit 0
'
install_eventscript "00.ctdb_test_trigger" "$script"

View File

@ -46,7 +46,7 @@ try_command_on_node -v 0 'ctdb shutdown -n 2'
onnode 0 $CTDB_TEST_WRAPPER wait_until_node_has_status 2 disconnected
try_command_on_node 1 'ctdb ping -n 2'
try_command_on_node -v 1 '! ctdb ping -n 2'
sanity_check_output \
2 \

View File

@ -0,0 +1,101 @@
#!/bin/bash
test_info()
{
cat <<EOF
Verify that 'ctdb disablemonitor' works correctly.
Prerequisites:
* An active CTDB cluster with at least 2 active nodes.
* 00_ctdb_install_eventscript.sh successfully installed its event
script.
Steps:
1. Verify that the status on all of the ctdb nodes is 'OK'.
2. Create a file called /tmp/ctdb-test-unhealthy-trigger.<node> on a
node and verify that the status of the node changes to unhealthy
within the interval indicated by the MonitorInterval variable.
3. Check that the file /tmp/ctdb-test-unhealthy-detected.<node> is
created, indicating that the event script is the reason the node
has been marked as unhealthy.
4. Now disable monitoring on the node using 'ctdb disablemonitor -n <node>.
5. Verify that the message 'Monitoring mode:DISABLED' is printed.
6. Remove /tmp/ctdb-test-unhealthy-detected.<node> and ensure that it
is not recreated within the interval indicated by the
MonitorInterval variable.
7. Remove /tmp/ctdb-test-unhealthy-trigger.<node>.
8. Verify that the status of the node continues to be 'UNHEALTHY',
since monitoring has been disabled.
Expected results:
* When monitoring is disabled, event scripts are not executed and the
state of nodes is not 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."
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"
echo "Creating trigger file on node $test_node to make it unhealthy..."
try_command_on_node $test_node touch "$trigger"
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"
# Wait until recovery is complete before disabling monitoring,
# otherwise completion of the recover can turn monitoring back on!
echo "Waiting until recovery is complete..."
wait_until 30 onnode $test_node ! test -e "$recovered_flag"
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
try_command_on_node -v $test_node rm -v "$detected"
sleep_for $monitor_interval
try_command_on_node $test_node test ! -e "$detected"
echo "OK: flag file was not recreated so monitoring must be disabled."
echo "Removing trigger file. Monitoring is disabled so node will stay unhealthy."
try_command_on_node -v $test_node rm -v "$trigger"
sleep_for $monitor_interval
onnode 0 $CTDB_TEST_WRAPPER node_has_status $test_node unhealthy
echo "OK, that all worked. Expect a restart..."
ctdb_test_exit

View File

@ -81,7 +81,4 @@ else
testfailures=1
fi
echo "Sleeping to avoid potential race..."
sleep_for 3
ctdb_test_exit

View File

@ -67,9 +67,6 @@ else
testfailures=1
fi
echo "Sleeping to avoid a potential race condition..."
sleep_for 3
echo "Unbanning node 2"
try_command_on_node 1 ctdb unban -n 2
@ -84,7 +81,4 @@ else
testfailures=1
fi
echo "Sleeping to avoid potential race..."
sleep_for 3
ctdb_test_exit

View File

@ -0,0 +1,24 @@
#!/bin/bash
test_info()
{
cat <<EOF
Uninstall the event script used for testing..
Prerequisites:
* Nodes must be accessible via 'onnode'.
Steps:
1.
Expected results:
* The script is successfully uninstalled from all nodes.
EOF
}
. ctdb_test_functions.bash
uninstall_eventscript "00.ctdb_test_trigger"