ctdb-protocol: Fix marshalling for ctdb_uptime
[vlendec/samba-autobuild/.git] / ctdb / tests / scripts / integration.bash
index 0d27c93643fabfe460ad0e4288d7bf3495401c74..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=""
@@ -229,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
@@ -292,7 +320,7 @@ _cluster_is_healthy ()
 
 _cluster_is_recovered ()
 {
-    node_has_status all recovered
+    node_has_status 0 recovered
 }
 
 _cluster_is_ready ()
@@ -496,31 +524,21 @@ wait_until_node_has_some_ips ()
 
 #######################################
 
-_ctdb_hack_options ()
+_service_ctdb ()
 {
-    local ctdb_options="$*"
-
-    case "$ctdb_options" in
-       *--start-as-stopped*)
-           export CTDB_START_AS_STOPPED="yes"
-    esac
-}
-
-restart_ctdb_1 ()
-{
-    _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.
@@ -529,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)"
@@ -541,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
@@ -699,8 +730,9 @@ ip_maskbits_iface ()
 
     ip addr show to "${_addr}/${_bits}" 2>/dev/null | \
        awk -v family="${_family}" \
-           'NR == 1 { iface = gensub(":$", "", 1, $2) } \
-             $1 ~ /inet/ { print gensub(".*/", "", 1, $2), iface, family }'
+           'NR == 1 { iface = $2; sub(":$", "", iface) } \
+             $1 ~ /inet/ { mask = $2; sub(".*/", "", mask); \
+                           print mask, iface, family }'
 }
 
 drop_ip ()