From: Martin Schwenke Date: Mon, 14 Dec 2015 10:37:44 +0000 (+1100) Subject: ctdb: Call out to ctdb_natgw helper from 11.natgw X-Git-Tag: samba-4.4.0rc1~62 X-Git-Url: http://git.samba.org/samba.git/?a=commitdiff_plain;h=bae9feacf2c3a1117f7b9001b95398142479e1c7;p=gd%2Fsamba-autobuild%2F.git ctdb: Call out to ctdb_natgw helper from 11.natgw To keep this commit comprehensible, 11.natgw and the CTDB CLI tool are temporarily inconsistent. The tool will be made consistent in a subsequent commit. ctdb_natgw_slave_only() is reimplemented to check for the option in the appropriate line in $CTDB_NATGW_NODES. Update unit tests and documentation. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/config/events.d/11.natgw b/ctdb/config/events.d/11.natgw index 1ca446d91c8..32e42c9e2b7 100755 --- a/ctdb/config/events.d/11.natgw +++ b/ctdb/config/events.d/11.natgw @@ -23,9 +23,26 @@ natgw_cfg_new="${service_state_dir}/cfg_new" natgw_cfg_old="${service_state_dir}/cfg_old" natgw_master_old="${service_state_dir}/master_old" +# Cached retrieval of private IP address from local node. This never +# changes. Sets $ip_address to avoid an unnecessary subprocess. +ctdb_get_ip_address () +{ + _ip_addr_file="${service_state_dir}/my-ip-address" + if [ ! -f "$_ip_addr_file" ] ; then + ctdb -X nodestatus | + awk -F '|' 'NR == 2 { print $3 }' >"$_ip_addr_file" + fi + + read ip_address <"$_ip_addr_file" +} + ctdb_natgw_slave_only () { - [ "$CTDB_NATGW_SLAVE_ONLY" = "yes" ] + ctdb_get_ip_address + + awk -v my_ip="$ip_address" \ + '$1 == my_ip { if ($2 ~ "slave-only") { exit 0 } else { exit 1 } }' \ + "$CTDB_NATGW_NODES" } natgw_check_config () @@ -60,7 +77,6 @@ CTDB_NATGW_PUBLIC_IFACE="$CTDB_NATGW_PUBLIC_IFACE" CTDB_NATGW_DEFAULT_GATEWAY="$CTDB_NATGW_DEFAULT_GATEWAY" CTDB_NATGW_PRIVATE_NETWORK="$CTDB_NATGW_PRIVATE_NETWORK" CTDB_NATGW_STATIC_ROUTES="$CTDB_NATGW_STATIC_ROUTES" -CTDB_NATGW_SLAVE_ONLY="$CTDB_NATGW_SLAVE_ONLY" EOF } @@ -166,7 +182,7 @@ natgw_set_slave () natgw_ensure_master () { - set -- $(ctdb natgwlist) + set -- $(ctdb_natgw master) natgwmaster="${1:--1}" # Default is -1 if natgwlist fails natgwip="$2" diff --git a/ctdb/doc/ctdb.7.xml b/ctdb/doc/ctdb.7.xml index 45d7c23bd14..c4d5f1c43b9 100644 --- a/ctdb/doc/ctdb.7.xml +++ b/ctdb/doc/ctdb.7.xml @@ -681,14 +681,15 @@ CTDB_NATGW_DEFAULT_GATEWAY=10.0.0.1 Normally any node in a NATGW group can act as the NATGW master. Some configurations may have special nodes that lack - connectivity to a public network. In such cases, - CTDB_NATGW_SLAVE_ONLY can be used to limit the - NATGW functionality of thos nodes. + connectivity to a public network. In such cases, those nodes + can be flagged with the "slave-only" option in the + CTDB_NATGW_NODES file to limit the NATGW + functionality of those nodes. See the NAT GATEWAY section in - ctdb.conf + ctdbd.conf 5 for more details of NATGW configuration. diff --git a/ctdb/doc/ctdbd.conf.5.xml b/ctdb/doc/ctdbd.conf.5.xml index a8ebe5669ca..5494b51ad0a 100644 --- a/ctdb/doc/ctdbd.conf.5.xml +++ b/ctdb/doc/ctdbd.conf.5.xml @@ -561,9 +561,20 @@ File format: -IPADDR +IPADDR slave-only + + IPADDR is the private IP address of each node in the NAT + gateway group. + + + If "slave-only" is specified then the corresponding node + can not be the NAT gateway master node. In this case + CTDB_NATGW_PUBLIC_IFACE and + CTDB_NATGW_PUBLIC_IP are optional and + unused. + No default, usually /usr/local/etc/ctdb/natgw_nodes when enabled. @@ -615,22 +626,6 @@ - - CTDB_NATGW_SLAVE_ONLY=yes|no - - - When set to "yes" a node can not be a NAT gateway master - node. In this case - CTDB_NATGW_PUBLIC_IFACE and - CTDB_NATGW_PUBLIC_IP are optional - and unused. - - - Default is no. - - - - CTDB_NATGW_STATIC_ROUTES=IPADDR/MASK[@GATEWAY] ... diff --git a/ctdb/tests/eventscripts/11.natgw.041.sh b/ctdb/tests/eventscripts/11.natgw.041.sh index 22dd3929bc1..e8126e1b47c 100755 --- a/ctdb/tests/eventscripts/11.natgw.041.sh +++ b/ctdb/tests/eventscripts/11.natgw.041.sh @@ -2,18 +2,17 @@ . "${TEST_SCRIPTS_DIR}/unit.sh" -define_test "CTDB_NATGW_SLAVE_ONLY=yes, CTDB_NATGW_PUBLIC_IFACE unset" +define_test "slave-only, CTDB_NATGW_PUBLIC_IFACE unset" setup_ctdb setup_ctdb_natgw <"$FAKE_CTDB_NATGW_STATE" } -ctdb_natgwlist () +# This is only used by the NAT gateway code at the moment, so use a +# hack. Assume that $CTDB_NATGW_NODES contains all nodes in the +# cluster (which is what current tests assume). Use the PNN to find +# the address from this file. The NAT gateway code only used the +# address, so just mark the node healthy. +ctdb_nodestatus () { - [ -r "$CTDB_NATGW_NODES" ] || \ - die "error: missing CTDB_NATGW_NODES=${CTDB_NATGW_NODES}" - - # Determine if the current node has the (fake) NAT gateway - # capability. This is only used to make sure tests are sane and - # don't try to use inconsistent setup. - if [ -r "$FAKE_CTDB_NATGW_STATE" ] ; then - read _state <"$FAKE_CTDB_NATGW_STATE" - else - _state="off" - fi - - # Determine the master node - _master="-1 0.0.0.0" - _pnn=0 - while read _ip ; do - if [ "$FAKE_CTDB_NATGW_MASTER" = "$_ip" ] ; then - _master="${_pnn} ${_ip}" - if [ "$_pnn" = "$FAKE_CTDB_PNN" -a "$_state" = "off" ] ; then - die "Inconsistent test configuration - master node is slave-only" - fi - break - fi - _pnn=$(($_pnn + 1)) - done <"$CTDB_NATGW_NODES" - echo "$_master" - - # Now print the node information - it is clearer to do this in a - # second pass. Any nodes before the master that have state not - # "off" are tagged as unhealthy, just so the output makes some - # sense. - _pnn=0 - _found_master=false - while read _ip ; do - if [ "$FAKE_CTDB_NATGW_MASTER" = "$_ip" ] ; then - _found_master=true - fi - if $_found_master ; then - _outstate="HEALTHY" - else - if [ $FAKE_CTDB_PNN -eq $_pnn -a "$_state" = "off" ] ; then - _outstate="HEALTHY" - else - _outstate="UNHEALTHY" - fi - fi - if [ $FAKE_CTDB_PNN -eq $_pnn ] ; then - _outstate="${_outstate} (THIS NODE)" - fi - printf "pnn:%d %-16s ${_outstate}\n" $_pnn "$_ip" - - _pnn=$(($_pnn + 1)) - done <"$CTDB_NATGW_NODES" - + echo '|Node|IP|Disconnected|Banned|Disabled|Unhealthy|Stopped|Inactive|PartiallyOnline|ThisNode|' + _line=$(( $FAKE_CTDB_PNN + 1 )) + _ip=$(sed -e "${_line}p" "$CTDB_NATGW_NODES") + echo "|${FAKE_CTDB_PNN}|${_ip}|0|0|0|0|0|0|0|Y|" } ###################################################################### @@ -514,7 +469,7 @@ case "$1" in moveip) ctdb_moveip "$@";; shutdown) ctdb_shutdown "$@";; setnatgwstate) ctdb_setnatgwstate "$@" ;; - natgwlist) ctdb_natgwlist "$@" ;; setvar) ctdb_setvar "$@" ;; + nodestatus) ctdb_nodestatus "$@" ;; *) not_implemented "$1" ;; esac diff --git a/ctdb/tests/eventscripts/stubs/ctdb_natgw b/ctdb/tests/eventscripts/stubs/ctdb_natgw new file mode 100755 index 00000000000..96ba7ef8bbf --- /dev/null +++ b/ctdb/tests/eventscripts/stubs/ctdb_natgw @@ -0,0 +1,34 @@ +#!/bin/sh + +prog="ctdb_natgw" + +not_implemented_exit_code=1 + +not_implemented () +{ + echo "${prog}: command \"$1\" not implemented in stub" >&2 + exit $not_implemented_exit_code +} + +ctdb_natgw_master () +{ + [ -r "$CTDB_NATGW_NODES" ] || \ + die "error: missing CTDB_NATGW_NODES=${CTDB_NATGW_NODES}" + + # Determine the master node + _master="-1 0.0.0.0" + _pnn=0 + while read _ip ; do + if [ "$FAKE_CTDB_NATGW_MASTER" = "$_ip" ] ; then + _master="${_pnn} ${_ip}" + break + fi + _pnn=$(($_pnn + 1)) + done <"$CTDB_NATGW_NODES" + echo "$_master" +} + +case "$1" in + master) ctdb_natgw_master "$@" ;; + *) not_implemented "$1" ;; +esac