summaryrefslogtreecommitdiffstats
path: root/ctdb/tests/eventscripts/stubs
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2014-03-14 16:29:01 +1100
committerAmitay Isaacs <amitay@samba.org>2014-03-26 04:21:41 +0100
commit7fdd6b7861a4767cd3e2dfa76a7d7e7790efd840 (patch)
tree10a8bafc0f96e89d3df24e796cd7ec2f62ade3c7 /ctdb/tests/eventscripts/stubs
parentfeeb9843bf46d00beb10f3e959ba0f73f5e33e8c (diff)
downloadsamba-7fdd6b7861a4767cd3e2dfa76a7d7e7790efd840.tar.gz
samba-7fdd6b7861a4767cd3e2dfa76a7d7e7790efd840.tar.xz
samba-7fdd6b7861a4767cd3e2dfa76a7d7e7790efd840.zip
ctdb-tests: Add some tests for 11.natgw eventscript
This includes adding support for: * Configuring fake NATGW state in the eventscript unit tests * "natgwlist" and "setnatgwstate" in ctdb command stub * ip command stub to default to "main table" when no table specified, allow routes to be added without "dev" option (just add a default dev), support "metric" option Signed-off-by: Martin Schwenke <martin@meltin.net>
Diffstat (limited to 'ctdb/tests/eventscripts/stubs')
-rwxr-xr-xctdb/tests/eventscripts/stubs/ctdb82
-rwxr-xr-xctdb/tests/eventscripts/stubs/ip84
2 files changed, 148 insertions, 18 deletions
diff --git a/ctdb/tests/eventscripts/stubs/ctdb b/ctdb/tests/eventscripts/stubs/ctdb
index da84ed7cdf..51c17635fc 100755
--- a/ctdb/tests/eventscripts/stubs/ctdb
+++ b/ctdb/tests/eventscripts/stubs/ctdb
@@ -2,6 +2,12 @@
prog="ctdb"
+# Print a message and exit.
+die ()
+{
+ echo "$1" >&2 ; exit ${2:-1}
+}
+
not_implemented_exit_code=1
usage ()
@@ -231,6 +237,66 @@ ctdb_shutdown ()
######################################################################
+FAKE_CTDB_NATGW_STATE="${FAKE_CTDB_STATE}/natgw_state"
+
+ctdb_setnatgwstate ()
+{
+ echo "$2" >"$FAKE_CTDB_NATGW_STATE"
+}
+
+ctdb_natgwlist ()
+{
+ [ -r "$CTDB_NATGW_NODES" ] || \
+ die "error: missing CTDB_NATGW_NODES=${CTDB_NATGW_NODES}"
+
+ # Determine the master node
+ _master="-1 0.0.0.0"
+ if [ -r "$FAKE_CTDB_NATGW_STATE" ] ; then
+ read _state <"$FAKE_CTDB_NATGW_STATE"
+ if [ "$_state" = "on" ] ; then
+ _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"
+ fi
+ fi
+ 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"
+
+}
+
+######################################################################
+
case "$1" in
gettickles)
setup_tickles
@@ -323,12 +389,14 @@ case "$1" in
done
;;
gratiousarp) : ;; # Do nothing for now
- killtcp) ctdb_killtcp "$@" ;;
- ip) ctdb_ip "$@" ;;
- pnn|xpnn) ctdb_pnn ;;
- enable) ctdb_enable "$@";;
- disable) ctdb_disable "$@";;
- moveip) ctdb_moveip "$@";;
- shutdown) ctdb_shutdown "$@";;
+ killtcp) ctdb_killtcp "$@" ;;
+ ip) ctdb_ip "$@" ;;
+ pnn|xpnn) ctdb_pnn ;;
+ enable) ctdb_enable "$@";;
+ disable) ctdb_disable "$@";;
+ moveip) ctdb_moveip "$@";;
+ shutdown) ctdb_shutdown "$@";;
+ setnatgwstate) ctdb_setnatgwstate "$@" ;;
+ natgwlist) ctdb_natgwlist "$@" ;;
*) not_implemented "$1" ;;
esac
diff --git a/ctdb/tests/eventscripts/stubs/ip b/ctdb/tests/eventscripts/stubs/ip
index 860f6a5408..e8f17d8413 100755
--- a/ctdb/tests/eventscripts/stubs/ip
+++ b/ctdb/tests/eventscripts/stubs/ip
@@ -80,12 +80,17 @@ ip_check_table ()
{
_cmd="$1"
+ if [ "$_cmd" = "route" -a -z "$_table" ] ;then
+ _table="main"
+ fi
+
[ -n "$_table" ] || not_implemented "ip rule/route without \"table\""
- # Only allow tables names from 13.per_ip_routing. This is a cheap
- # way of avoiding implementing the default/main/local tables.
+ # Only allow tables names from 13.per_ip_routing and "main". This
+ # is a cheap way of avoiding implementing the default/local
+ # tables.
case "$_table" in
- ctdb.*)
+ ctdb.*|main)
if $IP_ROUTE_BAD_TABLE_ID ; then
# Ouch. Simulate inconsistent errors from ip. :-(
case "$_cmd" in
@@ -449,14 +454,17 @@ ip_route ()
show|list) shift ; ip_route_show "$@" ;;
flush) shift ; ip_route_flush "$@" ;;
add) shift ; ip_route_add "$@" ;;
+ del*) shift ; ip_route_del "$@" ;;
*) not_implemented "$1 in \"ip route\"" ;;
esac
}
ip_route_common ()
{
- [ "$1" = table ] || not_implemented "$1 in \"$orig_args\""
- _table="$2"
+ if [ "$1" = table ] ; then
+ _table="$2"
+ shift 2
+ fi
ip_check_table "route"
}
@@ -487,6 +495,7 @@ ip_route_add ()
_dev=""
_gw=""
_table=""
+ _metric=""
while [ -n "$1" ] ; do
case "$1" in
@@ -495,13 +504,15 @@ ip_route_add ()
dev) _dev="$2" ; shift 2 ;;
via) _gw="$2" ; shift 2 ;;
table) _table="$2" ; shift 2 ;;
+ metric) _metric="$2" ; shift 2 ;;
*) not_implemented "$1 in \"$orig_args\"" ;;
esac
done
ip_check_table "route"
[ -n "$_prefix" ] || not_implemented "ip route without inet prefix in \"$orig_args\""
- [ -n "$_dev" ] || not_implemented "ip route without \"dev\" in \"$orig_args\""
+ # This can't be easily deduced, so print some garbage.
+ [ -n "$_dev" ] || _dev="ethXXX"
# Alias or add missing bits
case "$_prefix" in
@@ -517,14 +528,65 @@ ip_route_add ()
(
flock 0
- if [ -n "$_gw" ] ; then
- echo "${_prefix} via ${_gw} dev ${_dev} "
- else
- echo "${_prefix} dev ${_dev} scope link "
- fi >>"$_f"
+ _out="${_prefix} "
+ [ -z "$_gw" ] || _out="${_out}via ${_gw} "
+ [ -z "$_dev" ] || _out="${_out}dev ${_dev} "
+ [ -n "$_gw" ] || _out="${_out} scope link "
+ [ -z "$_metric" ] || _out="${_out} metric ${_metric} "
+ echo "$_out" >>"$_f"
) <"$_f"
}
+ip_route_del ()
+{
+ _prefix=""
+ _dev=""
+ _gw=""
+ _table=""
+ _metric=""
+
+ while [ -n "$1" ] ; do
+ case "$1" in
+ *.*.*.*/*|*.*.*.*) _prefix="$1" ; shift 1 ;;
+ local) _prefix="$2" ; shift 2 ;;
+ dev) _dev="$2" ; shift 2 ;;
+ via) _gw="$2" ; shift 2 ;;
+ table) _table="$2" ; shift 2 ;;
+ metric) _metric="$2" ; shift 2 ;;
+ *) not_implemented "$1 in \"$orig_args\"" ;;
+ esac
+ done
+
+ ip_check_table "route"
+ [ -n "$_prefix" ] || not_implemented "ip route without inet prefix in \"$orig_args\""
+ # This can't be easily deduced, so print some garbage.
+ [ -n "$_dev" ] || _dev="ethXXX"
+
+ # Alias or add missing bits
+ case "$_prefix" in
+ 0.0.0.0/0) _prefix="default" ;;
+ */*) : ;;
+ *) _prefix="${_prefix}/32" ;;
+ esac
+
+ _f="$FAKE_IP_STATE/routes/${_table}"
+ mkdir -p "$FAKE_IP_STATE/routes"
+ touch "$_f"
+
+ (
+ flock 0
+
+ # Escape some dots
+ [ -z "$_gw" ] || _gw=$(echo "$_gw" | sed -e 's@\.@\\.@g')
+ _prefix=$(echo "$_prefix" | sed -e 's@\.@\\.@g' -e 's@/@\\/@')
+
+ _re="^${_prefix}\>.*"
+ [ -z "$_gw" ] || _re="${_re}\<via ${_gw}\>.*"
+ [ -z "$_dev" ] || _re="${_re}\<dev ${_dev}\>.*"
+ [ -z "$_metric" ] || _re="${_re}.*\<metric ${_metric}\>.*"
+ sed -i -e "/${_re}/d" "$_f"
+ ) <"$_f"
+}
######################################################################