Skip to contentSkip to conversation

ssh-stress: Convert to new api

PATCH Superseded Joerg Vehlow 3 participants 6 messages Jun 14, 2021 – Jun 16, 2021

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ssh-stress: Convert to new api

From: Joerg Vehlow <[email protected]>

Apart from pure conversion:
- Use "StrictModes no" in ssh config, to get rid of
access permission problems; All part of the path of the authorized_keys file must not be writeable by anyone but the owner. This allows writing the file to the default temp directory
- Moved all rhost scripts into ssh-stress.sh

---
 .../network/stress/ssh/00_Descriptions.txt    |  11 -
 testcases/network/stress/ssh/Makefile         |  24 +-
 testcases/network/stress/ssh/ssh-stress.sh    | 260 ++++++++++++------
 .../network/stress/ssh/ssh-stress01-rmt.sh    |  65 -----
 .../network/stress/ssh/ssh-stress02-rmt.sh    |  76 -----
 .../network/stress/ssh/ssh-stress03-rmt.sh    |  77 ------
 6 files changed, 174 insertions(+), 339 deletions(-)
 delete mode 100644 testcases/network/stress/ssh/00_Descriptions.txt
 delete mode 100755 testcases/network/stress/ssh/ssh-stress01-rmt.sh
 delete mode 100755 testcases/network/stress/ssh/ssh-stress02-rmt.sh
 delete mode 100755 testcases/network/stress/ssh/ssh-stress03-rmt.sh
testcases/network/stress/ssh/00_Descriptions.txt deleted +0 -11
deleted file mode 100644
index 543e60d7d..000000000
@@ -1,11 +0,0 @@
-ssh-stress01
-	Verify the ssh connectivity over IPv4/IPv6 is not broken
-	after creating many ssh sessions
-
-ssh-stress02
-	Verify the ssh connectivity over IPv4/IPv6 is not broken
-	after logged in/out by many clients asynchronously for a long time
-
-ssh-stress03
-	Verify the ssh connectivity over IPv4/IPv6 is not broken
-	after forwarding TCP traffic for a long time
testcases/network/stress/ssh/Makefile +3 -21
index 1a6d052eb..7ebeec142 100644
@@ -1,24 +1,6 @@
-#
-#    testcases/network/stress/ssh Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Ngie Cooper, October 2009
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
+# Ngie Cooper, July 2009
 
 top_srcdir		?= ../../../..
 
testcases/network/stress/ssh/ssh-stress.sh +171 -89

318 lines not on this page · raw message

testcases/network/stress/ssh/ssh-stress01-rmt.sh deleted +0 -65

65 lines not on this page · raw message

testcases/network/stress/ssh/ssh-stress02-rmt.sh deleted +0 -76

76 lines not on this page · raw message

testcases/network/stress/ssh/ssh-stress03-rmt.sh deleted +0 -77

77 lines not on this page · raw message

Signature · 1 line
2.25.1
#2 lore raw

PATCH v2 1/1 ssh-stress: Convert to new api

In reply to Joerg Vehlow
Quoted 2 lines · Joerg Vehlow

From: Joerg Vehlow <[email protected]>

Hi Joerg,

Quoted 109 lines

Apart from pure conversion:
- Use "StrictModes no" in ssh config, to get rid of
access permission problems; All part of the path of the authorized_keys file must not be writeable by anyone but the owner. This allows writing the file to the default temp directory
- Moved all rhost scripts into ssh-stress.sh

---
 .../network/stress/ssh/00_Descriptions.txt    |  11 -
 testcases/network/stress/ssh/Makefile         |  24 +-
 testcases/network/stress/ssh/ssh-stress.sh    | 260 ++++++++++++------
 .../network/stress/ssh/ssh-stress01-rmt.sh    |  65 -----
 .../network/stress/ssh/ssh-stress02-rmt.sh    |  76 -----
 .../network/stress/ssh/ssh-stress03-rmt.sh    |  77 ------
 6 files changed, 174 insertions(+), 339 deletions(-)
 delete mode 100644 testcases/network/stress/ssh/00_Descriptions.txt
 delete mode 100755 testcases/network/stress/ssh/ssh-stress01-rmt.sh
 delete mode 100755 testcases/network/stress/ssh/ssh-stress02-rmt.sh
 delete mode 100755 testcases/network/stress/ssh/ssh-stress03-rmt.sh
testcases/network/stress/ssh/00_Descriptions.txt deleted +0 -11
deleted file mode 100644
index 543e60d7d..000000000
@@ -1,11 +0,0 @@
-ssh-stress01
-	Verify the ssh connectivity over IPv4/IPv6 is not broken
-	after creating many ssh sessions
-
-ssh-stress02
-	Verify the ssh connectivity over IPv4/IPv6 is not broken
-	after logged in/out by many clients asynchronously for a long time
-
-ssh-stress03
-	Verify the ssh connectivity over IPv4/IPv6 is not broken
-	after forwarding TCP traffic for a long time
testcases/network/stress/ssh/Makefile +3 -21
index 1a6d052eb..7ebeec142 100644
@@ -1,24 +1,6 @@
-#
-#    testcases/network/stress/ssh Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Ngie Cooper, October 2009
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
+# Ngie Cooper, July 2009
 
 top_srcdir		?= ../../../..
 
testcases/network/stress/ssh/ssh-stress.sh +9 -20
index 516bce765..49122eb54 100755
@@ -1,147 +1,229 @@
 #!/bin/sh
-
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2021 Joerg Vehlow <[email protected]>
 # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
-# Copyright (c) International Business Machines  Corp., 2005
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write the Free Software Foundation,
-# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#
+# Copyright (c) International Business Machines Corp., 2005
 # Author: Mitsuru Chinen <[email protected]>
-#
 
-TCID=ssh-stress
-TST_TOTAL=3
 TST_CLEANUP="cleanup"
+TST_SETUP="setup"
+TST_TESTFUNC="test"
+TST_CNT=3
+TST_NEEDS_ROOT=1
+TST_NEEDS_TMPDIR=1
+TST_NEEDS_CMDS="sshd ssh od xargs"

testcases/network/stress/ssh/ssh-stress.sh line 20

Quoted 10 lines
testcases/network/stress/ssh/ssh-stress.sh +3 -4
 
-TST_USE_LEGACY_API=1
 . tst_net.sh
 
-# Temporary directory to store sshd setting or ssh key
-# Note: ssh doesn't work when those directory is under /tmp.
-TMPDIR="/root"
+# SSH config file on the remote host
+RHOST_SSH_CONF=
+# SSG command to connect from the remote host to the test host
      ^
     SSH
Quoted 12 lines
testcases/network/stress/ssh/ssh-stress.sh +7 -1
+RHOST_SSH=
+# Processes started on the remote host, killed at cleanup
+RHOST_PIDS=
+# Netstress process started on the test host, killed at cleanup
+NETSTRESS_PID=
 
 cleanup()
 {
+	local pids pid
+
 	# Stop the ssh daemon
-	test -s sshd.pid && kill $(cat sshd.pid)

testcases/network/stress/ssh/ssh-stress.sh line 37

Quoted 10 lines
testcases/network/stress/ssh/ssh-stress.sh +6 -4
-	pkill 'netstress$'
-	tst_rmdir
-	[ "$rtmpdir" ] && tst_rhost_run -c "rm -rf $rtmpdir"
-	TMPDIR=
+	[ -s sshd.pid ] && kill $(cat sshd.pid)
+	[ -n "$NETSTRESS_PID" ] && kill -2 $NETSTRESS_PID >/dev/null 2>&1
+
+	for pid in $RHOST_PIDS; do
+		tst_rhost_run -c "kill -- $pid"  >/dev/null 2>&1
+	done

tst_rhost_run -c "kill $RHOST_PIDS"

testcases/network/stress/ssh/ssh-stress.sh line 44

Quoted 7 lines
testcases/network/stress/ssh/ssh-stress.sh +5 -0
+
+	# Kill all remaining ssh processes
+	tst_rhost_run -c "ps auwx | \
+		awk '\$0 ~ \"$RHOST_SSH_CONF\" && \$11 == \"ssh\" {print \$2}' | \
+		xargs -r -t kill -- >/dev/null 2>&1"
 }
 

What about using pkill -f instead of ps|awk|kill?

Quoted 93 lines
testcases/network/stress/ssh/ssh-stress.sh +22 -41
 setup()
 {
-	trap "tst_brkm TBROK 'test interrupted'" INT
-
-	tst_require_root
-	tst_require_cmds pkill sshd ssh od
-
-	# Get the sshd command with absolute path
-	SSHD=$(which sshd)
-	test "$SSHD" || tst_brkm TBROK "sshd daemon is not found"
+	local port rc
 
-	check_icmpv${TST_IPVER}_connectivity $(tst_iface) $(tst_ipaddr rhost) || \
-		tst_brkm TBROK "Failed to ping to $(tst_ipaddr rhost)"
 
 	port=$(tst_rhost_run -c "tst_get_unused_port ipv${TST_IPVER} stream")
 
-	tst_tmpdir
-
-	tmpdir=$TST_TMPDIR
-
-	cat << EOD > $tmpdir/sshd_config
+	cat << EOD > sshd_config
 Port $port
 ListenAddress $(tst_ipaddr)
 PermitRootLogin yes
-AuthorizedKeysFile $tmpdir/authorized_keys
+AuthorizedKeysFile $TST_TMPDIR/authorized_keys
 PasswordAuthentication no
 AllowTcpForwarding yes
 TCPKeepAlive yes
 UseDNS no
-PidFile $tmpdir/sshd.pid
+StrictModes no
+PidFile $TST_TMPDIR/sshd.pid
 EOD
 
-	$SSHD -f $tmpdir/sshd_config || \
-		tst_brkm TBROK "Failed to run sshd daemon"
-
-	tst_resm TINFO "Generate configuration file and key at the remote host"
-	rtmpdir=$(tst_rhost_run -c "mktemp -d -p $TMPDIR")
-	tst_rhost_run -s -c "ssh-keygen -t rsa -N \"\" -f $rtmpdir/id_rsa > /dev/null"
+	tst_res TINFO "Generate configuration file and key at the remote host"
+	tst_rhost_run -s -c "ssh-keygen -t rsa -N \"\" -f $TST_TMPDIR/id_rsa \
+		>/dev/null"
 
-	rconfig=$rtmpdir/ssh_config
+	RHOST_SSH_CONF=$TST_TMPDIR/ssh_config
 
 	tst_rhost_run -s -c "printf \"\
 Port $port\n\
 StrictHostKeyChecking no\n\
 PasswordAuthentication no\n\
-UserKnownHostsFile $rtmpdir/known_hosts\n\
-IdentityFile $rtmpdir/id_rsa\n\" > $rconfig"
+UserKnownHostsFile $TST_TMPDIR/known_hosts\n\
+IdentityFile $TST_TMPDIR/id_rsa\n\" > $RHOST_SSH_CONF"
 
-	tst_rhost_run -s -c "chmod 700 $rtmpdir; chmod 600 $rtmpdir/*"
+	tst_res TINFO "Generate authorized_keys"
+	tst_rhost_run -c "cat ${TST_TMPDIR}/id_rsa.pub" > authorized_keys
 
-	tst_resm TINFO "Generate authorized_keys"
-	tst_rhost_run -c "cat ${rtmpdir}/id_rsa.pub" > $tmpdir/authorized_keys
+	tst_res TINFO "restore context of authorized_keys"
+	rc=$(command -v restorecon)
+	[ -n "$rc" ] && $rc authorized_keys
 
-	tst_resm TINFO "restore context of authorized_keys"
-	local rc=$(which restorecon)
-	test "$rc" && $rc $tmpdir/authorized_keys
+	$(command -v sshd) -f $TST_TMPDIR/sshd_config || \
+		tst_brk TBROK "Failed to run sshd daemon"
 
-	chmod 700 $tmpdir
-	chmod 600 $tmpdir/*
+	RHOST_SSH="ssh -$TST_IPVER -F $RHOST_SSH_CONF $(tst_ipaddr)"
 }
 
-test01()
+test_ssh_connectivity()
 {
-	tst_resm TINFO "Creating '$CONNECTION_TOTAL' ssh sessions"
-
-	tst_rhost_run -s -c "ssh-stress01-rmt.sh $TST_IPVER $(tst_ipaddr) \
-		$rconfig $CONNECTION_TOTAL"
-
-	tst_resm TPASS "Test is finished successfully"
+	tst_rhost_run -c "$RHOST_SSH 'true >/dev/null 2>&1' >/dev/null"
+	[ $? -ne 0 ] && tst_brk TFAIL "SSH not reachable"
 }
 

testcases/network/stress/ssh/ssh-stress.sh line 101

Quoted 10 lines
testcases/network/stress/ssh/ssh-stress.sh +3 -5
-test02()
+test1()
 {
-	tst_resm TINFO "Log in/out by many clients asynchronously"
-	tst_resm TINFO "'$CONNECTION_TOTAL' clients, time $NS_DURATION sec"
+	local num all_conn pid
 
-	tst_rhost_run -s -c "ssh-stress02-rmt.sh $TST_IPVER $(tst_ipaddr) \
-		$rconfig $CONNECTION_TOTAL $NS_DURATION"
+	tst_res TINFO "Verify the ssh connectivity over IPv4/IPv6 is not broken after creating many ssh sessions"
                                                           ^

The message may have indicated the exact IP version with $TST_IPVER

Quoted 8 lines
testcases/network/stress/ssh/ssh-stress.sh +6 -1
-	tst_resm TPASS "Test is finished successfully"
+	test_ssh_connectivity
+
+	RHOST_PIDS=
+	num=0
+	while [ $num -lt $CONNECTION_TOTAL ]; do
+		pid=$(tst_rhost_run -c "$RHOST_SSH -N </dev/null 1>/dev/null 2>&1 \

testcases/network/stress/ssh/ssh-stress.sh line 118

Quoted 10 lines
testcases/network/stress/ssh/ssh-stress.sh +10 -0
+			& echo \$!")
+		RHOST_PIDS="$RHOST_PIDS $pid"
+		num=$(($num + 1))
+	done
+
+	tst_res TINFO "Killing all ssh sessions"
+	num=0
+	for pid in $RHOST_PIDS; do
+		tst_rhost_run -c "kill $pid" >/dev/null
+		[ $? -ne 0 ] && num=$((num + 1))

Do we need $((num + 1)) here? At least it could be used in the message below instead of "some ssh"...

Quoted 87 lines
testcases/network/stress/ssh/ssh-stress.sh +80 -3
+	done
+	
+	[ $num -ne 0 ] && tst_brk TFAIL "Some ssh processes died during execution"
+
+	test_ssh_connectivity
+
+	tst_res TPASS "Test finished successfully"
 }
 
-test03()
+test2()
 {
-	tst_resm TINFO "Forwarding TCP traffic with $NS_TIMES requests"
+	local start_epoc pids total_connections elapse_epoc new_pids
+	local ssh_num wait_sec login_sec
+
+	tst_res TINFO "Verify the ssh connectivity over IPv4/IPv6 is not broken after logged in/out by many clients asynchronously for a long time"
+
+	test_ssh_connectivity
+
+	start_epoc=$(date +%s)
+	RHOST_PIDS=
+	total_connections=0
+	while true ; do
+		# Exit after the specified time has elapsed.
+		elapse_epoc=$(( $(date +%s) - $start_epoc))
+		[ $elapse_epoc -ge $NS_DURATION ] && break
+
+		new_pids=
+		for pid in $RHOST_PIDS; do
+			if tst_rhost_run -c "kill -0 $pid" >/dev/null; then
+				new_pids="$new_pids $pid"
+			fi
+		done
+		RHOST_PIDS="$new_pids"
+
+		# Do not make ssh connection over the specified quantity
+		ssh_num=$(echo "$pids" | wc -w)
+		if [ $ssh_num -ge $CONNECTION_TOTAL ]; then
+			tst_res TINFO "Max connections reached"
+			tst_sleep 1
+			continue
+		fi
+
+		# specified wait time and login time
+		wait_sec=$(( $(od -A n -d -N 1 /dev/urandom) * 3 / 255 ))
+		login_sec=$(( $(od -A n -d -N 1 /dev/urandom) * 10 / 255 ))
+
+		# Login to the server
+		pid=$(tst_rhost_run -c "( \
+			  sleep $wait_sec && $RHOST_SSH -l root \"sleep $login_sec\" \
+			) </dev/null 1>/dev/null 2>&1 & echo \$!"
+		)
+		RHOST_PIDS="$RHOST_PIDS $pid"
+		total_connections=$(( total_connections + 1 ))
+	done
+
+	tst_res TINFO "Waiting for all connections to terminate"
+	while [ -n "$RHOST_PIDS" ]; do
+		tst_sleep 1
+		new_pids=
+		for pid in $RHOST_PIDS; do
+			if tst_rhost_run -c "kill -0 $pid" >/dev/null 2>&1; then
+				new_pids="$new_pids $pid"
+			fi
+		done
+		RHOST_PIDS="$new_pids"
+	done
+
+	test_ssh_connectivity
+
+	tst_res TPASS "Test finished successfully ($total_connections connections)"
+}
 
-	# Run a TCP traffic server
+test3()
+{
+	local port lport localhost rhost ret
+	tst_res TINFO "Verify the ssh connectivity over IPv4/IPv6 is not broken after forwarding TCP traffic for a long time"
+
+	localhost="127.0.0.1"
+	rhost="$(tst_ipaddr)"
+	if [ "$TST_IPVER" = "6" ]; then
+		localhost="::1"
+		rhost="[$(tst_ipaddr)]"
+	fi
+

testcases/network/stress/ssh/ssh-stress.sh line 211

Quoted 10 lines
testcases/network/stress/ssh/ssh-stress.sh +7 -1
+	test_ssh_connectivity
+
+	# Get a port for the server and a forwarding port
 	port=$(tst_get_unused_port ipv${TST_IPVER} stream)
+	lport=$(tst_rhost_run -c "tst_get_unused_port ipv${TST_IPVER} stream")
 
-	netstress -R 3 -g $port > tcp_server.log 2>&1 &
+	# Start a tcp server
+	netstress -R 3 -g $port >/dev/null 2>&1 &
+	NETSTRESS_PID=$!

We can now use netstress -B, it will go to background only after sucessfully performing bind()/listen(). The actual port number will be saved in the netstress_port file, i.e.:

netstress -B .
port=$(cat netstress_port)

testcases/network/stress/ssh/ssh-stress.sh line 217

Quoted 8 lines
testcases/network/stress/ssh/ssh-stress.sh +5 -2
-	tst_rhost_run -s -c "ssh-stress03-rmt.sh $TST_IPVER $(tst_ipaddr) \
-		$rconfig $port $NS_TIMES"
+	# Setup an ssh tunnel from the remote host to testhost
+	RHOST_PIDS=$(tst_rhost_run -c \
+		"$RHOST_SSH -N -L $lport:$rhost:$port </dev/null 1>/dev/null 2>&1 \
+		& echo \$!")
+	tst_sleep 1

Why you don't use -f option with ssh? I wouldn't rely on sleep 1 here.

#3 lore raw

PATCH v2 1/1 ssh-stress: Convert to new api

Hi Alexey,

thanks for your review, agree on all your suggestions.

Kind regards,
Petr

#4 lore raw

PATCH v2 1/1 ssh-stress: Convert to new api

In reply to Alexey Kodanev

Hi Alexey,

thanks for your review. I will integrate the changes, test and send a v3.

Quoted 5 lines

testcases/network/stress/ssh/ssh-stress.sh line 20

Quoted 3 lines
testcases/network/stress/ssh/ssh-stress.sh +3 -0
+# SSH config file on the remote host
+RHOST_SSH_CONF=
+# SSG command to connect from the remote host to the test host
       ^
      SSH

Obviously, thanks

Quoted 16 lines
Quoted 16 lines
testcases/network/stress/ssh/ssh-stress.sh +7 -4
+RHOST_SSH=
+# Processes started on the remote host, killed at cleanup
+RHOST_PIDS=
+# Netstress process started on the test host, killed at cleanup
+NETSTRESS_PID=
 
  cleanup()
  {
+	local pids pid
+
  	# Stop the ssh daemon
-	test -s sshd.pid && kill $(cat sshd.pid)
-	pkill 'netstress$'
-	tst_rmdir
-	[ "$rtmpdir" ] && tst_rhost_run -c "rm -rf $rtmpdir"
Quoted 8 lines

testcases/network/stress/ssh/ssh-stress.sh line 37

Quoted 7 lines
testcases/network/stress/ssh/ssh-stress.sh +6 -1
-	TMPDIR=
+	[ -s sshd.pid ] && kill $(cat sshd.pid)
+	[ -n "$NETSTRESS_PID" ] && kill -2 $NETSTRESS_PID >/dev/null 2>&1
+
+	for pid in $RHOST_PIDS; do
+		tst_rhost_run -c "kill -- $pid"  >/dev/null 2>&1
+	done

tst_rhost_run -c "kill $RHOST_PIDS"

I guess I did not use use it, because it might be a huge number of pids and I did not look at the actual limits, but now that I looked at it, it should be big enough...

Quoted 9 lines

testcases/network/stress/ssh/ssh-stress.sh line 43

Quoted 8 lines
testcases/network/stress/ssh/ssh-stress.sh +5 -0
+
+	# Kill all remaining ssh processes
+	tst_rhost_run -c "ps auwx | \
+		awk '\$0 ~ \"$RHOST_SSH_CONF\" && \$11 == \"ssh\" {print \$2}' | \
+		xargs -r -t kill -- >/dev/null 2>&1"
  }

What about using pkill -f instead of ps|awk|kill?

I guess I did not use pkill for two reasons:
1. I wanted to be sure to really only kill ssh processes with $RHOST_SSH_CONF in their arguments
2. I did not want to use an extra tool, that is not necessarily available on all systems.

The first one could be solved by using "pkill -f "^ssh .*$RHOST_SSH_CONF", I guess. This still leaves a problem with unescaped regexp meta characters in RHOST_SSH_CONF, but my awk solution has the same problem. But I think this is only theoretical, it is extremely unlikely, that any regexp meta character apart from "." is used in RHOST_SSH_CONF and the dot will unlikely produce false positives. The second point can be ignored. pkill is used in many locations throughout ltp already. It should probably be added as a runtime dependency.

Quoted 6 lines

testcases/network/stress/ssh/ssh-stress.sh line 101

Quoted 4 lines
testcases/network/stress/ssh/ssh-stress.sh +1 -2
-	tst_rhost_run -s -c "ssh-stress02-rmt.sh $TST_IPVER $(tst_ipaddr) \
-		$rconfig $CONNECTION_TOTAL $NS_DURATION"
+	tst_res TINFO "Verify the ssh connectivity over IPv4/IPv6 is not broken after creating many ssh sessions"
                                                            ^

The message may have indicated the exact IP version with $TST_IPVER

Yeah right, that was just copy and pasted from the original test description.

Quoted 6 lines

testcases/network/stress/ssh/ssh-stress.sh line 118

Quoted 4 lines
testcases/network/stress/ssh/ssh-stress.sh +3 -0
+	for pid in $RHOST_PIDS; do
+		tst_rhost_run -c "kill $pid" >/dev/null
+		[ $? -ne 0 ] && num=$((num + 1))

Do we need $((num + 1)) here? At least it could be used in the message below instead of "some ssh"...

I think I just counted them here, because I wanted to keep the loop running, so all processes are killed before tst_brk is called. But yes adding it to the message makes sense

Quoted 10 lines

testcases/network/stress/ssh/ssh-stress.sh line 211

Quoted 5 lines
testcases/network/stress/ssh/ssh-stress.sh +3 -1
-	netstress -R 3 -g $port > tcp_server.log 2>&1 &
+	# Start a tcp server
+	netstress -R 3 -g $port >/dev/null 2>&1 &
+	NETSTRESS_PID=$!

We can now use netstress -B, it will go to background only after sucessfully performing bind()/listen(). The actual port number will be saved in the netstress_port file, i.e.:

Quoted 2 lines

netstress -B .
port=$(cat netstress_port)

I will try this

Quoted 10 lines

testcases/network/stress/ssh/ssh-stress.sh line 217

Quoted 9 lines
testcases/network/stress/ssh/ssh-stress.sh +5 -2
-	tst_rhost_run -s -c "ssh-stress03-rmt.sh $TST_IPVER $(tst_ipaddr) \
-		$rconfig $port $NS_TIMES"
+	# Setup an ssh tunnel from the remote host to testhost
+	RHOST_PIDS=$(tst_rhost_run -c \
+		"$RHOST_SSH -N -L $lport:$rhost:$port </dev/null 1>/dev/null 2>&1 \
+		& echo \$!")
+	tst_sleep 1

Why you don't use -f option with ssh? I wouldn't rely on sleep 1 here.

Good idea, I did not think about -f.

J?rg

#5 lore raw

PATCH v2 1/1 ssh-stress: Convert to new api

Hi Joerg, Alexey,

Quoted 14 lines

Hi Alexey,

Quoted 6 lines

testcases/network/stress/ssh/ssh-stress.sh line 43

Quoted 5 lines
testcases/network/stress/ssh/ssh-stress.sh +4 -0
+	# Kill all remaining ssh processes
+	tst_rhost_run -c "ps auwx | \
+		awk '\$0 ~ \"$RHOST_SSH_CONF\" && \$11 == \"ssh\" {print \$2}' | \
+		xargs -r -t kill -- >/dev/null 2>&1"
  }

What about using pkill -f instead of ps|awk|kill?

I guess I did not use pkill for two reasons:
1. I wanted to be sure to really only kill ssh processes with $RHOST_SSH_CONF in their arguments
2. I did not want to use an extra tool, that is not necessarily available on all systems.

Quoted 8 lines

The first one could be solved by using "pkill -f "^ssh .*$RHOST_SSH_CONF", I guess. This still leaves a problem with unescaped regexp meta characters in RHOST_SSH_CONF, but my awk solution has the same problem. But I think this is only theoretical, it is extremely unlikely, that any regexp meta character apart from "." is used in RHOST_SSH_CONF and the dot will unlikely produce false positives.
The second point can be ignored. pkill is used in many locations throughout ltp already. It should probably be added as a runtime dependency.

+1. pkill as runtime dependency is probably better than xargs dependency. BTW I thought in the past to write tst_kill command, either as a shell implementation (which would look on pkill, killall and if none of them it'd used ps and grep) or (better) just to implement it in C.

Quoted 7 lines
Quoted 5 lines

testcases/network/stress/ssh/ssh-stress.sh line 101

Quoted 3 lines
testcases/network/stress/ssh/ssh-stress.sh +1 -2
-	tst_rhost_run -s -c "ssh-stress02-rmt.sh $TST_IPVER $(tst_ipaddr) \
-		$rconfig $CONNECTION_TOTAL $NS_DURATION"
+	tst_res TINFO "Verify the ssh connectivity over IPv4/IPv6 is not broken after creating many ssh sessions"
                                                            ^

The message may have indicated the exact IP version with $TST_IPVER

Yeah right, that was just copy and pasted from the original test description.

+ nit: "Verify SSH connectivity ..."

Kind regards,
Petr