Maintain datatypes when loading configs from DB

When loading domain configuration from database we are changing
the actual data type of the configuration to unicode string. We
want to preserve the type of the configuration value because
otherwise we have problems later in the code when for example a
'bool' configuration value like 'use_tls' is evaluated incorrectly
because its type is unicode instead of bool.

Closes-Bug: #1461299
Change-Id: I54f5bd19910528b18c428bb3702c8cd4db3cc801
This commit is contained in:
Roxana Gherle 2015-08-13 11:09:40 -07:00
parent 06eca086a0
commit 781e78b41b
2 changed files with 10 additions and 2 deletions

View File

@ -201,7 +201,8 @@ class DomainConfigs(dict):
for group in specific_config:
for option in specific_config[group]:
domain_config['cfg'].set_override(
option, specific_config[group][option], group)
option, specific_config[group][option],
group, enforce_type=True)
domain_config['cfg_overrides'] = specific_config
domain_config['driver'] = self._load_driver(domain_config)

View File

@ -142,7 +142,8 @@ class TestDatabaseDomainConfigs(tests.TestCase):
self.resource_api.create_domain(domain['id'], domain)
# Override two config options for our domain
conf = {'ldap': {'url': uuid.uuid4().hex,
'suffix': uuid.uuid4().hex},
'suffix': uuid.uuid4().hex,
'use_tls': 'True'},
'identity': {
'driver': 'ldap'}}
self.domain_config_api.create_config(domain['id'], conf)
@ -156,6 +157,11 @@ class TestDatabaseDomainConfigs(tests.TestCase):
self.assertEqual(conf['ldap']['suffix'], res.ldap.suffix)
self.assertEqual(CONF.ldap.query_scope, res.ldap.query_scope)
# Make sure the override is not changing the type of the config value
use_tls_type = type(CONF.ldap.use_tls)
self.assertEqual(use_tls_type(conf['ldap']['use_tls']),
res.ldap.use_tls)
# Now turn off using database domain configuration and check that the
# default config file values are now seen instead of the overrides.
CONF.set_override('domain_configurations_from_database', False,
@ -166,4 +172,5 @@ class TestDatabaseDomainConfigs(tests.TestCase):
res = domain_config.get_domain_conf(domain['id'])
self.assertEqual(CONF.ldap.url, res.ldap.url)
self.assertEqual(CONF.ldap.suffix, res.ldap.suffix)
self.assertEqual(CONF.ldap.use_tls, res.ldap.use_tls)
self.assertEqual(CONF.ldap.query_scope, res.ldap.query_scope)