Make heat-config logging more human friendly
Address problem where the logs made by heat-config where barely readable as they contained wrapped stdout/stderr lines. By printing the value in beautified YAML format, we make it possible for the humans to read them. As a safety measure if conversion fails it fallsback to original string. Change-Id: I64b2beb6eb2927c683f5188b000a7210be7da592 Partial-Bug: #1787912
This commit is contained in:
parent
3bfcd6bceb
commit
ce85c96692
@ -21,6 +21,7 @@ import subprocess
|
||||
import sys
|
||||
|
||||
import six
|
||||
import yaml
|
||||
|
||||
# legacy groups that have never had a hook script
|
||||
WHITELISTED_MISSING_HOOK_SCRIPTS = ['os-apply-config']
|
||||
@ -89,6 +90,19 @@ def find_hook_path(group):
|
||||
return hook_path
|
||||
|
||||
|
||||
def humanize(data):
|
||||
# reformat a json string with multi-line values into a human readable yaml
|
||||
# dump. if conversion fails, it will fallback to original string.
|
||||
try:
|
||||
return yaml.safe_dump(data,
|
||||
allow_unicode=True,
|
||||
default_flow_style=False,
|
||||
canonical=False,
|
||||
default_style="|")
|
||||
except Exception:
|
||||
return data
|
||||
|
||||
|
||||
def invoke_hook(c, log):
|
||||
# Sanitize input values (bug 1333992). Convert all String
|
||||
# inputs to strings if they're not already
|
||||
@ -151,7 +165,7 @@ def invoke_hook(c, log):
|
||||
stdout, stderr = subproc.communicate(
|
||||
input=json.dumps(c).encode('utf-8', 'replace'))
|
||||
|
||||
log.info(stdout)
|
||||
log.info(humanize(stdout))
|
||||
log.debug(stderr)
|
||||
|
||||
if subproc.returncode:
|
||||
|
Loading…
Reference in New Issue
Block a user