From 83432149e212155469b1e9f06eb0095121377356 Mon Sep 17 00:00:00 2001 From: Ben Howard Date: Mon, 7 Dec 2015 16:48:51 -0700 Subject: Import patches-unapplied version 2.1.2-0ubuntu1 to ubuntu/xenial-proposed Imported using git-ubuntu import. Changelog parent: 04946cba49f19c0b6b876bccdbb36d47334af002 New changelog entries: * New upstream release (LP: #1523715): - Bug fixes for Ubuntu 15.10 on Azure - Enablement for Azure Stack - Dropped patch for systemd job as upstream now includes it. --- azurelinuxagent/utils/shellutil.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'azurelinuxagent/utils/shellutil.py') diff --git a/azurelinuxagent/utils/shellutil.py b/azurelinuxagent/utils/shellutil.py index f4305d9..372c78a 100644 --- a/azurelinuxagent/utils/shellutil.py +++ b/azurelinuxagent/utils/shellutil.py @@ -1,4 +1,4 @@ -# Windows Azure Linux Agent +# Microsoft Azure Linux Agent # # Copyright 2014 Microsoft Corporation # @@ -65,21 +65,25 @@ def run(cmd, chk_err=True): retcode,out=run_get_output(cmd,chk_err) return retcode -def run_get_output(cmd, chk_err=True): +def run_get_output(cmd, chk_err=True, log_cmd=True): """ Wrapper for subprocess.check_output. Execute 'cmd'. Returns return code and STDOUT, trapping expected exceptions. Reports exceptions to Error if chk_err parameter is True """ - logger.verb("run cmd '{0}'", cmd) + if log_cmd: + logger.verb(u"run cmd '{0}'", cmd) try: output=subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) + output = text(output, encoding='utf-8', errors="backslashreplace") except subprocess.CalledProcessError as e : - if chk_err : - logger.error("run cmd '{0}' failed", e.cmd) - logger.error("Error Code:{0}", e.returncode) - logger.error("Result:{0}", e.output[:-1].decode('latin-1')) - return e.returncode, e.output.decode('latin-1') - return 0, text(output, encoding="utf-8") + output = text(e.output, encoding='utf-8', errors="backslashreplace") + if chk_err: + if log_cmd: + logger.error(u"run cmd '{0}' failed", e.cmd) + logger.error(u"Error Code:{0}", e.returncode) + logger.error(u"Result:{0}", output) + return e.returncode, output + return 0, output #End shell command util functions -- cgit v1.2.3