ctdb-tests: Move eventd tests to UNIT/ subdirectory
[samba.git] / ctdb / tests / eventscripts / scripts / 13.per_ip_routing.sh
1 setup ()
2 {
3         setup_public_addresses
4
5         service_name="per_ip_routing"
6
7         setup_script_options <<EOF
8 CTDB_PER_IP_ROUTING_CONF="${CTDB_BASE}/policy_routing"
9 CTDB_PER_IP_ROUTING_RULE_PREF=100
10 CTDB_PER_IP_ROUTING_TABLE_ID_LOW=1000
11 CTDB_PER_IP_ROUTING_TABLE_ID_HIGH=2000
12 EOF
13
14         # Tests need to create and populate this file
15         rm -f "$CTDB_PER_IP_ROUTING_CONF"
16 }
17
18 # Create policy routing configuration in $CTDB_PER_IP_ROUTING_CONF.
19 # $1 is the number of assigned IPs to use (<num>, all), defaulting to
20 # 1.  If $2 is "default" then a default route is also added.
21 create_policy_routing_config ()
22 {
23         _num_ips="${1:-1}"
24         _should_add_default="$2"
25
26         ctdb_get_my_public_addresses |
27         if [ "$_num_ips" = "all" ] ; then
28                 cat
29         else
30                 { head -n "$_num_ips" ; cat >/dev/null ; }
31         fi |
32         while read _dev _ip _bits ; do
33                 _net=$(ipv4_host_addr_to_net "$_ip" "$_bits")
34                 _gw="${_net%.*}.254" # a dumb, calculated default
35
36                 echo "$_ip $_net"
37
38                 if [ "$_should_add_default" = "default" ] ; then
39                         echo "$_ip 0.0.0.0/0 $_gw"
40                 fi
41         done >"$CTDB_PER_IP_ROUTING_CONF"
42 }