ctdb-tests: Use setup_script_options() in 10.interface tests
[metze/samba/wip.git] / ctdb / tests / eventscripts / scripts / 10.interface.sh
1 setup ()
2 {
3         setup_public_addresses
4 }
5
6 _tcp_connections ()
7 {
8         _count="$1"
9         _sip="$2"
10         _sport="$3"
11         _cip_base="$4"
12         _cport_base="$5"
13
14         _cip_prefix="${_cip_base%.*}"
15         _cip_suffix="${_cip_base##*.}"
16
17         for _i in $(seq 1 $_count) ; do
18                 _cip_last=$((_cip_suffix + _i))
19                 _cip="${_cip_prefix}.${_cip_last}"
20                 _cport=$((_cport_base + _i))
21                 echo "${_sip}:${_sport} ${_cip}:${_cport}"
22         done
23 }
24
25 setup_tcp_connections ()
26 {
27         _t="${FAKE_NETWORK_STATE}/tcp-established"
28         export FAKE_NETSTAT_TCP_ESTABLISHED_FILE="$_t"
29         _tcp_connections "$@" >"$FAKE_NETSTAT_TCP_ESTABLISHED_FILE"
30 }
31
32 setup_tcp_connections_unkillable ()
33 {
34         # These connections are listed by the "ss" stub but are not
35         # killed by the "ctdb killtcp" stub.  So killing these
36         # connections will never succeed... and will look like a time
37         # out.
38         _t=$(_tcp_connections "$@" | sed -e 's/ /|/g')
39         export FAKE_NETSTAT_TCP_ESTABLISHED="$_t"
40 }
41
42 # Setup some fake /proc/net/bonding files with just enough info for
43 # the eventscripts.
44
45 # arg1 is interface name, arg2 is currently active slave (use "None"
46 # if none), arg3 is MII status ("up" or "down").
47 setup_bond ()
48 {
49         _iface="$1"
50         _slave="${2:-${_iface}_sl_0}"
51         _mii_s="${3:-up}"
52         _mii_subs="${4:-${_mii_s:-up}}"
53
54         cat <<EOF
55 Setting $_iface to be a bond with active slave $_slave and MII status $_mii_s
56 EOF
57
58         _t="${FAKE_NETWORK_STATE}/proc-net-bonding"
59         export FAKE_PROC_NET_BONDING="$_t"
60         mkdir -p "$FAKE_PROC_NET_BONDING"
61
62         cat >"${FAKE_PROC_NET_BONDING}/$_iface" <<EOF
63 Bonding Mode: IEEE 802.3ad Dynamic link aggregation
64 Currently Active Slave: $_slave
65 # Status of the bond
66 MII Status: $_mii_s
67 # Status of 1st pretend adapter
68 MII Status: $_mii_subs
69 # Status of 2nd pretend adapter
70 MII Status: $_mii_subs
71 EOF
72 }