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
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
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
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
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
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
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
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
. "${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
. "${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
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
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
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:
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
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
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:
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
echo "$_code $_status $_err_out" >"$FAKE_CTDB_SCRIPTSTATUS/$script"
}
+######################################################################
+
setup_ctdb_policy_routing ()
{
export CTDB_PER_IP_ROUTING_CONF="$CTDB_BASE/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