summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuan Vidal <juan.vidal.allende@ericsson.com>2017-02-23 17:16:52 +0000
committerJuan Vidal <juan.vidal.allende@ericsson.com>2017-02-23 17:29:11 +0000
commit35b2d6a964f5b28b96c541df519b78205afc4562 (patch)
tree4a51b099eb9fa3bb8e06b64d6027220af6c769ef
parentdf08639171bba0e86f6595849d864ad514bd8f3d (diff)
Reduce logging level of run_cmd
run_cmd does not have enough information to determine if something should be logged with ERROR level. For example, you might want to repeat a command until it succeeds, and you would expect it to fail the first times, so it would not be an error in that context. Let's keep the debug logging only, which should be informative for troubleshooting. Change-Id: I72bc40e58d19188b83ad289fe7fa2b4453d5ad56 Signed-off-by: Juan Vidal <juan.vidal.allende@ericsson.com>
-rw-r--r--sfc/lib/utils.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/sfc/lib/utils.py b/sfc/lib/utils.py
index dde71b2b..6a1192b3 100644
--- a/sfc/lib/utils.py
+++ b/sfc/lib/utils.py
@@ -31,19 +31,21 @@ def run_cmd(cmd):
Run given command locally
Return a tuple with the return code, stdout, and stderr of the command
"""
- pipe = subprocess.Popen(cmd, shell=True,
+ pipe = subprocess.Popen(cmd,
+ shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
- output, errors = pipe.communicate()
- logger.debug("running [%s] returns: <%s> - %s "
- "" % (cmd, pipe.returncode, output))
+ stdout, stderr = [stream.strip() for stream in pipe.communicate()]
+ output = ' - STDOUT: "%s"' % stdout if len(stdout) > 0 else ''
+ error = ' - STDERR: "%s"' % stdout if len(stderr) > 0 else ''
+ logger.debug("Running [{command}] returns: [{rc}]{output}{error}".format(
+ command=cmd,
+ rc=pipe.returncode,
+ output=output,
+ error=error))
- if pipe.returncode != 0 or len(errors) > 0:
- logger.error('FAILED to execute {0}'.format(cmd))
- logger.error(errors)
-
- return pipe.returncode, output.strip(), errors.strip()
+ return pipe.returncode, stdout, stderr
def run_cmd_remote(ip, cmd, username="root", passwd="opnfv"):