ctdb-scripts: Compact server-end TCP connection killing output
[samba.git] / ctdb / tests / eventscripts / scripts / local.sh
index 61a033a1b6cce9aa38cdc870cd5b0a64a5569748..0e16f5b1b1d3db8835d1e31a7349e08545eb6324 100644 (file)
@@ -124,8 +124,7 @@ setup_generic ()
     export FAKE_TDB_IS_OK
     export FAKE_DATE_OUTPUT
 
-    export FAKE_NETSTAT_TCP_ESTABLISHED FAKE_TCP_LISTEN FAKE_NETSTAT_UNIX_LISTEN
-    export FAKE_NETSTAT_TCP_ESTABLISHED_FILE=$(mktemp --tmpdir="$EVENTSCRIPTS_TESTS_VAR_DIR")
+    export FAKE_TCP_LISTEN FAKE_NETSTAT_UNIX_LISTEN
 }
 
 tcp_port_down ()
@@ -136,6 +135,42 @@ tcp_port_down ()
     done
 }
 
+_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"
+}
+
 shares_missing ()
 {
     _fmt="$1" ; shift
@@ -802,11 +837,9 @@ setup_samba ()
     if [ "$1" != "down" ] ; then
 
        debug "Marking Samba services as up, listening and managed by CTDB"
-        # Get into known state.
-       eventscript_call ctdb_service_managed
 
         # All possible service names for all known distros.
-       for i in "smb" "nmb" "samba" ; do
+       for i in "smb" "nmb" "samba" "smbd" "nmbd" ; do
            service "$i" force-started
        done
 
@@ -822,11 +855,9 @@ setup_samba ()
        export FAKE_SLEEP_FORCE=0.1
     else
        debug "Marking Samba services as down, not listening and not managed by CTDB"
-        # Get into known state.
-       eventscript_call ctdb_service_unmanaged
 
         # All possible service names for all known distros.
-       for i in "smb" "nmb" "samba" ; do
+       for i in "smb" "nmb" "samba" "smbd" "nmbd" ; do
            service "$i" force-stopped
        done
 
@@ -839,6 +870,23 @@ setup_samba ()
     fi
 }
 
+samba_setup_fake_threads ()
+{
+       export FAKE_SMBD_THREAD_PIDS="$*"
+
+       _nl="
+"
+       _out=""
+       _count=0
+       for _pid ; do
+               [ "$_count" -lt 5 ] || break
+               _t=$(program_stack_trace "smbd" $_pid)
+               _out="${_out:+${_out}${_nl}}${_t}"
+               _count=$((_count + 1))
+       done
+       SAMBA_STACK_TRACES="$_out"
+}
+
 setup_winbind ()
 {
     setup_ctdb
@@ -848,8 +896,6 @@ setup_winbind ()
     if [ "$1" != "down" ] ; then
 
        debug "Marking Winbind service as up and managed by CTDB"
-        # Get into known state.
-       eventscript_call ctdb_service_managed
 
        service "winbind" force-started
 
@@ -859,8 +905,6 @@ setup_winbind ()
 
     else
        debug "Marking Winbind service as down and not managed by CTDB"
-        # Get into known state.
-       eventscript_call ctdb_service_unmanaged
 
        service "winbind" force-stopped
 
@@ -902,7 +946,6 @@ setup_nfs ()
     if [ "$1" != "down" ] ; then
        debug "Setting up NFS environment: all RPC services up, NFS managed by CTDB"
 
-       eventscript_call ctdb_service_managed
        service "nfs" force-started
        service "nfslock" force-started
 
@@ -916,7 +959,6 @@ setup_nfs ()
     else
        debug "Setting up NFS environment: all RPC services down, NFS not managed by CTDB"
 
-       eventscript_call ctdb_service_unmanaged
        service "nfs" force-stopped
        service "nfslock" force-stopped
 
@@ -999,6 +1041,17 @@ nfs_setup_fake_threads ()
     esac
 }
 
+program_stack_trace ()
+{
+       _prog="$1"
+       _pid="$2"
+
+       cat <<EOF
+Stack trace for ${_prog}[${_pid}]:
+[<ffffffff87654321>] fake_stack_trace_for_pid_${_pid}/stack+0x0/0xff
+EOF
+}
+
 program_stack_traces ()
 {
     _prog="$1"
@@ -1008,10 +1061,7 @@ program_stack_traces ()
     for _pid in ${FAKE_NFSD_THREAD_PIDS:-$FAKE_RPC_THREAD_PIDS} ; do
        [ $_count -le $_max ] || break
 
-       cat <<EOF
-Stack trace for ${_prog}[${_pid}]:
-[<ffffffff87654321>] fake_stack_trace_for_pid_${_pid}/stack+0x0/0xff
-EOF
+       program_stack_trace "$_prog" "$_pid"
        _count=$(($_count + 1))
     done
 }
@@ -1162,7 +1212,6 @@ setup_vsftpd ()
     else
        debug "Setting up VSFTPD environment: service down, not managed by CTDB"
 
-       eventscript_call ctdb_service_unmanaged
        service vsftpd force-stopped
 
        export CTDB_MANAGED_SERVICES="foo"
@@ -1182,7 +1231,6 @@ setup_httpd ()
        debug "Setting up HTTPD environment: service down, not managed by CTDB"
 
        for service_name in "apache2" "httpd" ; do
-           eventscript_call ctdb_service_unmanaged
            service "$service_name" force-stopped
        done