Fix printing of keys with non-string values
When trying to print a key which has a non-string value (e.g. bool or int), TypeError exception is raised. This is caused by the fact, that ensure_type() function accepts string values, but parsed values are passed (i.e. False instead of 'False' or 12 instead of '12' and so on). Change-Id: I10f5e60994bc34288f15af07d2d255ace3755b57 Closes-Bug: #1243263
This commit is contained in:
parent
d99f3c842a
commit
a666935692
|
@ -65,7 +65,7 @@ def print_key(
|
|||
else:
|
||||
raise exc.ConfigException(
|
||||
'key %s does not exist in %s' % (key, config_path))
|
||||
value_types.ensure_type(config, type_name)
|
||||
value_types.ensure_type(str(config), type_name)
|
||||
print(str(config))
|
||||
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ TEMPLATE_PATHS = [
|
|||
# config for example tree
|
||||
CONFIG = {
|
||||
"x": "foo",
|
||||
"y": False,
|
||||
"database": {
|
||||
"url": "sqlite:///blah"
|
||||
}
|
||||
|
@ -90,6 +91,15 @@ class TestRunOSConfigApplier(testtools.TestCase):
|
|||
self.stdout.read().strip())
|
||||
self.assertEqual('', self.logger.output)
|
||||
|
||||
def test_print_non_string_key(self):
|
||||
self.assertEqual(0, apply_config.main(
|
||||
['os-apply-config.py', '--metadata', self.path, '--key',
|
||||
'y', '--type', 'raw']))
|
||||
self.stdout.seek(0)
|
||||
self.assertEqual(str(CONFIG['y']),
|
||||
self.stdout.read().strip())
|
||||
self.assertEqual('', self.logger.output)
|
||||
|
||||
def test_print_key_missing(self):
|
||||
self.assertEqual(1, apply_config.main(
|
||||
['os-apply-config.py', '--metadata', self.path, '--key',
|
||||
|
|
Loading…
Reference in New Issue