ctdb-tests: Produce clear errors for missing IPv6 node IP addresses
authorMartin Schwenke <martin@meltin.net>
Wed, 21 Sep 2016 01:51:50 +0000 (11:51 +1000)
committerAmitay Isaacs <amitay@samba.org>
Thu, 22 Sep 2016 06:34:20 +0000 (08:34 +0200)
This replaces a broken FIXME comment in the code.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/tests/simple/scripts/local_daemons.bash

index b5cfff58eb0a364dd750194f80dae042a823dcb2..8624cb905c832eb9ccb41f00c2b09c0ff85a625a 100644 (file)
@@ -31,6 +31,21 @@ config_from_environment ()
        sed -e 's@=\([^"]\)@="\1@' -e 's@[^"]$@&"@' -e 's@="$@&"@'
 }
 
+# If the given IP is hosted then print 2 items: maskbits and iface
+have_ip ()
+{
+       local addr="$1"
+       local bits t
+
+       case "$addr" in
+       *:*) bits=128 ;;
+       *)   bits=32  ;;
+       esac
+
+       t=$(ip addr show to "${addr}/${bits}")
+       [ -n "$t" ]
+}
+
 setup_ctdb ()
 {
     mkdir -p "${TEST_VAR_DIR}/test.db/persistent"
@@ -53,13 +68,19 @@ setup_ctdb ()
     mkdir -p "${TEST_VAR_DIR}/events.d"
     cp -p "${events_d}/"* "${TEST_VAR_DIR}/events.d/"
 
+    local have_all_ips=true
     local i
     for i in $(seq 1 $TEST_LOCAL_DAEMONS) ; do
-       if [ "${CTDB_USE_IPV6}x" != "x" ]; then
-           j=$(printf "%02x" $i)
-           echo "fd00::5357:5f${j}" >>"$CTDB_NODES"
-           # FIXME: need to add addresses to lo as root before running :-(
-           # ip addr add "fc00:10::${i}/64" dev lo
+       if [ -n "$CTDB_USE_IPV6" ]; then
+           local j=$(printf "%02x" $i)
+           local node_ip="fd00::5357:5f${j}"
+           if have_ip "$node_ip" ; then
+               echo "$node_ip" >>"$CTDB_NODES"
+           else
+               echo "ERROR: ${node_ip} not on an interface, please add it"
+               have_all_ips=false
+           fi
+
            # 2 public addresses on most nodes, just to make things interesting.
            if [ $(($i - 1)) -ne $no_public_ips ] ; then
                echo "fc00:10::1:${i}/64 lo" >>"$public_addresses_all"
@@ -76,6 +97,10 @@ setup_ctdb ()
        fi
     done
 
+    if ! $have_all_ips ; then
+           return 1
+    fi
+
     local pnn
     for pnn in $(seq 0 $(($TEST_LOCAL_DAEMONS - 1))) ; do
        local public_addresses_mine="${TEST_VAR_DIR}/public_addresses.${pnn}"