ctdb-protocol: Fix marshalling for ctdb_uptime
[vlendec/samba-autobuild/.git] / ctdb / tests / scripts / integration.bash
index 2ae03425f43514d430ab59cee51806d3f4cfd27a..4f1227f4393f340cc84c8c56205d5b6395128e4b 100644 (file)
@@ -169,7 +169,7 @@ all_ips_on_node()
 _select_test_node_and_ips ()
 {
     try_command_on_node any \
-       "$CTDB ip -X -n all | awk -F'|' 'NR > 1 { print \$2, \$3 }'"
+       "$CTDB ip -X all | awk -F'|' 'NR > 1 { print \$2, \$3 }'"
 
     test_node=""  # this matches no PNN
     test_node_ips=""
@@ -186,6 +186,11 @@ _select_test_node_and_ips ()
     echo "Selected node ${test_node} with IPs: ${test_node_ips}."
     test_ip="${test_node_ips%% *}"
 
+    case "$test_ip" in
+       *:*) test_prefix="${test_ip}/128" ;;
+       *)   test_prefix="${test_ip}/32"  ;;
+    esac
+
     [ -n "$test_node" ] || return 1
 }
 
@@ -224,6 +229,34 @@ get_test_ip_mask_and_iface ()
     echo "$test_ip/$mask is on $iface"
 }
 
+ctdb_get_all_pnns ()
+{
+    try_command_on_node -q all "$CTDB pnn"
+    all_pnns="$out"
+}
+
+# The subtlety is that "ctdb delip" will fail if the IP address isn't
+# configured on a node...
+delete_ip_from_all_nodes ()
+{
+    _ip="$1"
+
+    ctdb_get_all_pnns
+
+    _nodes=""
+
+    for _pnn in $all_pnns ; do
+       all_ips_on_node $_pnn
+       while read _i _n ; do
+           if [ "$_ip" = "$_i" ] ; then
+               _nodes="${_nodes}${_nodes:+,}${_pnn}"
+           fi
+       done <<<"$out" # bashism
+    done
+
+    try_command_on_node -pq "$_nodes" "$CTDB delip $_ip"
+}
+
 #######################################
 
 # Wait until either timeout expires or command succeeds.  The command
@@ -287,7 +320,7 @@ _cluster_is_healthy ()
 
 _cluster_is_recovered ()
 {
-    node_has_status all recovered
+    node_has_status 0 recovered
 }
 
 _cluster_is_ready ()
@@ -491,31 +524,21 @@ wait_until_node_has_some_ips ()
 
 #######################################
 
-_ctdb_hack_options ()
-{
-    local ctdb_options="$*"
-
-    case "$ctdb_options" in
-       *--start-as-stopped*)
-           export CTDB_START_AS_STOPPED="yes"
-    esac
-}
-
-restart_ctdb_1 ()
+_service_ctdb ()
 {
-    _ctdb_hack_options "$@"
+    cmd="$1"
 
     if [ -e /etc/redhat-release ] ; then
-       service ctdb restart
+       service ctdb "$cmd"
     else
-       /etc/init.d/ctdb restart
+       /etc/init.d/ctdb "$cmd"
     fi
 }
 
 # Restart CTDB on all nodes.  Override for local daemons.
 _restart_ctdb_all ()
 {
-    onnode -p all $CTDB_TEST_WRAPPER restart_ctdb_1 "$@"
+    onnode -p all $CTDB_TEST_WRAPPER _service_ctdb restart
 }
 
 # Nothing needed for a cluster.  Override for local daemons.
@@ -524,10 +547,23 @@ setup_ctdb ()
     :
 }
 
-restart_ctdb ()
+start_ctdb_1 ()
+{
+    onnode "$1" $CTDB_TEST_WRAPPER _service_ctdb start
+}
+
+stop_ctdb_1 ()
 {
-    # "$@" is passed to restart_ctdb_all.
+    onnode "$1" $CTDB_TEST_WRAPPER _service_ctdb stop
+}
+
+restart_ctdb_1 ()
+{
+    onnode "$1" $CTDB_TEST_WRAPPER _service_ctdb restart
+}
 
+restart_ctdb ()
+{
     echo -n "Restarting CTDB"
     if $ctdb_test_restart_scheduled ; then
        echo -n " (scheduled)"
@@ -536,7 +572,7 @@ restart_ctdb ()
 
     local i
     for i in $(seq 1 5) ; do
-       _restart_ctdb_all "$@" || {
+       _restart_ctdb_all || {
            echo "Restart failed.  Trying again in a few seconds..."
            sleep_for 5
            continue
@@ -682,6 +718,45 @@ nfs_test_cleanup ()
 
 #######################################
 
+# If the given IP is hosted then print 2 items: maskbits and iface
+ip_maskbits_iface ()
+{
+    _addr="$1"
+
+    case "$_addr" in
+       *:*) _family="inet6" ; _bits=128 ;;
+       *)   _family="inet"  ; _bits=32  ;;
+    esac
+
+    ip addr show to "${_addr}/${_bits}" 2>/dev/null | \
+       awk -v family="${_family}" \
+           'NR == 1 { iface = $2; sub(":$", "", iface) } \
+             $1 ~ /inet/ { mask = $2; sub(".*/", "", mask); \
+                           print mask, iface, family }'
+}
+
+drop_ip ()
+{
+    _addr="${1%/*}"  # Remove optional maskbits
+
+    set -- $(ip_maskbits_iface $_addr)
+    if [ -n "$1" ] ; then
+       _maskbits="$1"
+       _iface="$2"
+       echo "Removing public address $_addr/$_maskbits from device $_iface"
+       ip addr del "$_ip/$_maskbits" dev "$_iface" >/dev/null 2>&1 || true
+    fi
+}
+
+drop_ips ()
+{
+    for _ip ; do
+       drop_ip "$_ip"
+    done
+}
+
+#######################################
+
 # $1: pnn, $2: DB name
 db_get_path ()
 {