From 1c17f543bebb8804736df4a9de7740322bfafc68 Mon Sep 17 00:00:00 2001 From: Alexis Lee Date: Thu, 22 Jan 2015 09:48:32 +0000 Subject: [PATCH] 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 --- os_apply_config/apply_config.py | 2 +- os_apply_config/tests/test_apply_config.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/os_apply_config/apply_config.py b/os_apply_config/apply_config.py index ab69b94..46a2245 100755 --- a/os_apply_config/apply_config.py +++ b/os_apply_config/apply_config.py @@ -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)) diff --git a/os_apply_config/tests/test_apply_config.py b/os_apply_config/tests/test_apply_config.py index 87b7b2e..5c6c86d 100644 --- a/os_apply_config/tests/test_apply_config.py +++ b/os_apply_config/tests/test_apply_config.py @@ -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)