ctdb-tests: Drop use of confusing testfailures variable
authorMartin Schwenke <martin@meltin.net>
Mon, 8 Oct 2018 01:59:33 +0000 (12:59 +1100)
committerAmitay Isaacs <amitay@samba.org>
Tue, 6 Nov 2018 06:16:16 +0000 (07:16 +0100)
Exit on first test failure instead of setting a variable.  The bizarre
logic in ctdb_test_exit() makes this worth dropping.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
14 files changed:
ctdb/tests/complex/32_cifs_tickle.sh
ctdb/tests/complex/33_gratuitous_arp.sh
ctdb/tests/complex/42_failover_ssh_hostname.sh
ctdb/tests/complex/43_failover_nfs_basic.sh
ctdb/tests/complex/45_failover_nfs_kill.sh
ctdb/tests/scripts/integration.bash
ctdb/tests/simple/05_ctdb_listnodes.sh
ctdb/tests/simple/06_ctdb_getpid.sh
ctdb/tests/simple/07_ctdb_process_exists.sh
ctdb/tests/simple/08_ctdb_isnotrecmaster.sh
ctdb/tests/simple/11_ctdb_ip.sh
ctdb/tests/simple/12_ctdb_getdebug.sh
ctdb/tests/simple/13_ctdb_setdebug.sh
ctdb/tests/simple/15_ctdb_statisticsreset.sh

index 366824501da5cb1fb5ad45877fa5eefd4c2eed3a..7f67a1127683e6e51422e09535219f51cb0a3f63 100755 (executable)
@@ -69,8 +69,7 @@ echo "$out"
 if [ "${out/SRC: ${src_socket} /}" != "$out" ] ; then
     echo "GOOD: CIFS connection tracked OK by CTDB."
 else
-    echo "BAD: Socket not tracked by CTDB."
-    testfailures=1
+    die "BAD: Socket not tracked by CTDB."
 fi
 
 # This is almost immediate.  However, it is sent between nodes
index 2ee2e063e0671ade9dbe5f2b483e845d25c81737..b2a52931f1f96a3d62c010b633860defb38c625b 100755 (executable)
@@ -82,6 +82,5 @@ echo "MAC address is: ${new_mac}"
 if [ "$original_mac" != "$new_mac" ] ; then
     echo "GOOD: MAC address changed"
 else
-    echo "BAD: MAC address did not change"
-    testfailures=1
+    die "BAD: MAC address did not change"
 fi
index 8c0ac10500e55d589a267cb51ba1917b4fc58d2a..14c2f472708f6b6d458dc2bcb73efa22c80bd293 100755 (executable)
@@ -78,6 +78,5 @@ echo "Hostname is: ${new_hostname}"
 if [ "$original_hostname" != "$new_hostname" ] ; then
     echo "GOOD: hostname changed"
 else
-    echo "BAD: hostname did not change"
-    testfailures=1
+    die "BAD: hostname did not change"
 fi
index a68f7db6811eda8e14f0257c990f496ef442d0cc..9ccf6d7d0d0742c46ab3657579f8be50092b471d 100755 (executable)
@@ -70,6 +70,5 @@ new_sum=$(sum $nfs_local_file)
 if [ "$original_md5" = "$new_md5" ] ; then
     echo "GOOD: file contents unchanged after failover"
 else
-    echo "BAD: file contents are different after failover"
-    testfailures=1
+    die "BAD: file contents are different after failover"
 fi
index aada3711d11a8aabd096a13572432b398c098a53..75a0345b33c9d20dc9d58438f728f61dd04bc5c3 100755 (executable)
@@ -77,6 +77,5 @@ new_sum=$(sum $nfs_local_file)
 if [ "$original_md5" = "$new_md5" ] ; then
     echo "GOOD: file contents unchanged after failover"
 else
-    echo "BAD: file contents are different after failover"
-    testfailures=1
+    die "BAD: file contents are different after failover"
 fi
index 3d68f702cea213d1b43917b886abfbbf560631b1..4790825d042e0234d8441b3f638f7b2b0a9a085a 100644 (file)
@@ -29,9 +29,6 @@ ctdb_test_exit ()
 
     trap - 0
 
-    [ $(($testfailures+0)) -eq 0 -a $status -ne 0 ] && testfailures=$status
-    status=$(($testfailures+0))
-
     # Avoid making a test fail from this point onwards.  The test is
     # now complete.
     set +e
@@ -69,7 +66,6 @@ ctdb_test_exit_hook_add ()
 ctdb_test_init ()
 {
     scriptname=$(basename "$0")
-    testfailures=0
     ctdb_test_restart_scheduled=false
 
     trap "ctdb_test_exit" 0
index 9e48a68e3c05675dee084b8b3eba42b581d1b770..fcf9198d179d67d8584645c75626855fe6dc7798 100755 (executable)
@@ -55,7 +55,7 @@ while [ $n -lt $num_nodes ] ; do
     else
        echo "DIFFERs from node 0:"
        echo "$out"
-       testfailures=1
+       exit 1
     fi
     n=$(($n + 1))
 done
index 21a6e552e55c204e04bd4573df5c605a0b901cde..fca1096b86d18c8eea98c0c5b3c18ff202e0ab2f 100755 (executable)
@@ -51,8 +51,7 @@ pids_getpid_n="$out"
 if [ "$pids_onnode" = "$pids_getpid_n" ] ; then
     echo "They're the same... cool!"
 else
-    echo "Error: they differ."
-    testfailures=1
+    die "Error: they differ."
 fi
 
 echo "Checking each PID for validity"
@@ -68,8 +67,7 @@ while [ $n -lt $num_nodes ] ; do
        # We could check cmdline too if this isn't good enough.
        echo "GOOD enough!"
     else
-       echo "BAD!"
-       testfailures=1
+       die "BAD!"
     fi
     n=$(($n + 1))
 done <<<"$pids_onnode"
index 8ccfc69baa99d99bb0eef437e3a9c2288554ede3..c4b5fdce3b1b8065fb4301105bdefc7999e2271f 100755 (executable)
@@ -62,8 +62,7 @@ echo "$out"
 if [ $status -eq 0 ] ; then
     echo "OK"
 else
-    echo "BAD"
-    testfailures=1
+    die "BAD"
 fi
 
 echo "Checking for PID $client_pid with SRVID $srvid on node $test_node"
@@ -75,8 +74,7 @@ echo "$out"
 if [ $status -eq 0 ] ; then
     echo "OK"
 else
-    echo "BAD"
-    testfailures=1
+    die "BAD"
 fi
 
 echo "Checking for PID $client_pid with SRVID $client_pid on node $test_node"
index 138f59c6e793713a554f97009696ff03f7e69deb..e860665058fb6f8d1378280262682bd919217d09 100755 (executable)
@@ -44,13 +44,11 @@ num_not_rm_lines=$(echo "$out" | fgrep -c 'this node is not the recmaster') || t
 if [ $num_rm_lines -eq 1 ] ; then
     echo "OK, there is only 1 recmaster"
 else
-    echo "BAD, there are ${num_rm_lines} nodes claiming to be the recmaster"
-    testfailures=1
+    die "BAD, there are ${num_rm_lines} nodes claiming to be the recmaster"
 fi
 
 if [ $(($num_all_lines - $num_not_rm_lines)) -eq 1 ] ; then
     echo "OK, all the other nodes claim not to be the recmaster"
 else
-    echo "BAD, there are only ${num_not_rm_lines} nodes claiming not to be the recmaster"
-    testfailures=1
+    die "BAD, there are only ${num_not_rm_lines} notrecmaster nodes"
 fi
index 8bca2c608c5f2d577052c5033a7c0f7b4e32306e..a9e671f7c6a2d0e31d2c635a1d865a5468c8dea9 100755 (executable)
@@ -42,18 +42,17 @@ machineout=$(echo "$out" | sed -r \
        -e 's@\]@@g')
 
 if [ -z "$TEST_LOCAL_DAEMONS" ]; then
-    while read ip pnn ; do
-        try_command_on_node $pnn "ip addr show"
-        if [ "${out/inet* ${ip}\/}" != "$out" ] ; then
-            echo "GOOD: node $pnn appears to have $ip assigned"
-        else
-            echo "BAD:  node $pnn does not appear to have $ip assigned"
-            testfailures=1
-        fi
-    done <<<"$ips" # bashism to avoid problem setting variable in pipeline.
+       while read ip pnn ; do
+               try_command_on_node $pnn "ip addr show"
+               if [ "${out/inet* ${ip}\/}" != "$out" ] ; then
+                       echo "GOOD: node $pnn appears to have $ip assigned"
+               else
+                       die "BAD: node $pnn does not appear to have $ip assigned"
+               fi
+       done <<<"$ips" # bashism to avoid problem setting variable in pipeline.
 fi
 
-[ "$testfailures" != 1 ] && echo "Looks good!"
+echo "Looks good!"
 
 cmd="$CTDB -X ip all | tail -n +2"
 echo "Checking that \"$cmd\" produces expected output..."
@@ -66,5 +65,5 @@ else
     echo "$out"
     echo "Should be like this:"
     echo "$machineout"
-    testfailures=1
+    exit 1
 fi
index 226184813c0fec65993c6ab62c5963dd7418cf4d..1d9d596527384181ea532e7cf2d056fd313fcc67 100755 (executable)
@@ -51,8 +51,7 @@ getdebug_n="$out"
 if [ "$getdebug_onnode" = "$getdebug_n" ] ; then
     echo "They're the same... cool!"
 else
-    echo "Error: they differ."
-    testfailures=1
+    die "Error: they differ."
 fi
 
 seps=""
index e8652108d72c6a2b968e001a3e1a18b1e51d8990..2301ef6833e99aa0f695b96e81f173be9c9d94da 100755 (executable)
@@ -19,6 +19,8 @@ set -e
 
 cluster_is_healthy
 
+ctdb_restart_when_done
+
 select_test_node_and_ips
 
 get_debug ()
@@ -45,8 +47,7 @@ set_and_check_debug ()
     get_debug $node
 
     if [ "$levelstr" != "$check_debug" ] ; then
-       echo "BAD: Debug level should have changed to \"$levelstr\" but it is \"$check_debug\"."
-       testfailures=1
+       die "BAD: Debug level \"$levelstr\" != \"$check_debug\"."
     fi
 }
 
@@ -80,9 +81,3 @@ INFO 8
 INFO 9
 DEBUG 10
 EOF
-
-if [ "$testfailures" != 1 ] ; then
-    echo
-    echo "Returning the debug level to its initial value..."
-    set_and_check_debug $test_node "$initial_debug"
-fi
index eaa60d692052e07f166d60129170498209890971..706358510b3385bfda65ad5b677eb8dc4e7db6e7 100755 (executable)
@@ -52,8 +52,7 @@ check_reduced ()
     if [ $after -lt $before ] ; then
        echo "GOOD: ${label} reduced from ${before} to ${after}"
     else
-       echo "BAD: ${label} did not reduce from ${before} to ${after}"
-       testfailures=1
+       die "BAD: ${label} did not reduce from ${before} to ${after}"
     fi
 }