When running with local daemons, provided there is more than 2 of
authorMartin Schwenke <martin@meltin.net>
Sun, 7 Dec 2008 21:15:18 +0000 (08:15 +1100)
committerMartin Schwenke <martin@meltin.net>
Sun, 7 Dec 2008 21:15:18 +0000 (08:15 +1100)
them, randomly pick a single node that will not have any public IPs
assigned.  This will make life a bit more interesting and will
simulate what happens on real clusters with a management node.  Some
tests were disabling a node to implicitly trigger a ctdb restart - now
use an explicit restart of ctdb when it is required.
17_ctdb_config_delete_ip.sh now randomly chooses a public IP on any
node to disable - this works around a problem where the hardcoded node
might not have any public addresses.

Signed-off-by: Martin Schwenke <martin@meltin.net>
(This used to be ctdb commit 3d59783c0e9478f4766c380945d6200fc654f5d9)

ctdb/tests/scripts/ctdb_test_functions.bash
ctdb/tests/simple/16_ctdb_config_add_ip.sh
ctdb/tests/simple/17_ctdb_config_delete_ip.sh
ctdb/tests/simple/20_ctdb_getmonmode.sh

index 96a0f9f56e5392108ccd073f8af1b444c599fecc..08f0274f8f359e0a3b5753f6f47ca0dd6be4e754 100644 (file)
@@ -397,6 +397,11 @@ start_daemons ()
     local public_addresses=$var_dir/public_addresses.txt
     rm -f $nodes $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
+    [ $num_nodes -gt 2 ] && no_public_ips=$(($RANDOM % $num_nodes + 1))
+
     local i
     for i in $(seq 1 $num_nodes) ; do
        if [ "${CTDB_USE_IPV6}x" != "x" ]; then
@@ -404,9 +409,11 @@ start_daemons ()
            ip addr add ::$i/128 dev lo
        else
            echo 127.0.0.$i >> $nodes
-           # 2 public addresses per node, just to make things interesting.
-           echo "192.0.2.$i/24 lo" >> $public_addresses
-           echo "192.0.2.$(($i + $num_nodes))/24 lo" >> $public_addresses
+           # 2 public addresses on most nodes, just to make things interesting.
+           if [ $i -ne $no_public_ips ] ; then
+               echo "192.0.2.$i/24 lo" >> $public_addresses
+               echo "192.0.2.$(($i + $num_nodes))/24 lo" >> $public_addresses
+           fi
        fi
     done
 
index e6b8ea75c9d7982b1bc7801c2f3dc30bdec57bbe..584640b15e08a531d1c8772bbaefe5551a55f7cd 100755 (executable)
@@ -104,11 +104,13 @@ if [ -n "$add_ip" ] ; then
     echo "Waiting for IP to be added..."
     wait_until 60 ips_are_on_nodeglob $test_node $test_node_ips ${add_ip%/*}
 
-    echo "That worked!  Disabling node $test_node to force a restart..."
-    try_command_on_node $test_node ctdb disable
+    echo "That worked!"
 else
     echo "BAD: Unable to find IP address to add."
     testfailures=1
 fi
 
+echo "Restarting cluster to restore configuration..."
+restart_ctdb
+
 ctdb_test_exit
index fce137ea51ed41f2c0ad98d1a1477293b03fc9f8..ac47f6318931f79d0ad9bd5fd4b8fc130d409f13 100755 (executable)
@@ -38,28 +38,19 @@ set -e
 
 onnode 0 $CTDB_TEST_WRAPPER cluster_is_healthy
 
-test_node=1
-
-echo "Getting list of public IPs on node ${test_node}..."
-try_command_on_node $test_node 'ctdb ip -n all | sed -e "1d"'
-
-test_node_ips=""
-num_ips=0
-while read ip pnn ; do
-    if [ "$pnn" = "$test_node" ] ; then
-       test_node_ips="${test_node_ips}${test_node_ips:+ }${ip}"
-       num_ips=$(($num_ips + 1))
-    fi
-done <<<"$out" # bashism to avoid problem setting variable in pipeline.
-
-echo "Node ${test_node} has IPs: $test_node_ips"
+echo "Getting list of public IPs..."
+try_command_on_node -v 0 'ctdb ip -n all | sed -e "1d"'
 
+# Select an IP/node to remove.
+num_ips=$(echo "$out" | wc -l)
 num_to_remove=$(($RANDOM % $num_ips))
-ips=$test_node_ips
-for i in $(seq 1 $num_to_remove) ; do
-    ips="${ips#* }"
-done
-ip_to_remove="${ips%% *}"
+
+# Find the details in the list.
+i=0
+while [ $i -lt $num_to_remove ] ; do
+    read ip_to_remove test_node
+    i=$(($i + 1))
+done <<<"$out"
 
 echo "Attempting to remove ${ip_to_remove} from node ${test_node}."
 try_command_on_node $test_node ctdb delip $ip_to_remove
@@ -74,8 +65,8 @@ while read ip pnn ; do
 done <<<"$out" # bashism to avoid problem setting variable in pipeline.
 
 if [ "${test_node_ips/${ip_to_remove}}" = "$test_node_ips" ] ; then
-    echo "That worked!  Disabling node $test_node to force a restart..."
-    try_command_on_node $test_node ctdb disable
+    echo "That worked!  Restarting cluster to restore configuration..."
+    restart_ctdb
 else
     echo "BAD: The remove IP address is still there!"
     testfailures=1
index 97bcf21bc7e6330c11ba9de617f757e4507400e9..215f0cfb54a49b8b447ba4ff66b4bac531df7b03 100755 (executable)
@@ -62,8 +62,8 @@ try_command_on_node -v 0 ctdb disablemonitor -n $test_node
 
 onnode 0 $CTDB_TEST_WRAPPER wait_until_node_has_status $test_node monoff
 
-echo "That worked!  Disabling node $test_node to force a restart..."
+echo "That worked!  Restarting cluster to restore configuration..."
 
-try_command_on_node $test_node ctdb disable
+restart_ctdb
 
 ctdb_test_exit