public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH v3] lib/test_net.sh: add network help script
@ 2014-04-03  8:36 Alexey Kodanev
  2014-04-07 15:32 ` chrubis
  0 siblings, 1 reply; 2+ messages in thread
From: Alexey Kodanev @ 2014-04-03  8:36 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>
---
v3: Don't set TCID TST_COUNT TST_TOTAL
    Don't check if TST_USE_SSH is 1

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..51b3e38
--- /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=
+	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="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" ]; 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


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [LTP] [PATCH v3] lib/test_net.sh: add network help script
  2014-04-03  8:36 [LTP] [PATCH v3] lib/test_net.sh: add network help script Alexey Kodanev
@ 2014-04-07 15:32 ` chrubis
  0 siblings, 0 replies; 2+ messages in thread
From: chrubis @ 2014-04-07 15:32 UTC (permalink / raw)
  To: Alexey Kodanev; +Cc: vasily.isaenko, ltp-list

Hi!
> 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

Pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment 
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees_APR
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-04-07 15:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-03  8:36 [LTP] [PATCH v3] lib/test_net.sh: add network help script Alexey Kodanev
2014-04-07 15:32 ` chrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox