Tests - eventscripts - initial policy routing tests
authorMartin Schwenke <martin@meltin.net>
Tue, 20 Mar 2012 06:22:02 +0000 (17:22 +1100)
committerMartin Schwenke <martin@meltin.net>
Thu, 22 Mar 2012 04:30:27 +0000 (15:30 +1100)
Signed-off-by: Martin Schwenke <martin@meltin.net>
12 files changed:
tests/eventscripts/multievent/13.per_ip_routing.001.sh [new file with mode: 0755]
tests/eventscripts/multievent/13.per_ip_routing.002.sh [new file with mode: 0755]
tests/eventscripts/multievent/13.per_ip_routing.003.sh [new file with mode: 0755]
tests/eventscripts/multievent/13.per_ip_routing.004.sh [new file with mode: 0755]
tests/eventscripts/multievent/13.per_ip_routing.005.sh [new file with mode: 0755]
tests/eventscripts/multievent/13.per_ip_routing.006.sh [new file with mode: 0755]
tests/eventscripts/multievent/13.per_ip_routing.007.sh [new file with mode: 0755]
tests/eventscripts/multievent/13.per_ip_routing.008.sh [new file with mode: 0755]
tests/eventscripts/multievent/13.per_ip_routing.009.sh [new file with mode: 0755]
tests/eventscripts/multievent/13.per_ip_routing.010.sh [new file with mode: 0755]
tests/eventscripts/multievent/13.per_ip_routing.011.sh [new file with mode: 0755]
tests/eventscripts/multievent/13.per_ip_routing.012.sh [new file with mode: 0755]

diff --git a/tests/eventscripts/multievent/13.per_ip_routing.001.sh b/tests/eventscripts/multievent/13.per_ip_routing.001.sh
new file mode 100755 (executable)
index 0000000..0bcf8e3
--- /dev/null
@@ -0,0 +1,16 @@
+#!/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
diff --git a/tests/eventscripts/multievent/13.per_ip_routing.002.sh b/tests/eventscripts/multievent/13.per_ip_routing.002.sh
new file mode 100755 (executable)
index 0000000..9a32df0
--- /dev/null
@@ -0,0 +1,14 @@
+#!/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"
diff --git a/tests/eventscripts/multievent/13.per_ip_routing.003.sh b/tests/eventscripts/multievent/13.per_ip_routing.003.sh
new file mode 100755 (executable)
index 0000000..832101f
--- /dev/null
@@ -0,0 +1,24 @@
+#!/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
diff --git a/tests/eventscripts/multievent/13.per_ip_routing.004.sh b/tests/eventscripts/multievent/13.per_ip_routing.004.sh
new file mode 100755 (executable)
index 0000000..49d2b4e
--- /dev/null
@@ -0,0 +1,25 @@
+#!/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
diff --git a/tests/eventscripts/multievent/13.per_ip_routing.005.sh b/tests/eventscripts/multievent/13.per_ip_routing.005.sh
new file mode 100755 (executable)
index 0000000..3ebacbe
--- /dev/null
@@ -0,0 +1,38 @@
+#!/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
+}
diff --git a/tests/eventscripts/multievent/13.per_ip_routing.006.sh b/tests/eventscripts/multievent/13.per_ip_routing.006.sh
new file mode 100755 (executable)
index 0000000..d458556
--- /dev/null
@@ -0,0 +1,38 @@
+#!/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
+}
diff --git a/tests/eventscripts/multievent/13.per_ip_routing.007.sh b/tests/eventscripts/multievent/13.per_ip_routing.007.sh
new file mode 100755 (executable)
index 0000000..53e9d38
--- /dev/null
@@ -0,0 +1,40 @@
+#!/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
+}
+
diff --git a/tests/eventscripts/multievent/13.per_ip_routing.008.sh b/tests/eventscripts/multievent/13.per_ip_routing.008.sh
new file mode 100755 (executable)
index 0000000..282ec07
--- /dev/null
@@ -0,0 +1,42 @@
+#!/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
+}
diff --git a/tests/eventscripts/multievent/13.per_ip_routing.009.sh b/tests/eventscripts/multievent/13.per_ip_routing.009.sh
new file mode 100755 (executable)
index 0000000..771651e
--- /dev/null
@@ -0,0 +1,44 @@
+#!/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
+}
diff --git a/tests/eventscripts/multievent/13.per_ip_routing.010.sh b/tests/eventscripts/multievent/13.per_ip_routing.010.sh
new file mode 100755 (executable)
index 0000000..f7caf1c
--- /dev/null
@@ -0,0 +1,52 @@
+#!/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
+}
diff --git a/tests/eventscripts/multievent/13.per_ip_routing.011.sh b/tests/eventscripts/multievent/13.per_ip_routing.011.sh
new file mode 100755 (executable)
index 0000000..18b51d4
--- /dev/null
@@ -0,0 +1,41 @@
+#!/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
+}
diff --git a/tests/eventscripts/multievent/13.per_ip_routing.012.sh b/tests/eventscripts/multievent/13.per_ip_routing.012.sh
new file mode 100755 (executable)
index 0000000..c272064
--- /dev/null
@@ -0,0 +1,48 @@
+#!/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
+}