Print JSON-compatible booleans

Given os-apply-config takes a JSON file as input and prints JSON-style
strings not Python ones, Booleans present an anomaly.

These are printed using `str(config)`, resulting in "True" and "False"
rather than the lowercase and JSON-compatible "true" and "false". This
patch corrects this.

There is some risk of breaking users but it should be trivial for them
to fix their scripts. As I write this, o-a-c is at 0.1.28, so we're
allowed breaking changes and I believe this is the last change required
to make all output JSON-compatible.

Change-Id: Ib41d3b01656fc7afc4911fd78ba7c1116aa9b1c9
This commit is contained in:
Alexis Lee 2015-01-22 09:48:32 +00:00
parent fcb3d0f96f
commit 1c17f543be
2 changed files with 2 additions and 2 deletions

View File

@ -102,7 +102,7 @@ def print_key(
raise exc.ConfigException(
'key %s does not exist in %s' % (key, config_path))
value_types.ensure_type(str(config), type_name)
if isinstance(config, (dict, list)):
if isinstance(config, (dict, list, bool)):
print(json.dumps(config))
else:
print(str(config))

View File

@ -135,7 +135,7 @@ class TestRunOSConfigApplier(testtools.TestCase):
['os-apply-config.py', '--metadata', self.path, '--key',
'y', '--type', 'raw']))
self.stdout.seek(0)
self.assertEqual(str(CONFIG['y']),
self.assertEqual("false",
self.stdout.read().strip())
self.assertEqual('', self.logger.output)