summaryrefslogtreecommitdiff
path: root/ctdb/tests
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2015-08-04 17:03:50 +1000
committerAmitay Isaacs <amitay@samba.org>2015-08-07 08:37:38 +0200
commiteba12122ccce602aede7756b8f91d34fe927d2c0 (patch)
tree832a1a2cb67e839f07bce592ca5a637cf74332e0 /ctdb/tests
parent5a6a9326e58c4ebabd351326493d5d320e0130e6 (diff)
downloadsamba-eba12122ccce602aede7756b8f91d34fe927d2c0.tar.gz
ctdb-tests: Add a policy routing test with misconfiguration
To support this, extend the "ip route add" stub to detect duplicate routes. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com> Autobuild-User(master): Amitay Isaacs <amitay@samba.org> Autobuild-Date(master): Fri Aug 7 08:37:38 CEST 2015 on sn-devel-104
Diffstat (limited to 'ctdb/tests')
-rwxr-xr-xctdb/tests/eventscripts/13.per_ip_routing.023.sh26
-rwxr-xr-xctdb/tests/eventscripts/stubs/ip10
2 files changed, 36 insertions, 0 deletions
diff --git a/ctdb/tests/eventscripts/13.per_ip_routing.023.sh b/ctdb/tests/eventscripts/13.per_ip_routing.023.sh
new file mode 100755
index 00000000000..336e129d762
--- /dev/null
+++ b/ctdb/tests/eventscripts/13.per_ip_routing.023.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+define_test "1 IP configured, broken configuration, takeip"
+
+setup_ctdb
+setup_ctdb_policy_routing
+
+# 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
+ # Now add configuration breakage by changing default route into a
+ # link local route with a gateway
+ net=$(ipv4_host_addr_to_net "$ip" "$bits")
+ sed -i -e "s@0\.0\.0\.0/0@${net}@" "$CTDB_PER_IP_ROUTING_CONF"
+
+ ok <<EOF
+RTNETLINK answers: File exists
+add_routing_for_ip: failed to add route: ${net} via ${net%.*}.254 dev ${dev} table ctdb.${ip}
+EOF
+ simple_test_event "takeip" $dev $ip $bits
+done
diff --git a/ctdb/tests/eventscripts/stubs/ip b/ctdb/tests/eventscripts/stubs/ip
index 59219d2c4f5..325c892722d 100755
--- a/ctdb/tests/eventscripts/stubs/ip
+++ b/ctdb/tests/eventscripts/stubs/ip
@@ -573,6 +573,16 @@ ip_route_add ()
mkdir -p "$FAKE_IP_STATE/routes"
touch "$_f"
+ # Check for duplicate
+ _prefix_regexp=$(echo "^${_prefix}" | sed -e 's@\.@\\.@g')
+ if [ -n "$_metric" ] ; then
+ _prefix_regexp="${_prefix_regexp} .*metric ${_metric} "
+ fi
+ if grep -q "$_prefix_regexp" "$_f" ; then
+ echo "RTNETLINK answers: File exists" >&2
+ exit 1
+ fi
+
(
flock 0