From: John Schwarz Date: Thu, 12 Nov 2015 14:05:19 +0000 (+0200) Subject: Send 50% less debug information when executing cmd X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=5d3dc68d7e6c958777ac0c4241371fd47eefb081;p=openstack-build%2Fneutron-build.git Send 50% less debug information when executing cmd The current code prints out the command it runs twice: once in 'create_process' or 'execute_rootwrap_daemon', and once after the command has finished executing and a return code is returned. Since this is synchronous, there is no need to print the command twice in a row, so this patch deletes the latter one, leaving only the exit code to be printed. This patch also refactors the surrounding code to make it more readable. Change-Id: I22289f838dbc3956a777a78c882e4d5f1e725d0e --- diff --git a/neutron/agent/linux/utils.py b/neutron/agent/linux/utils.py index 2148c73e1..c291f987d 100644 --- a/neutron/agent/linux/utils.py +++ b/neutron/agent/linux/utils.py @@ -125,32 +125,24 @@ def execute(cmd, process_input=None, addl_env=None, if isinstance(_stderr, bytes): _stderr = _stderr.decode('utf-8', 'surrogateescape') - command_str = { - 'cmd': cmd, - 'code': returncode - } - m = _("\nCommand: %(cmd)s" - "\nExit code: %(code)d\n") % command_str - extra_ok_codes = extra_ok_codes or [] - if returncode and returncode in extra_ok_codes: - returncode = None - - if returncode and log_fail_as_error: - command_str['stdin'] = process_input or '' - command_str['stdout'] = _stdout - command_str['stderr'] = _stderr - m += _("Stdin: %(stdin)s\n" - "Stdout: %(stdout)s\n" - "Stderr: %(stderr)s") % command_str - log_msg = m.strip().replace('\n', '; ') - LOG.error(log_msg) + if returncode and returncode not in extra_ok_codes: + msg = _("Exit code: %(returncode)d; " + "Stdin: %(stdin)s; " + "Stdout: %(stdout)s; " + "Stderr: %(stderr)s") % { + 'returncode': returncode, + 'stdin': process_input or '', + 'stdout': _stdout, + 'stderr': _stderr} + + if log_fail_as_error: + LOG.error(msg) + if check_exit_code: + raise RuntimeError(msg) else: - log_msg = m.strip().replace('\n', '; ') - LOG.debug(log_msg) + LOG.debug("Exit code: %d", returncode) - if returncode and check_exit_code: - raise RuntimeError(m) finally: # NOTE(termie): this appears to be necessary to let the subprocess # call clean something up in between calls, without