From cfef70236325c0edd9f1253ea801bfb0bf6f529e Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Wed, 10 Oct 2012 14:48:59 +1100 Subject: tests/eventscripts: add extra infrastructure for policy routing tests Less copying and pasting is a good thing... Signed-off-by: Martin Schwenke (This used to be ctdb commit 7d4b8cce96f33fff647a0c9d259c121dfc8403e9) --- ctdb/tests/eventscripts/scripts/local.sh | 72 ++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'ctdb/tests/eventscripts/scripts') diff --git a/ctdb/tests/eventscripts/scripts/local.sh b/ctdb/tests/eventscripts/scripts/local.sh index 56d09fa980..9e746b52d1 100644 --- a/ctdb/tests/eventscripts/scripts/local.sh +++ b/ctdb/tests/eventscripts/scripts/local.sh @@ -364,6 +364,8 @@ ctdb_fake_scriptstatus () echo "$_code $_status $_err_out" >"$FAKE_CTDB_SCRIPTSTATUS/$script" } +###################################################################### + setup_ctdb_policy_routing () { export CTDB_PER_IP_ROUTING_CONF="$CTDB_BASE/policy_routing" @@ -375,6 +377,76 @@ setup_ctdb_policy_routing () rm -f "$CTDB_PER_IP_ROUTING_CONF" } +# Create policy routing configuration in $CTDB_PER_IP_ROUTING_CONF. +# $1 is the number of assigned IPs to use (, all), defaulting to +# 1. If $2 is "default" then a default route is also added. +create_policy_routing_config () +{ + _num_ips="${1:-1}" + _should_add_default="$2" + + ctdb_get_my_public_addresses | + if [ "$_num_ips" = "all" ] ; then + cat + else + head -n "$_num_ips" + fi | + while read _dev _ip _bits ; do + _net=$(ipv4_host_addr_to_net "$_ip" "$_bits") + _gw="${_net%.*}.1" # a dumb, calculated default + + echo "$_ip $_net" + + if [ "$_should_add_default" = "default" ] ; then + echo "$_ip 0.0.0.0/0 $_gw" + fi + done >"$CTDB_PER_IP_ROUTING_CONF" +} + +# Check the routes against those that are expected. $1 is the number +# of assigned IPs to use (, all), defaulting to 1. If $2 is +# "default" then expect default routes to have been added. +check_routes () +{ + _num_ips="${1:-1}" + _should_add_default="$2" + + _policy_rules="" + _policy_routes="" + + ctdb_get_my_public_addresses | + if [ "$_num_ips" = "all" ] ; then + cat + else + head -n "$_num_ips" + fi | { + while read _dev _ip _bits ; do + _net=$(ipv4_host_addr_to_net "$_ip" "$_bits") + _gw="${_net%.*}.1" # a dumb, calculated default + + _policy_rules="${_policy_rules} +${CTDB_PER_IP_ROUTING_RULE_PREF}: from $_ip lookup ctdb.$_ip " + _policy_routes="${_policy_routes} +# ip route show table ctdb.$_ip +$_net dev $_dev scope link " + + if [ "$_should_add_default" = "default" ] ; then + _policy_routes="${_policy_routes} +default via $_gw dev $_dev " + fi + done + + ok <