~i-franz/cloud-init/enable-vmtools-for-ovf

« back to all changes in this revision

Viewing changes to cloudinit/config/cc_debug.py

  • Committer: Joshua Harlow
  • Date: 2014-11-22 02:10:16 UTC
  • mfrom: (1025.4.1 cloud-init)
  • Revision ID: harlowja@yahoo-inc.com-20141122021016-prnykyg70782zz94
Pretty up the debug module

Previously the usage of the yaml_dumps module was causing
any python unicode key and value to show up as:

'item': !!python/unicode "some string"

This was not very pretty...

Fix this by using safe_dumps (which is also a good thing to
use and allow_unicode=True). Also create a tiny helper function
in the cc_debug module that does not include the yaml start and
end footers (since this module has its own footers and headers).

Also includes a basic sanity test for this module.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
    Log configurations are not output.
34
34
"""
35
35
 
 
36
import copy
 
37
from StringIO import StringIO
 
38
 
36
39
from cloudinit import type_utils
37
40
from cloudinit import util
38
 
import copy
39
 
from StringIO import StringIO
 
41
 
 
42
SKIP_KEYS = frozenset(['log_cfgs'])
40
43
 
41
44
 
42
45
def _make_header(text):
50
53
    return header.getvalue()
51
54
 
52
55
 
 
56
def _dumps(obj):
 
57
    text = util.yaml_dumps(obj, explicit_start=False, explicit_end=False)
 
58
    return text.rstrip()
 
59
 
 
60
 
53
61
def handle(name, cfg, cloud, log, args):
54
62
    """Handler method activated by cloud-init."""
55
63
 
67
75
        return
68
76
    # Clean out some keys that we just don't care about showing...
69
77
    dump_cfg = copy.deepcopy(cfg)
70
 
    for k in ['log_cfgs']:
 
78
    for k in SKIP_KEYS:
71
79
        dump_cfg.pop(k, None)
72
80
    all_keys = list(dump_cfg.keys())
73
81
    for k in all_keys:
76
84
    # Now dump it...
77
85
    to_print = StringIO()
78
86
    to_print.write(_make_header("Config"))
79
 
    to_print.write(util.yaml_dumps(dump_cfg))
 
87
    to_print.write(_dumps(dump_cfg))
80
88
    to_print.write("\n")
81
89
    to_print.write(_make_header("MetaData"))
82
 
    to_print.write(util.yaml_dumps(cloud.datasource.metadata))
 
90
    to_print.write(_dumps(cloud.datasource.metadata))
83
91
    to_print.write("\n")
84
92
    to_print.write(_make_header("Misc"))
85
93
    to_print.write("Datasource: %s\n" %