--- /dev/null
+#!/bin/sh
+
+. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
+
+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
+
+simple_test_command dump_routes
--- /dev/null
+#!/bin/sh
+
+. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
+
+define_test "missing config, no takeip, ipreallocated"
+
+setup_ctdb
+setup_ctdb_policy_routing
+
+required_result 1 <<EOF
+error: CTDB_PER_IP_ROUTING_CONF=/home/martins/samba/ctdb/tests/eventscripts/etc-ctdb/policy_routing file not found
+EOF
+
+simple_test_event "ipreallocated"
--- /dev/null
+#!/bin/sh
+
+. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
+
+define_test "empty config, ipreallocated"
+
+setup_ctdb
+setup_ctdb_policy_routing
+
+touch "$CTDB_PER_IP_ROUTING_CONF"
+
+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
--- /dev/null
+#!/bin/sh
+
+. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
+
+define_test "empty config, takeip"
+
+setup_ctdb
+setup_ctdb_policy_routing
+
+touch "$CTDB_PER_IP_ROUTING_CONF"
+
+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
--- /dev/null
+#!/bin/sh
+
+. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
+
+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
+
+ ok_null
+
+ simple_test_event "takeip" $dev $ip $bits
+
+ 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
+}
--- /dev/null
+#!/bin/sh
+
+. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
+
+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
+
+ ok_null
+
+ simple_test_event "takeip" $dev $ip $bits
+
+ ok_null
+
+ 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
+}
--- /dev/null
+#!/bin/sh
+
+. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
+
+define_test "1 IP configured, 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
+
+ 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
+}
+
--- /dev/null
+#!/bin/sh
+
+. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
+
+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
+
+ ok_null
+
+ simple_test_event "takeip" $dev $ip $bits
+
+ ok_null
+
+ simple_test_event "takeip" $dev $ip $bits
+
+ 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
+}
--- /dev/null
+#!/bin/sh
+
+. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
+
+define_test "All IPs configured, takeip"
+
+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"
+
+ctdb_get_1_public_address |
+{
+ read dev ip bits
+
+ net=$(ipv4_host_addr_to_net "$ip" "$bits")
+ gw="${net%.*}.1" # a dumb, calculated default
+
+ ok_null
+
+ simple_test_event "takeip" $dev $ip $bits
+
+ 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
+}
--- /dev/null
+#!/bin/sh
+
+. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
+
+define_test "All IPs configured, takeip all on node"
+
+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"
+
+# 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
+
+ simple_test_command dump_routes
+}
--- /dev/null
+#!/bin/sh
+
+. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
+
+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
+
+ 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
+
+ simple_test_command dump_routes
+}
--- /dev/null
+#!/bin/sh
+
+. "${EVENTSCRIPTS_TESTS_DIR}/common.sh"
+
+define_test "1 IP configured, takeip, releaseip, ipreallocated"
+
+# This partly tests the test infrastructure. If the (stub) "ctdb
+# moveip" doesn't do anything then the IP being released will still be
+# on the node and the ipreallocated event will add the routes back.
+
+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
+
+ 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"
+
+ 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
+}