Browse Source

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
Sorin Sbarnea 4 months ago
parent
commit
ce85c96692
1 changed files with 15 additions and 1 deletions
  1. 15
    1
      heat-config/os-refresh-config/configure.d/55-heat-config

+ 15
- 1
heat-config/os-refresh-config/configure.d/55-heat-config View File

@@ -21,6 +21,7 @@ import subprocess
21 21
 import sys
22 22
 
23 23
 import six
24
+import yaml
24 25
 
25 26
 # legacy groups that have never had a hook script
26 27
 WHITELISTED_MISSING_HOOK_SCRIPTS = ['os-apply-config']
@@ -89,6 +90,19 @@ def find_hook_path(group):
89 90
             return hook_path
90 91
 
91 92
 
93
+def humanize(data):
94
+    # reformat a json string with multi-line values into a human readable yaml
95
+    # dump. if conversion fails, it will fallback to original string.
96
+    try:
97
+        return yaml.safe_dump(data,
98
+            allow_unicode=True,
99
+            default_flow_style=False,
100
+            canonical=False,
101
+            default_style="|")
102
+    except Exception:
103
+        return data
104
+
105
+
92 106
 def invoke_hook(c, log):
93 107
     # Sanitize input values (bug 1333992). Convert all String
94 108
     # inputs to strings if they're not already
@@ -151,7 +165,7 @@ def invoke_hook(c, log):
151 165
     stdout, stderr = subproc.communicate(
152 166
         input=json.dumps(c).encode('utf-8', 'replace'))
153 167
 
154
-    log.info(stdout)
168
+    log.info(humanize(stdout))
155 169
     log.debug(stderr)
156 170
 
157 171
     if subproc.returncode:

Loading…
Cancel
Save