* [LTP] [PATCH v2] lib/test_net.sh: add network help script
@ 2014-03-25 7:01 Alexey Kodanev
2014-04-02 14:53 ` chrubis
0 siblings, 1 reply; 3+ messages in thread
From: Alexey Kodanev @ 2014-03-25 7:01 UTC (permalink / raw)
To: ltp-list; +Cc: vasily.isaenko
Add tst_rhost_run() library function to run commands on remote host.
Supported options:
-b run in background
-s safe option, if something goes wrong, will exit with TBROK
-c specify command to run
Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com>
---
v2: Reset OPTIND
echo only if output is not empty
Remove setting $LTPROOT/testcases/bin in PATH
testcases/lib/test.sh | 1 +
testcases/lib/test_net.sh | 77 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 78 insertions(+), 0 deletions(-)
create mode 100644 testcases/lib/test_net.sh
diff --git a/testcases/lib/test.sh b/testcases/lib/test.sh
index 3f8a0f4..25248d9 100644
--- a/testcases/lib/test.sh
+++ b/testcases/lib/test.sh
@@ -23,6 +23,7 @@
export LTP_RET_VAL=0
export TST_COUNT=1
+export TST_LIB_LOADED=1
# Exit values map
tst_flag2mask()
diff --git a/testcases/lib/test_net.sh b/testcases/lib/test_net.sh
new file mode 100644
index 0000000..b7b32b2
--- /dev/null
+++ b/testcases/lib/test_net.sh
@@ -0,0 +1,77 @@
+#!/bin/sh
+# Copyright (c) 2014 Oracle and/or its affiliates. All Rights Reserved.
+#
+# 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
+#
+# Author: Alexey Kodanev <alexey.kodanev@oracle.com>
+#
+
+[ -z "$TST_LIB_LOADED" ] && . test.sh
+
+# Run command on remote host.
+# Options:
+# -b run in background
+# -s safe option, if something goes wrong, will exit with TBROK
+# -c specify command to run
+
+tst_rhost_run()
+{
+ # this is needed to run tools/apicmds on remote host
+ local pre_cmd="TCID=$TCID TST_COUNT=1 TST_TOTAL=1"
+ local post_cmd=
+ local out=
+ local user="root"
+ local cmd=
+ local safe=0
+
+ OPTIND=0
+
+ while getopts :bsc:u: opt; do
+ case "$opt" in
+ b)
+ pre_cmd="$pre_cmd nohup"
+ post_cmd=" > /dev/null 2>&1 &"
+ out="1> /dev/null"
+ ;;
+ s) safe=1 ;;
+ c) cmd=$OPTARG ;;
+ u) user=$OPTARG ;;
+ *)
+ tst_brkm TBROK "tst_rhost_run: unknown option: $opt"
+ ;;
+ esac
+ done
+
+ OPTIND=0
+
+ [ -z "$cmd" ] && tst_brkm TBROK "command not defined"
+
+ local output=
+ local ret=
+ if [ -n "$TST_USE_SSH" -a "$TST_USE_SSH" -eq 1 ]; then
+ output=`ssh -n -q $user@$RHOST "sh -c \
+ '$pre_cmd $cmd $post_cmd'" $out 2> /dev/null`
+ else
+ output=`rsh -n -l $user $RHOST "sh -c \
+ '$pre_cmd $cmd $post_cmd'" $out 2> /dev/null`
+ fi
+ ret=$?
+ [ $ret -ne 0 -a "$safe" -eq 1 ] && \
+ tst_brkm TBROK "failed to run '$cmd' on '$RHOST'"
+
+ [ -z "$out" -a -n "$output" ] && echo "$output"
+
+ return $ret
+}
--
1.7.1
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [LTP] [PATCH v2] lib/test_net.sh: add network help script
2014-03-25 7:01 [LTP] [PATCH v2] lib/test_net.sh: add network help script Alexey Kodanev
@ 2014-04-02 14:53 ` chrubis
[not found] ` <533C2D8A.4080502@oracle.com>
0 siblings, 1 reply; 3+ messages in thread
From: chrubis @ 2014-04-02 14:53 UTC (permalink / raw)
To: Alexey Kodanev; +Cc: vasily.isaenko, ltp-list
Hi!
> +[ -z "$TST_LIB_LOADED" ] && . test.sh
> +
> +# Run command on remote host.
> +# Options:
> +# -b run in background
> +# -s safe option, if something goes wrong, will exit with TBROK
> +# -c specify command to run
> +
> +tst_rhost_run()
> +{
> + # this is needed to run tools/apicmds on remote host
> + local pre_cmd="TCID=$TCID TST_COUNT=1 TST_TOTAL=1"
Hmm, if I get it right, this is here in order to make possible to run
the tst_get_unused_port apicmd command.
I don't like that much that we have to set the TST_COUNT and TST_TOTAL
too. Maybe we should relax the rules in ltpapicmd.c, given that
TST_TOTAL is not used for anything in the lib/ directory and the
tst_count is used only used only in the tst_print().
> + local post_cmd=
> + local out=
> + local user="root"
> + local cmd=
> + local safe=0
> +
> + OPTIND=0
> +
> + while getopts :bsc:u: opt; do
> + case "$opt" in
> + b)
> + pre_cmd="$pre_cmd nohup"
> + post_cmd=" > /dev/null 2>&1 &"
> + out="1> /dev/null"
> + ;;
> + s) safe=1 ;;
> + c) cmd=$OPTARG ;;
> + u) user=$OPTARG ;;
> + *)
> + tst_brkm TBROK "tst_rhost_run: unknown option: $opt"
> + ;;
> + esac
> + done
> +
> + OPTIND=0
> +
> + [ -z "$cmd" ] && tst_brkm TBROK "command not defined"
> +
> + local output=
> + local ret=
> + if [ -n "$TST_USE_SSH" -a "$TST_USE_SSH" -eq 1 ]; then
I would just simplify it to if [ -n "$TST_USE_SSH" ].
> + output=`ssh -n -q $user@$RHOST "sh -c \
> + '$pre_cmd $cmd $post_cmd'" $out 2> /dev/null`
> + else
> + output=`rsh -n -l $user $RHOST "sh -c \
> + '$pre_cmd $cmd $post_cmd'" $out 2> /dev/null`
> + fi
> + ret=$?
> + [ $ret -ne 0 -a "$safe" -eq 1 ] && \
> + tst_brkm TBROK "failed to run '$cmd' on '$RHOST'"
> +
> + [ -z "$out" -a -n "$output" ] && echo "$output"
> +
> + return $ret
> +}
The rest looks good.
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [LTP] [PATCH v2] lib/test_net.sh: add network help script
[not found] ` <533C2D8A.4080502@oracle.com>
@ 2014-04-02 16:19 ` chrubis
0 siblings, 0 replies; 3+ messages in thread
From: chrubis @ 2014-04-02 16:19 UTC (permalink / raw)
To: Alexey Kodanev; +Cc: vasily.isaenko, ltp-list
Hi!
> >> +[ -z "$TST_LIB_LOADED" ] && . test.sh
> >> +
> >> +# Run command on remote host.
> >> +# Options:
> >> +# -b run in background
> >> +# -s safe option, if something goes wrong, will exit with TBROK
> >> +# -c specify command to run
> >> +
> >> +tst_rhost_run()
> >> +{
> >> + # this is needed to run tools/apicmds on remote host
> >> + local pre_cmd="TCID=$TCID TST_COUNT=1 TST_TOTAL=1"
> > Hmm, if I get it right, this is here in order to make possible to run
> > the tst_get_unused_port apicmd command.
> >
> > I don't like that much that we have to set the TST_COUNT and TST_TOTAL
> > too. Maybe we should relax the rules in ltpapicmd.c, given that
> > TST_TOTAL is not used for anything in the lib/ directory and the
> > tst_count is used only used only in the tst_print().
> Yes, you are right, I did so because of apicmds.
> What about if we remove the check completely? We won't use tst_res*,
> tst_brk*... in new tests.
For now I've added an exception for the tst_get_unused_port the same way
we do it for tst_kvercmp. See latest git commit.
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-04-02 16:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-25 7:01 [LTP] [PATCH v2] lib/test_net.sh: add network help script Alexey Kodanev
2014-04-02 14:53 ` chrubis
[not found] ` <533C2D8A.4080502@oracle.com>
2014-04-02 16:19 ` chrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox