From 48078dd24fdf87b6524f4052694e0a6e16dc86fb Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Wed, 29 Jul 2009 18:01:07 +1000 Subject: [PATCH] Test suite: Fixes for node state parsing plus new stop/continue tests. The parsing of "ctdb status -Y" output to determine various node states was implemented very strictly. Therefore, the parsing broke due to the addition of the new "stopped" state to the output of "ctdb status -Y". This relaxes the parsing so that it should work for versions prior to the introduction of the "stopped" state, as well as future versions that add new states to the end of the list of bits in output of "ctdb status -Y". Similarly the check for cluster unhealthy (in _cluster_is_healthy()) now just checks for a single 1 in any bit in the "ctdb status -Y" output, rather than checking for a particular number of 0s. New tests tests/simple/{41_ctdb_stop.sh,42_ctdb_continue.sh,43_stop_recmaster_yield.sh} do rudimentary testing of the stop and continue functions. Remove tests tests/simple/41_ctdb_ban.sh and tests/simple/42_ctdb_unban.sh. They were both unreliable. tests/simple/21_ctdb_disablemonitor.sh now schedules a restart, since one will be required. Signed-off-by: Martin Schwenke (This used to be ctdb commit 67c5bfb5f02c9d45a32d976021ede4fb2174dfe9) --- ctdb/tests/scripts/ctdb_test_functions.bash | 22 +++-- ctdb/tests/simple/21_ctdb_disablemonitor.sh | 3 + ctdb/tests/simple/41_ctdb_ban.sh | 98 -------------------- ctdb/tests/simple/41_ctdb_stop.sh | 55 +++++++++++ ctdb/tests/simple/42_ctdb_continue.sh | 71 ++++++++++++++ ctdb/tests/simple/42_ctdb_unban.sh | 95 ------------------- ctdb/tests/simple/43_stop_recmaster_yield.sh | 54 +++++++++++ 7 files changed, 195 insertions(+), 203 deletions(-) delete mode 100755 ctdb/tests/simple/41_ctdb_ban.sh create mode 100755 ctdb/tests/simple/41_ctdb_stop.sh create mode 100755 ctdb/tests/simple/42_ctdb_continue.sh delete mode 100755 ctdb/tests/simple/42_ctdb_unban.sh create mode 100755 ctdb/tests/simple/43_stop_recmaster_yield.sh diff --git a/ctdb/tests/scripts/ctdb_test_functions.bash b/ctdb/tests/scripts/ctdb_test_functions.bash index b84fe7224ef..38324d7a9ef 100644 --- a/ctdb/tests/scripts/ctdb_test_functions.bash +++ b/ctdb/tests/scripts/ctdb_test_functions.bash @@ -326,7 +326,7 @@ _cluster_is_healthy () count=0 while read line ; do count=$(($count + 1)) - [ "${line#:*:*:}" != "0:0:0:0:" ] && return 1 + [ "${line##:*:*:*1:}" != "$line" ] && return 1 done [ $count -gt 0 ] && return $? } <<<"$out" # Yay bash! @@ -368,14 +368,16 @@ 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:?:?" ;; - (unbanned) bits="?:0:?:?" ;; - (disabled) bits="?:?:1:?" ;; - (enabled) bits="?:?:0:?" ;; + (unhealthy) bits="?:?:?:1:*" ;; + (healthy) bits="?:?:?:0:*" ;; + (disconnected) bits="1:*" ;; + (connected) bits="0:*" ;; + (banned) bits="?:1:*" ;; + (unbanned) bits="?:0:*" ;; + (disabled) bits="?:?:1:*" ;; + (enabled) bits="?:?:0:*" ;; + (stopped) bits="?:?:?:?:1:*" ;; + (notstopped) bits="?:?:?:?:0:*" ;; (frozen) fpat='^[[:space:]]+frozen[[:space:]]+1$' ;; (unfrozen) fpat='^[[:space:]]+frozen[[:space:]]+0$' ;; (monon) mpat='^Monitoring mode:ACTIVE \(0\)$' ;; @@ -393,7 +395,7 @@ node_has_status () { read x while read line ; do - [ "${line#:${pnn}:*:${bits}:}" = "" ] && return 0 + [ "${line#:${pnn}:*:${bits}}" != "$line" ] && return 0 done return 1 } <<<"$out" # Yay bash! diff --git a/ctdb/tests/simple/21_ctdb_disablemonitor.sh b/ctdb/tests/simple/21_ctdb_disablemonitor.sh index 5bf7e83650d..1797ed48d78 100755 --- a/ctdb/tests/simple/21_ctdb_disablemonitor.sh +++ b/ctdb/tests/simple/21_ctdb_disablemonitor.sh @@ -44,6 +44,9 @@ set -e cluster_is_healthy +# Reset configuration +ctdb_restart_when_done + test_node=1 # We need this for later, so we know how long to sleep. diff --git a/ctdb/tests/simple/41_ctdb_ban.sh b/ctdb/tests/simple/41_ctdb_ban.sh deleted file mode 100755 index 40cd2c1196f..00000000000 --- a/ctdb/tests/simple/41_ctdb_ban.sh +++ /dev/null @@ -1,98 +0,0 @@ -#!/bin/bash - -test_info() -{ - cat <' command. -3. Before the ban timeout expires, verify that the status of the - node changes to 'banned'. -4. Verify that the public IP addresses that were being served by - the node are failed over to one of the other nodes. -5. When the ban expires ensure that the status of the node changes - back to 'OK' and that the public IP addresses move back to the - node. - -Expected results: - -* The status of the banned nodes changes as expected and IP addresses - failover as expected. -EOF -} - -. ctdb_test_functions.bash - -ctdb_test_init "$@" - -set -e - -cluster_is_healthy - -echo "Finding out which node is the recovery master..." -try_command_on_node -v 0 "$CTDB recmaster" -recmaster=$out - -echo "Getting list of public IPs..." -try_command_on_node 0 "$CTDB ip -n all | sed -e '1d'" - -# When selecting test_node we want a node that has public IPs and that -# is not the recmaster. We pick the first one that satisfies both -# conditions. We avoid the recmaster because banning the recmaster -# (obviously) causes the recmaster to change... and changing the -# recmaster causes all nodes to become unbanned! -test_node="" - -ips="" -while read ip pnn ; do - [ -z "$test_node" -a $recmaster -ne $pnn ] && test_node=$pnn - [ "$pnn" = "$test_node" ] && ips="${ips}${ips:+ }${ip}" -done <<<"$out" # bashism to avoid problem setting variable in pipeline. - -if [ -z "$test_node" ] ; then - echo "BAD: unable to select a suitable node for banning." - exit 1 -fi - -echo "Selected node ${test_node} with IPs: $ips" - -ban_time=15 - -echo "Banning node $test_node for $ban_time seconds" -try_command_on_node 1 $CTDB ban $ban_time -n $test_node - -# Avoid a potential race condition... -onnode 0 $CTDB_TEST_WRAPPER wait_until_node_has_status $test_node banned - -if wait_until_ips_are_on_nodeglob "[!${test_node}]" $ips ; then - echo "All IPs moved." -else - echo "Some IPs didn't move." - testfailures=1 -fi - -echo "Sleeping until ban expires..." -sleep_for $ban_time - -onnode 0 $CTDB_TEST_WRAPPER wait_until_node_has_status $test_node unbanned - -# BUG: this is only guaranteed if DeterministicIPs is 1 and -# NoIPFailback is 0. -if wait_until_ips_are_on_nodeglob "$test_node" $ips ; then - echo "All IPs moved." -else - echo "Some IPs didn't move." - testfailures=1 -fi diff --git a/ctdb/tests/simple/41_ctdb_stop.sh b/ctdb/tests/simple/41_ctdb_stop.sh new file mode 100755 index 00000000000..976b88fb40c --- /dev/null +++ b/ctdb/tests/simple/41_ctdb_stop.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +test_info() +{ + cat <' command. -3. Before the ban timeout expires, verify that the status of the - node changes to 'banned'. -4. Verify that the public IP addresses that were being served by - the node are failed over to one of the other nodes. -5. Before the ban timeout expires, use 'ctdb unban' to unban the - node. -6. Verify that the status of the node changes back to 'OK' and that - the public IP addresses move back to the node. - -Expected results: - -* The 'ctdb unban' command successfully unbans a banned node. -EOF -} - -. ctdb_test_functions.bash - -ctdb_test_init "$@" - -set -e - -cluster_is_healthy - -echo "Finding out which node is the recovery master..." -try_command_on_node -v 0 "$CTDB recmaster" -recmaster=$out - -echo "Getting list of public IPs..." -try_command_on_node 0 "$CTDB ip -n all | sed -e '1d'" - -# See 41_ctdb_ban.sh for an explanation of why test_node is chosen -# like this. -test_node="" - -ips="" -while read ip pnn ; do - [ -z "$test_node" -a $recmaster -ne $pnn ] && test_node=$pnn - [ "$pnn" = "$test_node" ] && ips="${ips}${ips:+ }${ip}" -done <<<"$out" # bashism to avoid problem setting variable in pipeline. - -if [ -z "$test_node" ] ; then - echo "BAD: unable to select a suitable node for banning." - exit 1 -fi - -echo "Selected node ${test_node} with IPs: $ips" - -ban_time=60 - -echo "Banning node $test_node for $ban_time seconds" -try_command_on_node 1 $CTDB ban $ban_time -n $test_node - -# Avoid a potential race condition... -onnode 0 $CTDB_TEST_WRAPPER wait_until_node_has_status $test_node banned - -if wait_until_ips_are_on_nodeglob "[!${test_node}]" $ips ; then - echo "All IPs moved." -else - echo "Some IPs didn't move." - testfailures=1 -fi - -echo "Unbanning node $test_node" -try_command_on_node 1 $CTDB unban -n $test_node - -onnode 0 $CTDB_TEST_WRAPPER wait_until_node_has_status $test_node unbanned - -# BUG: this is only guaranteed if DeterministicIPs is 1 and -# NoIPFailback is 0. -if wait_until_ips_are_on_nodeglob "$test_node" $ips ; then - echo "All IPs moved." -else - echo "Some IPs didn't move." - testfailures=1 -fi diff --git a/ctdb/tests/simple/43_stop_recmaster_yield.sh b/ctdb/tests/simple/43_stop_recmaster_yield.sh new file mode 100755 index 00000000000..c5edc77c098 --- /dev/null +++ b/ctdb/tests/simple/43_stop_recmaster_yield.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +test_info() +{ + cat <