xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: xen-devel@lists.xenproject.org, Ian.Jackson@eu.citrix.com
Cc: Marcos.Matsunaga@oracle.com,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Subject: [PATCH v1 4/7] OssTest: Add target_cmd_root_rc which returns return code.
Date: Wed, 16 Nov 2016 20:37:07 -0500	[thread overview]
Message-ID: <1479346630-122644-5-git-send-email-konrad.wilk@oracle.com> (raw)
In-Reply-To: <1479346630-122644-1-git-send-email-konrad.wilk@oracle.com>

All the different target_cmd_* end up calling tcmdex
which has the unfortunate side-effect of calling 'die' if
the SSH sessions results in any return code not zero.

That is fine, except for tests where we want to get a non-zero
return value.

This patch moves the: die "status $r" from tcmdex
to all the other functions which use tcmdex.

Also we make tcmd behave in the normal old way (die "status $r")
or if returnrc is set to one, we will return the error code.

The only exposed function that does that is target_cmd_root_rc.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
 Osstest/TestSupport.pm | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/Osstest/TestSupport.pm b/Osstest/TestSupport.pm
index 888f0ac..92f043a 100644
--- a/Osstest/TestSupport.pm
+++ b/Osstest/TestSupport.pm
@@ -51,6 +51,7 @@ BEGIN {
                       get_runvar_default need_runvars
                       unique_incrementing_runvar next_unique_name
 
+                      target_cmd_root_rc
                       target_cmd_root target_cmd target_cmd_build
                       target_cmd_output_root target_cmd_output
                       target_cmd_inputfh_root sshuho
@@ -424,17 +425,17 @@ sub tcmdex {
     # We use timeout(1) as a backstop, in case $cmd doesn't die.  We
     # need $cmd to die because we won't release the resources we own
     # until all of our children are dead.
-    my $r= cmd($timeout,$stdin,$stdout,
+    cmd($timeout,$stdin,$stdout,
 	       'timeout',$timeout+30, $cmd,@$optsref,@args);
-    $r and die "status $r";
 }
 
 sub tgetfileex {
     my ($ruser, $ho,$timeout, $rsrc,$ldst) = @_;
     unlink $ldst or $!==&ENOENT or die "$ldst $!";
-    tcmdex($timeout,undef,undef,
+    my $r = tcmdex($timeout,undef,undef,
            'scp', sshopts(),
            sshuho($ruser,$ho).":$rsrc", $ldst);
+    $r and die "status $r";
 } 
 sub target_getfile ($$$$) {
     my ($ho,$timeout, $rsrc,$ldst) = @_;
@@ -448,16 +449,18 @@ sub target_getfile_root ($$$$) {
 sub tputfileex {
     my ($ruser, $ho,$timeout, $lsrc,$rdst, $rsync) = @_;
     my @args= ($lsrc, sshuho($ruser,$ho).":$rdst");
+    my $r = 0;
     if (!defined $rsync) {
-        tcmdex($timeout,undef,undef,
+        $r = tcmdex($timeout,undef,undef,
                'scp', sshopts(),
                @args);
     } else {
         unshift @args, $rsync if length $rsync;
-        tcmdex($timeout,undef,undef,
+        $r = tcmdex($timeout,undef,undef,
                'rsync', [ '-e', 'ssh '.join(' ',@{ sshopts() }) ],
                @args);
     }
+    $r and die "status $r";
 }
 sub target_putfile ($$$$;$) {
     # $ho,$timeout,$lsrc,$rdst,[$rsync_opt]
@@ -652,19 +655,22 @@ sub target_await_down ($$) {
 }    
 
 sub tcmd { # $tcmd will be put between '' but not escaped
-    my ($stdin,$stdout,$user,$ho,$tcmd,$timeout,$extrasshopts) = @_;
+    my ($stdin,$stdout,$returnrc,$user,$ho,$tcmd,$timeout,$extrasshopts) = @_;
     $timeout=30 if !defined $timeout;
     target_adjust_timeout($ho,\$timeout);
-    tcmdex($timeout,$stdin,$stdout,
+    my $r = tcmdex($timeout,$stdin,$stdout,
            'ssh', sshopts(), @{ $extrasshopts || [] },
            sshuho($user,$ho), $tcmd);
+    die "status $r" if $r and !$returnrc;
+    return $r;
 }
-sub target_cmd ($$;$$) { tcmd(undef,undef,'osstest',@_); }
-sub target_cmd_root ($$;$$) { tcmd(undef,undef,'root',@_); }
+sub target_cmd ($$;$$) { tcmd(undef,undef,0, 'osstest',@_); }
+sub target_cmd_root ($$;$$) { tcmd(undef,undef,0, 'root',@_); }
+sub target_cmd_root_rc ($$;$$) { tcmd(undef,undef,1, 'root',@_); }
 
 sub tcmdout {
     my $stdout= IO::File::new_tmpfile();
-    tcmd(undef,$stdout,@_);
+    tcmd(undef,$stdout,0,@_);
     $stdout->seek(0,0) or die "$stdout $!";
     my $r;
     { local ($/) = undef;
@@ -679,7 +685,7 @@ sub target_cmd_output_root ($$;$) { tcmdout('root',@_); }
 
 sub target_cmd_inputfh_root ($$$;$$) {
     my ($tho,$stdinfh,$tcmd,@rest) = @_;
-    tcmd($stdinfh,undef,'root',$tho,$tcmd,@rest);
+    tcmd($stdinfh,undef,0,'root',$tho,$tcmd,@rest);
 }
 
 sub poll_loop ($$$&) {
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2016-11-16 22:28 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-17  1:37 [PATCH v1] OSSTest test-harness for livepatches Konrad Rzeszutek Wilk
2016-11-17  1:37 ` [PATCH v1 1/7] ts-xen-build: Enable livepatch Konrad Rzeszutek Wilk
2016-11-17 11:45   ` Ian Jackson
2016-11-17  1:37 ` [PATCH v1 2/7] ts-xen-build: Build the livepatch test-cases Konrad Rzeszutek Wilk
2016-11-17  1:37 ` [PATCH v1 3/7] ts-xen-build: Install livepatch regressions tests Konrad Rzeszutek Wilk
2016-11-17 11:49   ` [PATCH v1 3/7] ts-xen-build: Install livepatch regressions tests. [and 1 more messages] Ian Jackson
2016-11-21 21:28     ` Konrad Rzeszutek Wilk
2016-12-12 16:12       ` Ian Jackson
2016-11-17  1:37 ` Konrad Rzeszutek Wilk [this message]
2016-11-17 11:53   ` [PATCH v1 4/7] OssTest: Add target_cmd_root_rc which returns return code Ian Jackson
2016-11-17  1:37 ` [PATCH v1 5/7] ts-livepatch: Initial test-cases Konrad Rzeszutek Wilk
2016-11-17 12:21   ` Ian Jackson
2016-11-21 22:47     ` Konrad Rzeszutek Wilk
2016-12-12 16:17       ` Ian Jackson
2016-11-17  1:37 ` [PATCH v1 6/7] sg-run-job: Add the test-livepatch Konrad Rzeszutek Wilk
2016-11-17 12:23   ` Ian Jackson
2016-11-17  1:37 ` [PATCH v1 7/7] make-flight/mfi-common: Add them in the matrix Konrad Rzeszutek Wilk
2016-11-17 12:24   ` Ian Jackson
2016-12-12 19:01     ` Konrad Rzeszutek Wilk
2016-12-12 16:19       ` Ian Jackson
2016-11-17 12:28 ` [PATCH v1] OSSTest test-harness for livepatches Ian Jackson

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=1479346630-122644-5-git-send-email-konrad.wilk@oracle.com \
    --to=konrad.wilk@oracle.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=Marcos.Matsunaga@oracle.com \
    --cc=xen-devel@lists.xenproject.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).