Merge "Fix py3 issue of heat-container-agent"

This commit is contained in:
Zuul 2019-08-01 10:25:41 +00:00 committed by Gerrit Code Review
commit f9ad8ce302
5 changed files with 18 additions and 15 deletions

View File

@ -18,6 +18,7 @@ import os
import shutil
import stat
import subprocess
import six
import sys
import requests
@ -93,7 +94,7 @@ def invoke_hook(c, log):
hot_inputs = c.get('inputs', [])
for hot_input in hot_inputs:
if hot_input.get('type', None) == 'String' and \
not isinstance(hot_input['value'], basestring):
not isinstance(hot_input['value'], six.string_types):
hot_input['value'] = str(hot_input['value'])
iv = dict((i['name'], i['value']) for i in c['inputs'])
# The group property indicates whether it is softwarecomponent or
@ -145,7 +146,8 @@ def invoke_hook(c, log):
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = subproc.communicate(input=json.dumps(c))
stdout, stderr = subproc.communicate(
input=json.dumps(c).encode('utf-8', 'replace'))
log.info(stdout)
log.debug(stderr)
@ -158,7 +160,7 @@ def invoke_hook(c, log):
try:
if stdout:
signal_data = json.loads(stdout)
signal_data = json.loads(stdout.decode('utf-8', 'replace'))
except ValueError:
signal_data = {
'deploy_stdout': stdout,
@ -178,7 +180,8 @@ def invoke_hook(c, log):
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = subproc.communicate(input=json.dumps(signal_data))
stdout, stderr = subproc.communicate(
input=json.dumps(signal_data).encode('utf-8', 'replace'))
log.info(stdout)

View File

@ -58,7 +58,7 @@ def trim_response(response, trimmed_values=None):
"""
trimmed_values = trimmed_values or ('deploy_stdout', 'deploy_stderr')
str_response = json.dumps(response, ensure_ascii=True, encoding='utf-8')
str_response = json.dumps(response, ensure_ascii=True)
len_total = len(str_response)
offset = MAX_RESPONSE_SIZE - len_total
if offset >= 0:

View File

@ -30,8 +30,8 @@ def prepare_dir(path):
def build_response(deploy_stdout, deploy_stderr, deploy_status_code):
return {
'deploy_stdout': deploy_stdout,
'deploy_stderr': deploy_stderr,
'deploy_stdout': deploy_stdout.decode('utf-8', 'replace'),
'deploy_stderr': deploy_stderr.decode('utf-8', 'replace'),
'deploy_status_code': deploy_status_code,
}

View File

@ -38,13 +38,13 @@ def write_input_file(file_path, content):
prepare_dir(os.path.dirname(file_path))
with os.fdopen(os.open(
file_path, os.O_CREAT | os.O_WRONLY, 0o600), 'w') as f:
f.write(content.encode('utf-8'))
f.write(content)
def build_response(deploy_stdout, deploy_stderr, deploy_status_code):
return {
'deploy_stdout': deploy_stdout,
'deploy_stderr': deploy_stderr,
'deploy_stdout': deploy_stdout.decode('utf-8', 'replace'),
'deploy_stderr': deploy_stderr.decode('utf-8', 'replace'),
'deploy_status_code': deploy_status_code,
}

View File

@ -59,15 +59,15 @@ def main(argv=sys.argv):
env['heat_outputs_path'] = heat_outputs_path
with os.fdopen(os.open(fn, os.O_CREAT | os.O_WRONLY, 0o700), 'w') as f:
f.write(c.get('config', '').encode('utf-8'))
f.write(c.get('config', ''))
log.debug('Running %s' % fn)
subproc = subprocess.Popen([fn], stdout=subprocess.PIPE,
stderr=subprocess.PIPE, env=env)
stdout, stderr = subproc.communicate()
log.info(stdout)
log.debug(stderr)
log.info(stdout.decode('utf-8', 'replace'))
log.debug(stderr.decode('utf-8', 'replace'))
if subproc.returncode:
log.error("Error running %s. [%s]\n" % (fn, subproc.returncode))
@ -85,8 +85,8 @@ def main(argv=sys.argv):
pass
response.update({
'deploy_stdout': stdout,
'deploy_stderr': stderr,
'deploy_stdout': stdout.decode('utf-8', 'replace'),
'deploy_stderr': stderr.decode('utf-8', 'replace'),
'deploy_status_code': subproc.returncode,
})