1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-27 22:50:26 +03:00

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)
This commit is contained in:
Martin Schwenke 2012-10-10 14:48:59 +11:00
parent 74843dadad
commit cfef702363
16 changed files with 171 additions and 318 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -7,32 +7,15 @@ define_test "1 IP configured, 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 |
{
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
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

View File

@ -7,32 +7,19 @@ define_test "1 IP configured, takeip, releaseip"
setup_ctdb
setup_ctdb_policy_routing
# create config for 1 IP
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
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

View File

@ -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

View File

@ -7,36 +7,18 @@ define_test "1 IP configured, takeip twice"
setup_ctdb
setup_ctdb_policy_routing
# create config for 1 IP
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
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

View File

@ -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

View File

@ -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
# create config for all IPs
create_policy_routing_config all 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
while read dev ip bits ; do
ok_null
simple_test_event "takeip" $dev $ip $bits
done
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
}
# should have routes for all IPs
check_routes all default

View File

@ -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
# do link local fu instead of creating configuration
export CTDB_PER_IP_ROUTING_CONF="__auto_link_local__"
# add routes for all addresses
ctdb_get_my_public_addresses |
{
policy_rules=""
policy_routes=""
while read dev ip bits ; do
while read dev ip bits ; do
ok_null
simple_test_event "takeip" $dev $ip $bits
done
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
}
check_routes all

View File

@ -11,38 +11,20 @@ define_test "1 IP configured, takeip, releaseip, ipreallocated"
setup_ctdb
setup_ctdb_policy_routing
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
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

View File

@ -7,18 +7,10 @@ define_test "1 IP configured, releaseip of unassigned"
setup_ctdb
setup_ctdb_policy_routing
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
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

View File

@ -10,38 +10,21 @@ define_test "1 IP configured, takeip, moveip, ipreallocated"
setup_ctdb
setup_ctdb_policy_routing
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
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

View File

@ -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

View File

@ -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