summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2012-10-10 14:48:59 +1100
committerMartin Schwenke <martin@meltin.net>2012-10-11 12:10:45 +1100
commitcfef70236325c0edd9f1253ea801bfb0bf6f529e (patch)
treefbb36947bb2e68773c5827111c0acb9ae96456c0
parent74843dadada9995efc5f5f3c8458ec58bcf6bc05 (diff)
downloadsamba-cfef70236325c0edd9f1253ea801bfb0bf6f529e.tar.gz
samba-cfef70236325c0edd9f1253ea801bfb0bf6f529e.tar.xz
samba-cfef70236325c0edd9f1253ea801bfb0bf6f529e.zip
tests/eventscripts: add extra infrastructure for policy routing tests
Less copying and pasting is a good thing... Signed-off-by: Martin Schwenke <martin@meltin.net> (This used to be ctdb commit 7d4b8cce96f33fff647a0c9d259c121dfc8403e9)
-rwxr-xr-xctdb/tests/eventscripts/13.per_ip_routing.001.sh13
-rwxr-xr-xctdb/tests/eventscripts/13.per_ip_routing.002.sh2
-rwxr-xr-xctdb/tests/eventscripts/13.per_ip_routing.003.sh15
-rwxr-xr-xctdb/tests/eventscripts/13.per_ip_routing.004.sh13
-rwxr-xr-xctdb/tests/eventscripts/13.per_ip_routing.005.sh33
-rwxr-xr-xctdb/tests/eventscripts/13.per_ip_routing.006.sh31
-rwxr-xr-xctdb/tests/eventscripts/13.per_ip_routing.007.sh36
-rwxr-xr-xctdb/tests/eventscripts/13.per_ip_routing.008.sh34
-rwxr-xr-xctdb/tests/eventscripts/13.per_ip_routing.009.sh39
-rwxr-xr-xctdb/tests/eventscripts/13.per_ip_routing.010.sh50
-rwxr-xr-xctdb/tests/eventscripts/13.per_ip_routing.011.sh39
-rwxr-xr-xctdb/tests/eventscripts/13.per_ip_routing.012.sh30
-rwxr-xr-xctdb/tests/eventscripts/13.per_ip_routing.013.sh26
-rwxr-xr-xctdb/tests/eventscripts/13.per_ip_routing.014.sh33
-rwxr-xr-xctdb/tests/eventscripts/13.per_ip_routing.015.sh21
-rw-r--r--ctdb/tests/eventscripts/scripts/local.sh72
16 files changed, 170 insertions, 317 deletions
diff --git a/ctdb/tests/eventscripts/13.per_ip_routing.001.sh b/ctdb/tests/eventscripts/13.per_ip_routing.001.sh
index 3d22864edf..8523c1010f 100755
--- a/ctdb/tests/eventscripts/13.per_ip_routing.001.sh
+++ b/ctdb/tests/eventscripts/13.per_ip_routing.001.sh
@@ -6,11 +6,10 @@ define_test "not configured"
setup_ctdb
-ok <<EOF
-# ip rule show
-0: from all lookup local
-32766: from all lookup main
-32767: from all lookup default
-EOF
+ok_null
+simple_test_event "takeip"
-simple_test_command dump_routes
+ok_null
+simple_test_event "ipreallocate"
+
+check_routes 0
diff --git a/ctdb/tests/eventscripts/13.per_ip_routing.002.sh b/ctdb/tests/eventscripts/13.per_ip_routing.002.sh
index 4d5c68cce9..d6320c65d8 100755
--- a/ctdb/tests/eventscripts/13.per_ip_routing.002.sh
+++ b/ctdb/tests/eventscripts/13.per_ip_routing.002.sh
@@ -7,6 +7,8 @@ define_test "missing config file"
setup_ctdb
setup_ctdb_policy_routing
+# Error because policy routing is configured but the configuration
+# file is missing.
required_result 1 <<EOF
error: CTDB_PER_IP_ROUTING_CONF=${CTDB_BASE}/policy_routing file not found
EOF
diff --git a/ctdb/tests/eventscripts/13.per_ip_routing.003.sh b/ctdb/tests/eventscripts/13.per_ip_routing.003.sh
index c1e0d01294..bb2c4b70fb 100755
--- a/ctdb/tests/eventscripts/13.per_ip_routing.003.sh
+++ b/ctdb/tests/eventscripts/13.per_ip_routing.003.sh
@@ -7,18 +7,11 @@ define_test "empty config, ipreallocated"
setup_ctdb
setup_ctdb_policy_routing
-touch "$CTDB_PER_IP_ROUTING_CONF"
+create_policy_routing_config 0
+# ipreallocated should silently add any missing routes
ok_null
-
-# ipreallocated should add any missing routes
simple_test_event "ipreallocated"
-ok <<EOF
-# ip rule show
-0: from all lookup local
-32766: from all lookup main
-32767: from all lookup default
-EOF
-
-simple_test_command dump_routes
+# empty configuration file should mean there are no routes
+check_routes 0
diff --git a/ctdb/tests/eventscripts/13.per_ip_routing.004.sh b/ctdb/tests/eventscripts/13.per_ip_routing.004.sh
index 88ffac369c..4595313b71 100755
--- a/ctdb/tests/eventscripts/13.per_ip_routing.004.sh
+++ b/ctdb/tests/eventscripts/13.per_ip_routing.004.sh
@@ -7,19 +7,12 @@ define_test "empty config, takeip"
setup_ctdb
setup_ctdb_policy_routing
-touch "$CTDB_PER_IP_ROUTING_CONF"
+create_policy_routing_config 0
public_address=$(ctdb_get_1_public_address)
ok_null
-
simple_test_event "takeip" $public_address
-ok <<EOF
-# ip rule show
-0: from all lookup local
-32766: from all lookup main
-32767: from all lookup default
-EOF
-
-simple_test_command dump_routes
+# empty configuration file should mean there are no routes
+check_routes 0
diff --git a/ctdb/tests/eventscripts/13.per_ip_routing.005.sh b/ctdb/tests/eventscripts/13.per_ip_routing.005.sh
index 822f39f044..9495cc54ce 100755
--- a/ctdb/tests/eventscripts/13.per_ip_routing.005.sh
+++ b/ctdb/tests/eventscripts/13.per_ip_routing.005.sh
@@ -7,32 +7,15 @@ define_test "1 IP configured, takeip"
setup_ctdb
setup_ctdb_policy_routing
-ctdb_get_1_public_address |
-{
- read dev ip bits
-
- net=$(ipv4_host_addr_to_net "$ip" "$bits")
- gw="${net%.*}.1" # a dumb, calculated default
-
- cat >"$CTDB_PER_IP_ROUTING_CONF" <<EOF
-$ip $net
-$ip 0.0.0.0/0 $gw
-EOF
+# Configuration for 1 IP
+create_policy_routing_config 1 default
+# takeip should add routes for the given address
+ctdb_get_1_public_address |
+while read dev ip bits ; do
ok_null
-
simple_test_event "takeip" $dev $ip $bits
+done
- ok <<EOF
-# ip rule show
-0: from all lookup local
-${CTDB_PER_IP_ROUTING_RULE_PREF}: from $ip lookup ctdb.$ip
-32766: from all lookup main
-32767: from all lookup default
-# ip route show table ctdb.$ip
-$net dev $dev scope link
-default via $gw dev $dev
-EOF
-
- simple_test_command dump_routes
-}
+# Should have routes for 1 IP
+check_routes 1 default
diff --git a/ctdb/tests/eventscripts/13.per_ip_routing.006.sh b/ctdb/tests/eventscripts/13.per_ip_routing.006.sh
index ed9df846fe..b93b6cdea1 100755
--- a/ctdb/tests/eventscripts/13.per_ip_routing.006.sh
+++ b/ctdb/tests/eventscripts/13.per_ip_routing.006.sh
@@ -7,32 +7,19 @@ define_test "1 IP configured, takeip, releaseip"
setup_ctdb
setup_ctdb_policy_routing
-ctdb_get_1_public_address |
-{
- read dev ip bits
-
- net=$(ipv4_host_addr_to_net "$ip" "$bits")
- gw="${net%.*}.1" # a dumb, calculated default
-
- cat >"$CTDB_PER_IP_ROUTING_CONF" <<EOF
-$ip $net
-$ip 0.0.0.0/0 $gw
-EOF
+# create config for 1 IP
+create_policy_routing_config 1 default
+ctdb_get_1_public_address |
+while read dev ip bits ; do
+ # takeip adds routes
ok_null
-
simple_test_event "takeip" $dev $ip $bits
+ # releaseip removes routes
ok_null
-
simple_test_event "releaseip" $dev $ip $bits
+done
- ok <<EOF
-# ip rule show
-0: from all lookup local
-32766: from all lookup main
-32767: from all lookup default
-EOF
-
- simple_test_command dump_routes
-}
+# should have no routes
+check_routes 0
diff --git a/ctdb/tests/eventscripts/13.per_ip_routing.007.sh b/ctdb/tests/eventscripts/13.per_ip_routing.007.sh
index f7332ac50b..096bc96d99 100755
--- a/ctdb/tests/eventscripts/13.per_ip_routing.007.sh
+++ b/ctdb/tests/eventscripts/13.per_ip_routing.007.sh
@@ -7,34 +7,12 @@ define_test "1 IP configured, ipreallocated"
setup_ctdb
setup_ctdb_policy_routing
-ctdb_get_1_public_address |
-{
- read dev ip bits
+# create config for 1 IP
+create_policy_routing_config 1 default
- net=$(ipv4_host_addr_to_net "$ip" "$bits")
- gw="${net%.*}.1" # a dumb, calculated default
-
- cat >"$CTDB_PER_IP_ROUTING_CONF" <<EOF
-$ip $net
-$ip 0.0.0.0/0 $gw
-EOF
-
- ok_null
-
- # ipreallocated should add any missing routes
- simple_test_event "ipreallocated"
-
- ok <<EOF
-# ip rule show
-0: from all lookup local
-${CTDB_PER_IP_ROUTING_RULE_PREF}: from $ip lookup ctdb.$ip
-32766: from all lookup main
-32767: from all lookup default
-# ip route show table ctdb.$ip
-$net dev $dev scope link
-default via $gw dev $dev
-EOF
-
- simple_test_command dump_routes
-}
+# no takeip, but ipreallocated should add any missing routes
+ok_null
+simple_test_event "ipreallocated"
+# should have routes for 1 IP
+check_routes 1 default
diff --git a/ctdb/tests/eventscripts/13.per_ip_routing.008.sh b/ctdb/tests/eventscripts/13.per_ip_routing.008.sh
index db37cbb241..9bb0c195fd 100755
--- a/ctdb/tests/eventscripts/13.per_ip_routing.008.sh
+++ b/ctdb/tests/eventscripts/13.per_ip_routing.008.sh
@@ -7,36 +7,18 @@ define_test "1 IP configured, takeip twice"
setup_ctdb
setup_ctdb_policy_routing
-ctdb_get_1_public_address |
-{
- read dev ip bits
-
- net=$(ipv4_host_addr_to_net "$ip" "$bits")
- gw="${net%.*}.1" # a dumb, calculated default
-
- cat >"$CTDB_PER_IP_ROUTING_CONF" <<EOF
-$ip $net
-$ip 0.0.0.0/0 $gw
-EOF
+# create config for 1 IP
+create_policy_routing_config 1 default
+ctdb_get_1_public_address |
+while read dev ip bits ; do
ok_null
-
simple_test_event "takeip" $dev $ip $bits
+ # 2nd takeip event for the same IP should be a no-op
ok_null
-
simple_test_event "takeip" $dev $ip $bits
+done
- ok <<EOF
-# ip rule show
-0: from all lookup local
-${CTDB_PER_IP_ROUTING_RULE_PREF}: from $ip lookup ctdb.$ip
-32766: from all lookup main
-32767: from all lookup default
-# ip route show table ctdb.$ip
-$net dev $dev scope link
-default via $gw dev $dev
-EOF
-
- simple_test_command dump_routes
-}
+# should be routes for 1 IP
+check_routes 1 default
diff --git a/ctdb/tests/eventscripts/13.per_ip_routing.009.sh b/ctdb/tests/eventscripts/13.per_ip_routing.009.sh
index 3e33e903c2..cbea1ade61 100755
--- a/ctdb/tests/eventscripts/13.per_ip_routing.009.sh
+++ b/ctdb/tests/eventscripts/13.per_ip_routing.009.sh
@@ -2,43 +2,20 @@
. "${TEST_SCRIPTS_DIR}/unit.sh"
-define_test "All IPs configured, takeip"
+define_test "All IPs configured, takeip 1 address"
setup_ctdb
setup_ctdb_policy_routing
-ctdb_get_all_public_addresses |
-while read dev ip bits ; do
- net=$(ipv4_host_addr_to_net "$ip" "$bits")
- gw="${net%.*}.1" # a dumb, calculated default
-
- cat <<EOF
-$ip $net
-$ip 0.0.0.0/0 $gw
-EOF
-done >"$CTDB_PER_IP_ROUTING_CONF"
+# configure all addresses
+create_policy_routing_config all default
+# add routes for all 1 IP
ctdb_get_1_public_address |
-{
- read dev ip bits
-
- net=$(ipv4_host_addr_to_net "$ip" "$bits")
- gw="${net%.*}.1" # a dumb, calculated default
-
+while read dev ip bits ; do
ok_null
-
simple_test_event "takeip" $dev $ip $bits
+done
- ok <<EOF
-# ip rule show
-0: from all lookup local
-${CTDB_PER_IP_ROUTING_RULE_PREF}: from $ip lookup ctdb.$ip
-32766: from all lookup main
-32767: from all lookup default
-# ip route show table ctdb.$ip
-$net dev $dev scope link
-default via $gw dev $dev
-EOF
-
- simple_test_command dump_routes
-}
+# for 1 IP
+check_routes 1 default
diff --git a/ctdb/tests/eventscripts/13.per_ip_routing.010.sh b/ctdb/tests/eventscripts/13.per_ip_routing.010.sh
index 4704b9f04c..d11585ec51 100755
--- a/ctdb/tests/eventscripts/13.per_ip_routing.010.sh
+++ b/ctdb/tests/eventscripts/13.per_ip_routing.010.sh
@@ -2,51 +2,19 @@
. "${TEST_SCRIPTS_DIR}/unit.sh"
-define_test "All IPs configured, takeip all on node"
+define_test "All IPs configured, takeip on all nodes"
setup_ctdb
setup_ctdb_policy_routing
-# First setup the policy routing config for all possible IPs
-ctdb_get_all_public_addresses |
-while read dev ip bits ; do
- net=$(ipv4_host_addr_to_net "$ip" "$bits")
- gw="${net%.*}.1" # a dumb, calculated default
-
- cat <<EOF
-$ip $net
-$ip 0.0.0.0/0 $gw
-EOF
-done >"$CTDB_PER_IP_ROUTING_CONF"
+# create config for all IPs
+create_policy_routing_config all default
-# Now do a takeip for each IP on the "current" node
ctdb_get_my_public_addresses |
-{
- policy_rules=""
- policy_routes=""
- while read dev ip bits ; do
-
- net=$(ipv4_host_addr_to_net "$ip" "$bits")
- gw="${net%.*}.1" # a dumb, calculated default
-
- ok_null
-
- simple_test_event "takeip" $dev $ip $bits
-
- 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
-default via $gw dev $dev "
- done
-
- ok <<EOF
-# ip rule show
-0: from all lookup local ${policy_rules}
-32766: from all lookup main
-32767: from all lookup default ${policy_routes}
-EOF
+while read dev ip bits ; do
+ ok_null
+ simple_test_event "takeip" $dev $ip $bits
+done
- simple_test_command dump_routes
-}
+# should have routes for all IPs
+check_routes all default
diff --git a/ctdb/tests/eventscripts/13.per_ip_routing.011.sh b/ctdb/tests/eventscripts/13.per_ip_routing.011.sh
index 65adbb5d5a..d8ec9ac210 100755
--- a/ctdb/tests/eventscripts/13.per_ip_routing.011.sh
+++ b/ctdb/tests/eventscripts/13.per_ip_routing.011.sh
@@ -6,36 +6,15 @@ define_test "__auto_link_local__, takeip all on node"
setup_ctdb
setup_ctdb_policy_routing
-# Override to do link local fu
-CTDB_PER_IP_ROUTING_CONF="__auto_link_local__"
-# Do a takeip for each IP on the "current" node
-ctdb_get_my_public_addresses |
-{
- policy_rules=""
- policy_routes=""
- while read dev ip bits ; do
-
- net=$(ipv4_host_addr_to_net "$ip" "$bits")
- gw="${net%.*}.1" # a dumb, calculated default
-
- ok_null
+# do link local fu instead of creating configuration
+export CTDB_PER_IP_ROUTING_CONF="__auto_link_local__"
- simple_test_event "takeip" $dev $ip $bits
-
- 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 "
- done
-
- ok <<EOF
-# ip rule show
-0: from all lookup local ${policy_rules}
-32766: from all lookup main
-32767: from all lookup default ${policy_routes}
-EOF
+# add routes for all addresses
+ctdb_get_my_public_addresses |
+while read dev ip bits ; do
+ ok_null
+ simple_test_event "takeip" $dev $ip $bits
+done
- simple_test_command dump_routes
-}
+check_routes all
diff --git a/ctdb/tests/eventscripts/13.per_ip_routing.012.sh b/ctdb/tests/eventscripts/13.per_ip_routing.012.sh
index 198551f877..6c8a6ab4b3 100755
--- a/ctdb/tests/eventscripts/13.per_ip_routing.012.sh
+++ b/ctdb/tests/eventscripts/13.per_ip_routing.012.sh
@@ -11,38 +11,20 @@ define_test "1 IP configured, takeip, releaseip, ipreallocated"
setup_ctdb
setup_ctdb_policy_routing
-ctdb_get_1_public_address |
-{
- read dev ip bits
-
- net=$(ipv4_host_addr_to_net "$ip" "$bits")
- gw="${net%.*}.1" # a dumb, calculated default
-
- cat >"$CTDB_PER_IP_ROUTING_CONF" <<EOF
-$ip $net
-$ip 0.0.0.0/0 $gw
-EOF
+create_policy_routing_config 1 default
+ctdb_get_1_public_address |
+while read dev ip bits ; do
ok_null
-
simple_test_event "takeip" $dev $ip $bits
ok_null
-
ctdb moveip $ip 1
simple_test_event "releaseip" $dev $ip $bits
ok_null
-
- # This will cause any
simple_test_event "ipreallocated"
+done
- ok <<EOF
-# ip rule show
-0: from all lookup local
-32766: from all lookup main
-32767: from all lookup default
-EOF
-
- simple_test_command dump_routes
-}
+# all routes should have been removed and not added back
+check_routes 0
diff --git a/ctdb/tests/eventscripts/13.per_ip_routing.013.sh b/ctdb/tests/eventscripts/13.per_ip_routing.013.sh
index 5c07632023..567622edd9 100755
--- a/ctdb/tests/eventscripts/13.per_ip_routing.013.sh
+++ b/ctdb/tests/eventscripts/13.per_ip_routing.013.sh
@@ -7,18 +7,10 @@ define_test "1 IP configured, releaseip of unassigned"
setup_ctdb
setup_ctdb_policy_routing
-ctdb_get_1_public_address |
-{
- read dev ip bits
-
- net=$(ipv4_host_addr_to_net "$ip" "$bits")
- gw="${net%.*}.1" # a dumb, calculated default
-
- cat >"$CTDB_PER_IP_ROUTING_CONF" <<EOF
-$ip $net
-$ip 0.0.0.0/0 $gw
-EOF
+create_policy_routing_config 1 default
+ctdb_get_1_public_address |
+while read dev ip bits ; do
ok <<EOF
WARNING: Failed to delete policy routing rule
Command "ip rule del from $ip pref $CTDB_PER_IP_ROUTING_RULE_PREF table ctdb.$ip" failed:
@@ -26,13 +18,7 @@ WARNING: Failed to delete policy routing rule
EOF
simple_test_event "releaseip" $dev $ip $bits
+done
- ok <<EOF
-# ip rule show
-0: from all lookup local
-32766: from all lookup main
-32767: from all lookup default
-EOF
-
- simple_test_command dump_routes
-}
+# there should be no routes
+check_routes 0
diff --git a/ctdb/tests/eventscripts/13.per_ip_routing.014.sh b/ctdb/tests/eventscripts/13.per_ip_routing.014.sh
index 9327264ecd..ee08c36fa3 100755
--- a/ctdb/tests/eventscripts/13.per_ip_routing.014.sh
+++ b/ctdb/tests/eventscripts/13.per_ip_routing.014.sh
@@ -10,38 +10,21 @@ define_test "1 IP configured, takeip, moveip, ipreallocated"
setup_ctdb
setup_ctdb_policy_routing
-ctdb_get_1_public_address |
-{
- read dev ip bits
-
- net=$(ipv4_host_addr_to_net "$ip" "$bits")
- gw="${net%.*}.1" # a dumb, calculated default
-
- cat >"$CTDB_PER_IP_ROUTING_CONF" <<EOF
-$ip $net
-$ip 0.0.0.0/0 $gw
-EOF
+create_policy_routing_config 1 default
+ctdb_get_1_public_address |
+while read dev ip bits ; do
ok_null
-
# Set up the routes for an IP that we have
simple_test_event "takeip" $dev $ip $bits
# Now move that IPs but don't run the associated "releaseip"
ctdb moveip $ip 1
- ok <<EOF
-Removing ip rule/routes for unhosted public address 10.0.0.3
-EOF
-
+ # This should handle removal of the routes
+ ok "Removing ip rule/routes for unhosted public address $ip"
simple_test_event "ipreallocated"
+done
- ok <<EOF
-# ip rule show
-0: from all lookup local
-32766: from all lookup main
-32767: from all lookup default
-EOF
-
- simple_test_command dump_routes
-}
+# no routes left
+check_routes 0
diff --git a/ctdb/tests/eventscripts/13.per_ip_routing.015.sh b/ctdb/tests/eventscripts/13.per_ip_routing.015.sh
index 5258438b00..2b9ecba053 100755
--- a/ctdb/tests/eventscripts/13.per_ip_routing.015.sh
+++ b/ctdb/tests/eventscripts/13.per_ip_routing.015.sh
@@ -9,18 +9,12 @@ setup_ctdb_policy_routing
export IP_ROUTE_BAD_TABLE_ID=true
+create_policy_routing_config 1 default
+
ctdb_get_1_public_address |
{
read dev ip bits
- net=$(ipv4_host_addr_to_net "$ip" "$bits")
- gw="${net%.*}.1" # a dumb, calculated default
-
- cat >"$CTDB_PER_IP_ROUTING_CONF" <<EOF
-$ip $net
-$ip 0.0.0.0/0 $gw
-EOF
-
ok <<EOF
WARNING: Failed to delete policy routing rule
Command "ip rule del from $ip pref $CTDB_PER_IP_ROUTING_RULE_PREF table ctdb.$ip" failed:
@@ -29,13 +23,8 @@ WARNING: Failed to delete policy routing rule
EOF
simple_test_event "releaseip" $dev $ip $bits
+}
- ok <<EOF
-# ip rule show
-0: from all lookup local
-32766: from all lookup main
-32767: from all lookup default
-EOF
- simple_test_command dump_routes
-}
+# there should be no routes
+check_routes 0
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 (<num>, 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 (<num>, 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 <<EOF
+# ip rule show
+0: from all lookup local ${_policy_rules}
+32766: from all lookup main
+32767: from all lookup default ${_policy_routes}
+EOF
+
+ simple_test_command dump_routes
+ }
+}
+
######################################################################
# Samba/winbind fakery