From patchwork Thu Nov 17 01:37:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Rzeszutek Wilk X-Patchwork-Id: 9432977 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 23B7E60471 for ; Wed, 16 Nov 2016 22:30:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 123A529175 for ; Wed, 16 Nov 2016 22:30:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 051962917D; Wed, 16 Nov 2016 22:30:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.2 required=2.0 tests=BAYES_00, DATE_IN_FUTURE_03_06, RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D328928D1C for ; Wed, 16 Nov 2016 22:30:32 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c78gq-0004FH-LY; Wed, 16 Nov 2016 22:28:24 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c78gp-0004DB-NJ for xen-devel@lists.xenproject.org; Wed, 16 Nov 2016 22:28:23 +0000 Received: from [85.158.139.211] by server-3.bemta-5.messagelabs.com id 17/67-01948-68DDC285; Wed, 16 Nov 2016 22:28:22 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrFLMWRWlGSWpSXmKPExsXSO6nOVbftrk6 EwbfHrBbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8b8hW3MBYsUKt6dPMbYwPhCoouRi0NIYCKT xOYfU1kgnL+MEu/WfGOCcDYyShzevJQRwulmlHjweBVQhoODTcBE4s0qxy5GTg4RAVuJe42zG UFsZoFwif/7O5hAbGGBIIln/5eClbMIqEp8e2gHEuYVcJc4uL2BFcSWEJCTOH/8JzNICaeAh8 TbHxwgYSGgkn//frJDlBhKfN64lHkCI98CRoZVjBrFqUVlqUW6RgZ6SUWZ6RkluYmZObqGBqZ 6uanFxYnpqTmJScV6yfm5mxiBYVLPwMC4g7Fxtt8hRkkOJiVR3g3HdCKE+JLyUyozEosz4otK c1KLDzHKcHAoSfBq3wHKCRalpqdWpGXmAAMWJi3BwaMkwnvzNlCat7ggMbc4Mx0idYpRUUqc9 y1IQgAkkVGaB9cGi5JLjLJSwryMDAwMQjwFqUW5mSWo8q8YxTkYlYR5pUC282TmlcBNfwW0mA lo8R4BsMUliQgpqQZG9twae8t7aZMizWa7vlryScJDxaUgKV43pHLx+SMi7GvmdayZrfxDsFK v6pWaZm2W85La8we/P01T0dt4YT/3t2/t18T5f73ofTxDfO6NJLan9exKhroe580u6tvt3zbt fdxXqcjPnIE7V/xMd9rIrqC6ed8RZUcGdrO7jpc5vx1Yd8Sg56ixEktxRqKhFnNRcSIA7Jpo9 o0CAAA= X-Env-Sender: konrad.wilk@oracle.com X-Msg-Ref: server-5.tower-206.messagelabs.com!1479335299!69025433!1 X-Originating-IP: [141.146.126.69] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTQxLjE0Ni4xMjYuNjkgPT4gMjc3MjE4\n X-StarScan-Received: X-StarScan-Version: 9.0.16; banners=-,-,- X-VirusChecked: Checked Received: (qmail 60615 invoked from network); 16 Nov 2016 22:28:22 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-5.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 16 Nov 2016 22:28:22 -0000 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id uAGMSFmY013849 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Nov 2016 22:28:15 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id uAGMSE1F007920 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Nov 2016 22:28:14 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id uAGMSEtl004184; Wed, 16 Nov 2016 22:28:14 GMT Received: from osstest.dumpdata.com (/209.6.196.81) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 16 Nov 2016 14:28:14 -0800 From: Konrad Rzeszutek Wilk To: xen-devel@lists.xenproject.org, Ian.Jackson@eu.citrix.com Date: Wed, 16 Nov 2016 20:37:07 -0500 Message-Id: <1479346630-122644-5-git-send-email-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1479346630-122644-1-git-send-email-konrad.wilk@oracle.com> References: <1479346630-122644-1-git-send-email-konrad.wilk@oracle.com> X-Source-IP: userv0022.oracle.com [156.151.31.74] Cc: Marcos.Matsunaga@oracle.com, Konrad Rzeszutek Wilk Subject: [Xen-devel] [PATCH v1 4/7] OssTest: Add target_cmd_root_rc which returns return code. X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 ($$$&) {