summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Paraskevopoulos <geopar@intracom-telecom.com>2017-02-07 12:08:39 +0200
committerGeorge Paraskevopoulos <geopar@intracom-telecom.com>2017-02-07 12:32:31 +0200
commitc94abdd2538b948ccd75a1d1e6386e6e5a1675ec (patch)
tree3791ea177ac3f5134af7322dee715235bf63a61d
parent995a0d9cfa3051034027b44c5bccb45e9180f8a0 (diff)
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 <geopar@intracom-telecom.com>
-rw-r--r--sfc/lib/utils.py16
1 files 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