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