onnode: fix natgwlist nodespec
authorMartin Schwenke <martin@meltin.net>
Mon, 23 May 2011 05:33:12 +0000 (15:33 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Wed, 8 Jun 2011 04:23:56 +0000 (14:23 +1000)
This hasn't worked for a while if ever.

We treat this case specially because the output has 2 works on the 1st
line.  We also handle the error case where /etc/ctdb_natgw_nodes
exists but none of the other $NATGW_* configuration is done.

Signed-off-by: Martin Schwenke <martin@meltin.net>
tools/onnode

index 59f2535d28466ff098e42e80e0320288646e0eda..804ab09cc2d38793022952ea6863e8b8a274d9c5 100755 (executable)
@@ -189,20 +189,36 @@ get_node_with_property ()
 
     local prop_node=""
     if [ "${ctdb_props##:${prop}:}" = "$ctdb_props" ] ; then
+       # Not in cache.
        prop_node=$(ctdb "$prop" -Y 2>/dev/null)
-       # We only want the first line.
-       local nl="
-"
-       prop_node="${prop_node%%${nl}*}"
        if [ $? -eq 0 ] ; then
-           ctdb_props="${ctdb_props}${ctdb_props:+ }:${prop}:${prop_node}"
+           if [ "$prop" = "natgwlist" ] ; then
+               prop_node="${prop_node%% *}" # 1st word
+               if [ "$prop_node" = "-1" ] ; then
+                   # This works around natgwlist returning 0 even
+                   # when there's no natgw.
+                   prop_node=""
+               fi
+           else
+               # We only want the first line.
+               local nl="
+"
+               prop_node="${prop_node%%${nl}*}"
+           fi
        else
            prop_node=""
        fi
+
+       if [ -n "$prop_node" ] ; then
+           # Add to cache.
+           ctdb_props="${ctdb_props}${ctdb_props:+ }:${prop}:${prop_node}"
+       fi
     else
+       # Get from cache.
        prop_node="${ctdb_props##:${prop}:}"
        prop_node="${prop_node%% *}"
     fi
+
     if [ -n "$prop_node" ] ; then
        echo_nth "$prop_node" $all_nodes
     else