summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2020-03-05 20:21:26 +1100
committerMartin Schwenke <martins@samba.org>2020-07-22 07:53:36 +0000
commit760c3039b0752204090b493132ad32bad4140064 (patch)
treed981477793020297ee94a31f8e21cbb11ed18554
parent41ff58338a0b36dfccc19579c8edfa5939cd5978 (diff)
downloadsamba-760c3039b0752204090b493132ad32bad4140064.tar.gz
ctdb-tests: Improve test portability
"wc -l" on some platforms (e.g. FreeBSD) contains leading spaces and stops "$num from being a number. Create a more portable solution and put it in a function instead of repeating the logic. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
-rwxr-xr-xctdb/tests/INTEGRATION/failover/pubips.040.NoIPTakeover.sh43
1 files changed, 29 insertions, 14 deletions
diff --git a/ctdb/tests/INTEGRATION/failover/pubips.040.NoIPTakeover.sh b/ctdb/tests/INTEGRATION/failover/pubips.040.NoIPTakeover.sh
index a39e48d0883..058d7febf5f 100755
--- a/ctdb/tests/INTEGRATION/failover/pubips.040.NoIPTakeover.sh
+++ b/ctdb/tests/INTEGRATION/failover/pubips.040.NoIPTakeover.sh
@@ -22,9 +22,26 @@ echo "Wait until the ips are reallocated"
sleep_for 30
try_command_on_node 0 "$CTDB ipreallocate"
-num=`try_command_on_node -v 1 "$CTDB ip" | grep -v Public | egrep " 1$" | wc -l`
-echo "Number of addresses on node 1 : $num"
+# sets: num
+count_ips_on_node ()
+{
+ local node="$1"
+
+ ctdb_onnode "$node" ip
+ # outfile is set by ctdb_onnode() above
+ # shellcheck disable=SC2154,SC2126
+ # * || true is needed to avoid command failure when there are no matches
+ # * Using "wc -l | tr -d '[:space:]'" is our standard
+ # pattern... and "grep -c" requires handling of special case
+ # for no match
+ num=$(grep -v 'Public' "$outfile" | \
+ grep " ${node}\$" | \
+ wc -l | \
+ tr -d '[:space:]')
+ echo "Number of addresses on node ${node}: ${num}"
+}
+count_ips_on_node 1
echo "Turning on NoIPTakeover on all nodes"
try_command_on_node all "$CTDB setvar NoIPTakeover 1"
@@ -33,12 +50,11 @@ try_command_on_node 1 "$CTDB ipreallocate"
echo Disable node 1
try_command_on_node 1 "$CTDB disable"
try_command_on_node 1 "$CTDB ipreallocate"
-num=`try_command_on_node -v 1 "$CTDB ip" | grep -v Public | egrep " 1$" | wc -l`
-echo "Number of addresses on node 1 : $num"
-[ "$num" != "0" ] && {
- echo "BAD: node 1 still hosts ip addresses"
- exit 1
-}
+
+count_ips_on_node 1
+if [ "$num" != "0" ] ; then
+ test_fail "BAD: node 1 still hosts IP addresses"
+fi
echo "Enable node 1 again"
@@ -46,12 +62,11 @@ try_command_on_node 1 "$CTDB enable"
sleep_for 30
try_command_on_node 1 "$CTDB ipreallocate"
try_command_on_node 1 "$CTDB ipreallocate"
-num=`try_command_on_node -v 1 "$CTDB ip" | grep -v Public | egrep " 1$" | wc -l`
-echo "Number of addresses on node 1 : $num"
-[ "$num" != "0" ] && {
- echo "BAD: node took over ip addresses"
- exit 1
-}
+
+count_ips_on_node 1
+if [ "$num" != "0" ] ; then
+ test_fail "BAD: node 1 took over IP addresses"
+fi
echo "OK. ip addresses were not taken over"