Merge "Chef: Fix encoding and Python 3 support"

This commit is contained in:
Zuul 2018-05-10 13:02:37 +00:00 committed by Gerrit Code Review
commit 7fe19b8ed8
2 changed files with 11 additions and 10 deletions

View File

@ -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']

View File

@ -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()):