ctdb-tests: Avoid ShellCheck warnings
[Samba.git] / ctdb / tests / UNIT / eventscripts / scripts / 11.natgw.sh
blob3b19895127916bac51ff8ba7abc2a9ec777c028d
1 setup()
3 debug "Setting up NAT gateway"
5 natgw_nodes="${CTDB_BASE}/natgw_nodes"
7 ctdb_set_pnn
10 # A separate function for this makes sense because it can be done
11 # multiple times per test
12 setup_ctdb_natgw()
14 # Read from stdin
15 while read -r _ip _opts; do
16 case "$_opts" in
17 leader)
18 export FAKE_CTDB_NATGW_LEADER="$_ip"
19 echo "$_ip"
21 follower-only)
22 printf "%s\tfollower-only\n" "$_ip"
25 echo "$_ip"
27 esac
28 done >"$natgw_nodes"
30 # Assume all of the nodes are on a /24 network and have IPv4
31 # addresses:
32 read -r _ip <"$natgw_nodes"
34 setup_script_options <<EOF
35 CTDB_NATGW_NODES="$natgw_nodes"
36 CTDB_NATGW_PRIVATE_NETWORK="${_ip%.*}.0/24"
37 # These are fixed. Probably don't use the same network for the
38 # private node IPs. To unset the default gateway just set it to
39 # "". :-)
40 CTDB_NATGW_PUBLIC_IP="10.1.1.121/24"
41 CTDB_NATGW_PUBLIC_IFACE="eth1"
42 CTDB_NATGW_DEFAULT_GATEWAY="10.1.1.254"
43 EOF
46 ok_natgw_leader_ip_addr_show()
48 _mac=$(echo "$CTDB_NATGW_PUBLIC_IFACE" |
49 cksum |
50 sed -r -e 's@(..)(..)(..).*@fe:fe:fe:\1:\2:\3@')
52 # This is based on CTDB_NATGW_PUBLIC_IP
53 _brd="10.1.1.255"
55 ok <<EOF
56 1: ${CTDB_NATGW_PUBLIC_IFACE}: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
57 link/ether ${_mac} brd ff:ff:ff:ff:ff:ff
58 inet ${CTDB_NATGW_PUBLIC_IP} brd ${_brd} scope global ${CTDB_NATGW_PUBLIC_IFACE}
59 valid_lft forever preferred_lft forever
60 EOF
63 ok_natgw_follower_ip_addr_show()
65 _mac=$(echo "$CTDB_NATGW_PUBLIC_IFACE" |
66 cksum |
67 sed -r -e 's@(..)(..)(..).*@fe:fe:fe:\1:\2:\3@')
69 ok <<EOF
70 1: ${CTDB_NATGW_PUBLIC_IFACE}: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
71 link/ether ${_mac} brd ff:ff:ff:ff:ff:ff
72 EOF
75 ok_natgw_leader_static_routes()
77 _nl="
79 _t=""
80 for _i in $CTDB_NATGW_STATIC_ROUTES; do
81 # This is intentionally different to the code in 11.natgw ;-)
82 case "$_i" in
83 *@*)
84 _net=$(echo "$_i" | sed -e 's|@.*||')
85 _gw=$(echo "$_i" | sed -e 's|.*@||')
88 _net="$_i"
89 _gw="$CTDB_NATGW_DEFAULT_GATEWAY"
91 esac
93 [ -n "$_gw" ] || continue
94 _t="${_t}${_t:+${_nl}}"
95 _t="${_t}${_net} via ${_gw} dev ethXXX metric 10 "
96 done
97 _t=$(echo "$_t" | sort)
98 ok "$_t"
101 ok_natgw_follower_static_routes()
103 _nl="
105 _t=""
106 for _i in $CTDB_NATGW_STATIC_ROUTES; do
107 # This is intentionally different to the code in 11.natgw ;-)
108 _net=$(echo "$_i" | sed -e 's|@.*||')
110 # The interface for the private network isn't
111 # specified as part of the NATGW configuration and
112 # isn't part of the command to add the route. It is
113 # implicitly added by "ip route" but our stub doesn't
114 # do this and adds "ethXXX".
115 _t="${_t}${_t:+${_nl}}"
116 _t="${_t}${_net} via ${FAKE_CTDB_NATGW_LEADER} dev ethXXX metric 10 "
117 done
118 _t=$(echo "$_t" | sort)
119 ok "$_t"