From c94abdd2538b948ccd75a1d1e6386e6e5a1675ec Mon Sep 17 00:00:00 2001 From: George Paraskevopoulos Date: Tue, 7 Feb 2017 12:08:39 +0200 Subject: Simplify run_cmd sfc.lib.utils.run_cmd has a lot of unnecessary options which are never used. This patch simplifies this function and also fixes the returncode checking (commands have terminate with errors on returncode != 0 not on return code < 0) Also change the return value on error to None instead of False Change-Id: I5f1068ffd1bc6091e866a002b1afcb2507d30981 Signed-off-by: George Paraskevopoulos --- sfc/lib/utils.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/sfc/lib/utils.py b/sfc/lib/utils.py index 13f534be..032dcfd3 100644 --- a/sfc/lib/utils.py +++ b/sfc/lib/utils.py @@ -27,25 +27,19 @@ FUNCTEST_RESULTS_DIR = os.path.join("home", "opnfv", "functest", "results", "odl-sfc") -def run_cmd(cmd, wdir=None, ignore_stderr=False, ignore_no_output=True): +def run_cmd(cmd): """run given command locally and return commands output if success""" pipe = subprocess.Popen(cmd, shell=True, - stdin=subprocess.PIPE, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, cwd=wdir) + stderr=subprocess.PIPE) (output, errors) = pipe.communicate() if output: output = output.strip() - if pipe.returncode < 0: + if pipe.returncode != 0 or len(errors) > 0: + logger.error('FAILED to execute {0}'.format(cmd)) logger.error(errors) - return False - if errors: - logger.error(errors) - return ignore_stderr - - if ignore_no_output and not output: - return True + return None return output -- cgit 1.2.3-korg