]> xenbits.xensource.com Git - people/iwj/osstest.git/commitdiff
TestSupport: target_cmd_root_status: New sub which returns return code.
authorKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Thu, 17 Nov 2016 01:16:09 +0000 (20:16 -0500)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Fri, 9 Jun 2017 14:34:14 +0000 (15:34 +0100)
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 adds the $badstatusok to tcmdex - and makes all
the existing callers pass in the value of zero to it. This
way the commands behave the normal old way.
to all the other functions which use tcmdex.

The only exposed function that does it differently
is target_cmd_root_status.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Osstest/TestSupport.pm

index c23ac135fd76773ca2137205dae988b65785e1f1..c36dc76cc627aa8052ba1ade61f16a12c1e5af40 100644 (file)
@@ -52,6 +52,7 @@ BEGIN {
                       unique_incrementing_runvar next_unique_name
                       stashfilecontents
 
+                      target_cmd_root_status
                       target_cmd_root target_cmd target_cmd_build
                       target_cmd_output_root target_cmd_output
                       target_cmd_inputfh_root sshuho
@@ -441,20 +442,21 @@ sub sshopts () {
 }
 
 sub tcmdex {
-    my ($timeout,$stdin,$stdout,$cmd,$optsref,@args) = @_;
+    my ($timeout,$stdin,$stdout,$badstatusok,$cmd,$optsref,@args) = @_;
     logm("executing $cmd ... @args");
     # 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,
               'timeout',$timeout+30, $cmd,@$optsref,@args);
+    return $r if $badstatusok;
     $r and die "status $r";
 }
 
 sub tgetfileex {
     my ($ruser, $ho,$timeout, $rsrc,$ldst) = @_;
     unlink $ldst or $!==&ENOENT or die "$ldst $!";
-    tcmdex($timeout,undef,undef,
+    tcmdex($timeout,undef,undef, 0,
            'scp', sshopts(),
            sshuho($ruser,$ho).":$rsrc", $ldst);
 } 
@@ -471,12 +473,12 @@ sub tputfileex {
     my ($ruser, $ho,$timeout, $lsrc,$rdst, $rsync) = @_;
     my @args= ($lsrc, sshuho($ruser,$ho).":$rdst");
     if (!defined $rsync) {
-        tcmdex($timeout,undef,undef,
+        tcmdex($timeout,undef,undef, 0,
                'scp', sshopts(),
                @args);
     } else {
         unshift @args, $rsync if length $rsync;
-        tcmdex($timeout,undef,undef,
+        tcmdex($timeout,undef,undef, 0,
                'rsync', [ '-e', 'ssh '.join(' ',@{ sshopts() }) ],
                @args);
     }
@@ -682,20 +684,21 @@ 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,$badstatusok,$user,$ho,$tcmd,$timeout,$extrasshopts) = @_;
     $timeout=30 if !defined $timeout;
     target_adjust_timeout($ho,\$timeout);
     $tcmd = ' ' if $tcmd eq ''; # ssh host '' logs in !
-    tcmdex($timeout,$stdin,$stdout,
+    tcmdex($timeout,$stdin,$stdout, $badstatusok,
            'ssh', sshopts(), @{ $extrasshopts || [] },
            sshuho($user,$ho), $tcmd);
 }
-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_status ($$;$$) { 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;
@@ -710,7 +713,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 ($$$&) {