From: Jenkins Date: Tue, 24 Nov 2015 05:13:18 +0000 (+0000) Subject: Merge "Make sure we return unicode strings for process output" X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=830c2e30fd716a34e1aa3f37a6e8f59fd8cc3824;p=openstack-build%2Fneutron-build.git Merge "Make sure we return unicode strings for process output" --- 830c2e30fd716a34e1aa3f37a6e8f59fd8cc3824 diff --cc neutron/agent/linux/utils.py index 95619a98d,5bbc1bf01..29d129ad1 --- a/neutron/agent/linux/utils.py +++ b/neutron/agent/linux/utils.py @@@ -120,30 -119,35 +120,27 @@@ def execute(cmd, process_input=None, ad _stdout, _stderr = obj.communicate(_process_input) returncode = obj.returncode obj.stdin.close() - if six.PY3: - if isinstance(_stdout, bytes): - _stdout = _stdout.decode('utf-8', 'surrogateescape') - if isinstance(_stderr, bytes): - _stderr = _stderr.decode('utf-8', 'surrogateescape') + _stdout = utils.safe_decode_utf8(_stdout) + _stderr = utils.safe_decode_utf8(_stderr) - 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