mirror of
https://github.com/samba-team/samba.git
synced 2025-03-27 22:50:26 +03:00
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 <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
parent
f1265f0ebe
commit
bae9feacf2
@ -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"
|
||||
|
||||
|
@ -681,14 +681,15 @@ CTDB_NATGW_DEFAULT_GATEWAY=10.0.0.1
|
||||
<para>
|
||||
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,
|
||||
<varname>CTDB_NATGW_SLAVE_ONLY</varname> 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
|
||||
<varname>CTDB_NATGW_NODES</varname> file to limit the NATGW
|
||||
functionality of those nodes.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
See the <citetitle>NAT GATEWAY</citetitle> section in
|
||||
<citerefentry><refentrytitle>ctdb.conf</refentrytitle>
|
||||
<citerefentry><refentrytitle>ctdbd.conf</refentrytitle>
|
||||
<manvolnum>5</manvolnum></citerefentry> for more details of
|
||||
NATGW configuration.
|
||||
</para>
|
||||
|
@ -561,9 +561,20 @@
|
||||
<para>
|
||||
File format:
|
||||
<screen>
|
||||
<parameter>IPADDR</parameter>
|
||||
<parameter>IPADDR</parameter> <optional>slave-only</optional>
|
||||
</screen>
|
||||
</para>
|
||||
<para>
|
||||
IPADDR is the private IP address of each node in the NAT
|
||||
gateway group.
|
||||
</para>
|
||||
<para>
|
||||
If "slave-only" is specified then the corresponding node
|
||||
can not be the NAT gateway master node. In this case
|
||||
<varname>CTDB_NATGW_PUBLIC_IFACE</varname> and
|
||||
<varname>CTDB_NATGW_PUBLIC_IP</varname> are optional and
|
||||
unused.
|
||||
</para>
|
||||
<para>
|
||||
No default, usually
|
||||
<filename>/usr/local/etc/ctdb/natgw_nodes</filename> when enabled.
|
||||
@ -615,22 +626,6 @@
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>CTDB_NATGW_SLAVE_ONLY=yes|no</term>
|
||||
<listitem>
|
||||
<para>
|
||||
When set to "yes" a node can not be a NAT gateway master
|
||||
node. In this case
|
||||
<varname>CTDB_NATGW_PUBLIC_IFACE</varname> and
|
||||
<varname>CTDB_NATGW_PUBLIC_IP</varname> are optional
|
||||
and unused.
|
||||
</para>
|
||||
<para>
|
||||
Default is no.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>CTDB_NATGW_STATIC_ROUTES=<parameter>IPADDR/MASK[@GATEWAY]</parameter> ...</term>
|
||||
<listitem>
|
||||
|
@ -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 <<EOF
|
||||
192.168.1.21
|
||||
192.168.1.21 slave-only
|
||||
192.168.1.22 master
|
||||
192.168.1.23
|
||||
192.168.1.24
|
||||
EOF
|
||||
|
||||
CTDB_NATGW_PUBLIC_IFACE=""
|
||||
CTDB_NATGW_SLAVE_ONLY="yes"
|
||||
|
||||
ok_null
|
||||
simple_test_event "ipreallocated"
|
||||
|
@ -2,11 +2,11 @@
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
define_test "CTDB_NATGW_SLAVE_ONLY=yes, CTDB_NATGW_PUBLIC_IP unset"
|
||||
define_test "slave-only, CTDB_NATGW_PUBLIC_IP unset"
|
||||
|
||||
setup_ctdb
|
||||
setup_ctdb_natgw <<EOF
|
||||
192.168.1.21
|
||||
192.168.1.21 slave-only
|
||||
192.168.1.22 master
|
||||
192.168.1.23
|
||||
192.168.1.24
|
||||
@ -14,7 +14,6 @@ EOF
|
||||
|
||||
CTDB_NATGW_PUBLIC_IFACE=""
|
||||
CTDB_NATGW_PUBLIC_IP=""
|
||||
CTDB_NATGW_SLAVE_ONLY="yes"
|
||||
|
||||
ok_null
|
||||
simple_test_event "ipreallocated"
|
||||
|
@ -250,62 +250,17 @@ ctdb_setnatgwstate ()
|
||||
echo "$2" >"$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
|
||||
|
34
ctdb/tests/eventscripts/stubs/ctdb_natgw
Executable file
34
ctdb/tests/eventscripts/stubs/ctdb_natgw
Executable file
@ -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
|
Loading…
x
Reference in New Issue
Block a user