From ce85c966929a89226f668bdff9d45898671d8b08 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Mon, 10 Dec 2018 15:44:07 +0000 Subject: [PATCH] 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 --- .../os-refresh-config/configure.d/55-heat-config | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/heat-config/os-refresh-config/configure.d/55-heat-config b/heat-config/os-refresh-config/configure.d/55-heat-config index 25659c2..9227362 100755 --- a/heat-config/os-refresh-config/configure.d/55-heat-config +++ b/heat-config/os-refresh-config/configure.d/55-heat-config @@ -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: