From 35b2d6a964f5b28b96c541df519b78205afc4562 Mon Sep 17 00:00:00 2001 From: Juan Vidal Date: Thu, 23 Feb 2017 17:16:52 +0000 Subject: 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 --- sfc/lib/utils.py | 20 +++++++++++--------- 1 file 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"): -- cgit 1.2.3-korg