ctdb-tests: Create 10.interface.sh
authorMartin Schwenke <martin@meltin.net>
Mon, 19 Mar 2018 09:36:22 +0000 (20:36 +1100)
committerAmitay Isaacs <amitay@samba.org>
Wed, 28 Mar 2018 00:57:17 +0000 (02:57 +0200)
Contains testing support used only by tests for 10.interface event
script.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/tests/eventscripts/scripts/10.interface.sh [new file with mode: 0644]
ctdb/tests/eventscripts/scripts/local.sh

diff --git a/ctdb/tests/eventscripts/scripts/10.interface.sh b/ctdb/tests/eventscripts/scripts/10.interface.sh
new file mode 100644 (file)
index 0000000..48f2c39
--- /dev/null
@@ -0,0 +1,60 @@
+_tcp_connections ()
+{
+       _count="$1"
+       _sip="$2"
+       _sport="$3"
+       _cip_base="$4"
+       _cport_base="$5"
+
+       _cip_prefix="${_cip_base%.*}"
+       _cip_suffix="${_cip_base##*.}"
+
+       for _i in $(seq 1 $_count) ; do
+               _cip_last=$((_cip_suffix + _i))
+               _cip="${_cip_prefix}.${_cip_last}"
+               _cport=$((_cport_base + _i))
+               echo "${_sip}:${_sport} ${_cip}:${_cport}"
+       done
+}
+
+setup_tcp_connections ()
+{
+       _t=$(mktemp --tmpdir="$EVENTSCRIPTS_TESTS_VAR_DIR")
+       export FAKE_NETSTAT_TCP_ESTABLISHED_FILE="$_t"
+       _tcp_connections "$@" >"$FAKE_NETSTAT_TCP_ESTABLISHED_FILE"
+}
+
+setup_tcp_connections_unkillable ()
+{
+       # These connections are listed by the "ss" stub but are not
+       # killed by the "ctdb killtcp" stub.  So killing these
+       # connections will never succeed... and will look like a time
+       # out.
+       _t=$(_tcp_connections "$@" | sed -e 's/ /|/g')
+       export FAKE_NETSTAT_TCP_ESTABLISHED="$_t"
+}
+
+# Setup some fake /proc/net/bonding files with just enough info for
+# the eventscripts.
+
+# arg1 is interface name, arg2 is currently active slave (use "None"
+# if none), arg3 is MII status ("up" or "down").
+setup_bond ()
+{
+       _iface="$1"
+       _slave="${2:-${_iface}_sl_0}"
+       _mii_s="${3:-up}"
+       _mii_subs="${4:-${_mii_s:-up}}"
+
+       echo "Setting $_iface to be a bond with active slave $_slave and MII status $_mii_s"
+       cat >"${FAKE_PROC_NET_BONDING}/$_iface" <<EOF
+Bonding Mode: IEEE 802.3ad Dynamic link aggregation
+Currently Active Slave: $_slave
+# Status of the bond
+MII Status: $_mii_s
+# Status of 1st pretend adapter
+MII Status: $_mii_subs
+# Status of 2nd pretend adapter
+MII Status: $_mii_subs
+EOF
+}
index 53c3c840166ffae06ed841beda049cfe390d2430..c0f1b26fca1b617da6da633c3d178f83362dab91 100644 (file)
@@ -117,42 +117,6 @@ unix_socket_listening ()
        FAKE_NETSTAT_UNIX_LISTEN="${FAKE_NETSTAT_UNIX_LISTEN} ${_s}"
 }
 
-_tcp_connections ()
-{
-       _count="$1"
-       _sip="$2"
-       _sport="$3"
-       _cip_base="$4"
-       _cport_base="$5"
-
-       _cip_prefix="${_cip_base%.*}"
-       _cip_suffix="${_cip_base##*.}"
-
-       for _i in $(seq 1 $_count) ; do
-               _cip_last=$((_cip_suffix + _i))
-               _cip="${_cip_prefix}.${_cip_last}"
-               _cport=$((_cport_base + _i))
-               echo "${_sip}:${_sport} ${_cip}:${_cport}"
-       done
-}
-
-setup_tcp_connections ()
-{
-       _t=$(mktemp --tmpdir="$EVENTSCRIPTS_TESTS_VAR_DIR")
-       export FAKE_NETSTAT_TCP_ESTABLISHED_FILE="$_t"
-       _tcp_connections "$@" >"$FAKE_NETSTAT_TCP_ESTABLISHED_FILE"
-}
-
-setup_tcp_connections_unkillable ()
-{
-       # These connections are listed by the "ss" stub but are not
-       # killed by the "ctdb killtcp" stub.  So killing these
-       # connections will never succeed... and will look like a time
-       # out.
-       _t=$(_tcp_connections "$@" | sed -e 's/ /|/g')
-       export FAKE_NETSTAT_TCP_ESTABLISHED="$_t"
-}
-
 setup_shares ()
 {
        debug "Setting up shares (3 existing shares)"
@@ -192,30 +156,6 @@ shares_missing ()
        echo "$_out"
 }
 
-# Setup some fake /proc/net/bonding files with just enough info for
-# the eventscripts.
-
-# arg1 is interface name, arg2 is currently active slave (use "None"
-# if none), arg3 is MII status ("up" or "down").
-setup_bond ()
-{
-    _iface="$1"
-    _slave="${2:-${_iface}_sl_0}"
-    _mii_s="${3:-up}"
-    _mii_subs="${4:-${_mii_s:-up}}"
-    echo "Setting $_iface to be a bond with active slave $_slave and MII status $_mii_s"
-    cat >"${FAKE_PROC_NET_BONDING}/$_iface" <<EOF
-Bonding Mode: IEEE 802.3ad Dynamic link aggregation
-Currently Active Slave: $_slave
-# Status of the bond
-MII Status: $_mii_s
-# Status of 1st pretend adapter
-MII Status: $_mii_subs
-# Status of 2nd pretend adapter
-MII Status: $_mii_subs
-EOF
-}
-
 _ethtool_setup ()
 {
        FAKE_ETHTOOL_LINK_DOWN="${FAKE_NETWORK_STATE}/ethtool-link-down"