All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wei Gao via ltp <ltp@lists.linux.it>
To: Martin Doucha <mdoucha@suse.cz>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v1] tst_test.sh: Add support for localhost ssh key setup
Date: Tue, 24 Sep 2024 06:15:32 -0400	[thread overview]
Message-ID: <ZvKRRDKH4D8ok8od@wegao> (raw)
In-Reply-To: <efb8ced2-c2d2-4a1e-9358-e39e7f6b7adc@suse.cz>

On Wed, Sep 18, 2024 at 01:46:30PM +0200, Martin Doucha wrote:
> Hi,
> this kind of configuration should be done by the test runner. LTP should not
> modify global system configuration unless doing so is a key part of the test
> scenario itself.
Will remove ssh configuration part to test runner.
> 
> The test runner can also create an alias for the lftp command so that the
> test can call it using the old name.
Create an alias for lftp not enough since current code use parameter "-nv" which
not supported by lftp so following error will popup:

lftp: invalid option -- 'n'
Try `lftp --help' for more information

> 
> On 18. 09. 24 12:03, Wei Gao via ltp wrote:
> > When RHOST=localhost, ssh@localhost will encounter error since
> > no correct setup for authorized_keys and known_hosts etc.
> > 
> > Signed-off-by: Wei Gao <wegao@suse.com>
> > ---
> >   testcases/lib/tst_test.sh               | 32 +++++++++++++++++++++++++
> >   testcases/network/tcp_cmds/ftp/ftp01.sh | 12 ++++++++--
> >   2 files changed, 42 insertions(+), 2 deletions(-)
> > 
> > diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
> > index c19c30b76..6df16bd17 100644
> > --- a/testcases/lib/tst_test.sh
> > +++ b/testcases/lib/tst_test.sh
> > @@ -784,6 +784,34 @@ tst_run()
> >   	_tst_do_exit
> >   }
> > +_tst_setup_localhost_ssh()
> > +{
> > +	if [ -z "$TST_SSHD_CONFIG" ]; then
> > +		TST_SSHD_CONFIG="/etc/ssh/sshd_config"
> > +	fi
> > +
> > +	if [ -z "$TST_SSH_DIR" ]; then
> > +		TST_SSH_DIR="/root/.ssh/"
> > +	fi
> > +
> > +	if [ ! -e "$TST_SSHD_CONFIG" ]; then
> > +		echo 'PermitRootLogin yes' >$TST_SSHD_CONFIG
> > +	elif [ ! `grep "^PermitRootLogin *yes" $TST_SSHD_CONFIG | wc -l` -gt 0 ]; then
> > +		echo 'PermitRootLogin yes' >>$TST_SSHD_CONFIG
> > +	fi
> > +
> > +	if [ ! -e "$TST_SSH_DIR/id_rsa" ]; then
> > +		ssh-keygen -q -N "" -t rsa -b 4096 -f $TST_SSH_DIR/id_rsa
> > +	fi
> > +
> > +	if [ -e "$TST_SSH_DIR/id_rsa.pub" ]; then
> > +		cat $TST_SSH_DIR/id_rsa.pub >> $TST_SSH_DIR/authorized_keys
> > +		ssh-keyscan -H localhost >> $TST_SSH_DIR/known_hosts
> > +	fi
> > +
> > +	systemctl restart sshd
> > +}
> > +
> >   _tst_run_iterations()
> >   {
> >   	local _tst_i=$TST_ITERATIONS
> > @@ -910,6 +938,10 @@ if [ -z "$TST_NO_DEFAULT_RUN" ]; then
> >   	tst_res TINFO "Running: $(basename $0) $TST_ARGS"
> >   	tst_res TINFO "Tested kernel: $(uname -a)"
> > +	if [ "$TST_NEEDS_LOCALHOST_SSH" = 1 ]; then
> > +		_tst_setup_localhost_ssh
> > +	fi
> > +
> >   	OPTIND=1
> >   	while getopts ":hi:$TST_OPTS" _tst_name $TST_ARGS; do
> > diff --git a/testcases/network/tcp_cmds/ftp/ftp01.sh b/testcases/network/tcp_cmds/ftp/ftp01.sh
> > index 53d1eec53..8ec7f4fca 100755
> > --- a/testcases/network/tcp_cmds/ftp/ftp01.sh
> > +++ b/testcases/network/tcp_cmds/ftp/ftp01.sh
> > @@ -4,13 +4,21 @@
> >   # Copyright (c) 2003 Manoj Iyer <manjo@mail.utexas.edu>
> >   # Copyright (c) 2001 Robbie Williamson <robbiew@us.ibm.com>
> > +TST_SETUP=setup
> >   TST_TESTFUNC=do_test
> >   TST_CNT=4
> >   TST_NEEDS_CMDS='awk ftp'
> >   TST_NEEDS_TMPDIR=1
> > +TST_NEEDS_LOCALHOST_SSH=1
> >   RUSER="${RUSER:-root}"
> >   RHOST="${RHOST:-localhost}"
> > +FTP_CLIENT_CMD="ftp -nv"
> > +
> > +setup()
> > +{
> > +    grep -q 'sles' /etc/os-release && FTP_CLIENT_CMD='lftp'
> > +}
> >   do_test()
> >   {
> > @@ -41,7 +49,7 @@ test_get()
> >               echo cd $TST_NET_DATAROOT
> >               echo get $file
> >               echo quit
> > -        } | ftp -nv $RHOST
> > +        } | $FTP_CLIENT_CMD $RHOST
> >           sum1="$(ls -l $file | awk '{print $5}')"
> >           sum2="$(ls -l $TST_NET_DATAROOT/$file | awk '{print $5}')"
> > @@ -62,7 +70,7 @@ test_put()
> >               echo cd $TST_TMPDIR
> >               echo put $file
> >               echo quit
> > -        } | ftp -nv $RHOST
> > +        } | $FTP_CLIENT_CMD $RHOST
> >           sum1="$(tst_rhost_run -c "sum $TST_TMPDIR/$file" -s | awk '{print $1}')"
> >           sum2="$(sum $TST_NET_DATAROOT/$file | awk '{print $1}')"
> 
> -- 
> Martin Doucha   mdoucha@suse.cz
> SW Quality Engineer
> SUSE LINUX, s.r.o.
> CORSO IIa
> Krizikova 148/34
> 186 00 Prague 8
> Czech Republic
> 

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2024-09-24 10:16 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-18 10:03 [LTP] [PATCH v1] tst_test.sh: Add support for localhost ssh key setup Wei Gao via ltp
2024-09-18 11:46 ` Martin Doucha
2024-09-24 10:15   ` Wei Gao via ltp [this message]
2024-09-24 12:08     ` Martin Doucha
2024-09-25  3:57 ` [LTP] [PATCH v2] ftp01.sh: Add support for test lftp Wei Gao via ltp
2024-10-15 19:39   ` Petr Vorel
2024-10-16  3:13     ` Wei Gao via ltp
2024-10-16 13:41       ` Petr Vorel
2024-11-04 16:20       ` Petr Vorel
2024-10-16 12:47     ` Cyril Hrubis
2024-10-16 13:48       ` Petr Vorel
2024-10-16 15:32         ` Cyril Hrubis
2024-10-16 16:17       ` Martin Doucha
2024-10-16 21:15         ` Petr Vorel
2024-11-01 12:11           ` Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZvKRRDKH4D8ok8od@wegao \
    --to=ltp@lists.linux.it \
    --cc=mdoucha@suse.cz \
    --cc=wegao@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.