diff --git a/heat-config-chef/install.d/hook-chef.py b/heat-config-chef/install.d/hook-chef.py index 61743a8..41ef4e7 100755 --- a/heat-config-chef/install.d/hook-chef.py +++ b/heat-config-chef/install.d/hook-chef.py @@ -101,20 +101,21 @@ def main(argv=sys.argv): log.error("Error cloning kitchen from %s into %s: %s", kitchen, kitchen_path, err) json.dump({'deploy_status_code': ret, - 'deploy_stdout': out, - 'deploy_stderr': err}, + 'deploy_stdout': out.decode('utf-8', 'replace'), + 'deploy_stderr': err.decode('utf-8', 'replace')}, sys.stdout) return 0 # write the json attributes ret, out, err = run_subproc(['hostname', '-f']) if ret == 0: - fqdn = out.strip() + fqdn = out.decode('utf-8').strip() else: err = "Could not determine hostname with hostname -f" json.dump({'deploy_status_code': ret, 'deploy_stdout': "", - 'deploy_stderr': err}, sys.stdout) + 'deploy_stderr': err.decode('utf-8', 'replace')}, + sys.stdout) return 0 node_config = {} for input in c['inputs']: @@ -142,10 +143,10 @@ def main(argv=sys.argv): cmd = ['chef-client', '-z', '--config', config_path, "-j", node_file] ret, out, err = run_subproc(cmd, heat_outputs_path=heat_outputs_path) resp = {'deploy_status_code': ret, - 'deploy_stdout': out, - 'deploy_stderr': err} + 'deploy_stdout': out.decode('utf-8', 'replace'), + 'deploy_stderr': err.decode('utf-8', 'replace')} log.debug("Chef output: %s", out) - if err: + if ret != 0: log.error("Chef return code %s:\n%s", ret, err) for output in c.get('outputs', []): output_name = output['name'] diff --git a/tests/test_hook_chef.py b/tests/test_hook_chef.py index f55f73d..0bc4bab 100644 --- a/tests/test_hook_chef.py +++ b/tests/test_hook_chef.py @@ -81,7 +81,7 @@ class HookChefTest(common.RunScriptTest): sys.stdin.seek(0) mock_subproc = mock.Mock() mock_popen.return_value = mock_subproc - mock_subproc.communicate.return_value = ("out", "err") + mock_subproc.communicate.return_value = (b"out", b"err") mock_subproc.returncode = 0 with mock.patch("os.fdopen", mock.mock_open()) as mfdopen: with mock.patch("os.open", mock.mock_open()): @@ -133,7 +133,7 @@ class HookChefTest(common.RunScriptTest): sys.stdin.seek(0) mock_subproc = mock.Mock() mock_popen.return_value = mock_subproc - mock_subproc.communicate.return_value = ("out", "err") + mock_subproc.communicate.return_value = (b"out", b"err") mock_subproc.returncode = 0 with mock.patch("os.fdopen", mock.mock_open()) as mfdopen: with mock.patch("os.open", mock.mock_open()): @@ -178,7 +178,7 @@ class HookChefTest(common.RunScriptTest): sys.stdin.seek(0) mock_subproc = mock.Mock() mock_popen.return_value = mock_subproc - mock_subproc.communicate.return_value = ("out", "err") + mock_subproc.communicate.return_value = (b"out", b"err") mock_subproc.returncode = 0 with mock.patch("os.fdopen", mock.mock_open()) as mfdopen: with mock.patch("os.open", mock.mock_open()):