Test: make enforce_type=True in CONF.set_override

Method CONF.set_override to change config option's
value with designated value in unit test, but never check if the
designated vaule is valid. Each config option has a type like StrOpt,
BoolOpt, etc. StrOpt with parameter choices only allows values in set
of choices. In short, each config option has limitation for type
and value. In production code, oslo.conf can ensure user's input is
valid, but in unit test, test methods can pass if we use method
CONF.set_override without parameter enforce_type=True even we pass wrong
type or wrong value to config option. This commit makes sure calling
method CONF.set_override with enforce_type=True and fixes violations.

Change-Id: Ibf5570b74947b071b96aa7ca4a682affb137d065
Related-Bug: #1517839
This commit is contained in:
Chaozhe.Chen 2016-01-11 17:48:39 +08:00
parent 22bc7731de
commit f9b52a93bb
5 changed files with 15 additions and 8 deletions

View File

@ -69,7 +69,8 @@ class TestCase(testscenarios.TestWithScenarios, base.BaseTestCase):
def setUp(self):
super(TestCase, self).setUp()
self.conf = self.useFixture(config_fixture.Config()).conf
self.conf.set_override('connection', self.db_url, 'database')
self.conf.set_override('connection', self.db_url, 'database',
enforce_type=True)
self.conn = ck_db_api.get_instance()
migration = self.conn.get_migration()
migration.upgrade('head')

View File

@ -186,13 +186,16 @@ class ConfigFixture(fixture.GabbiFixture):
msg_conf = conffixture.ConfFixture(conf)
msg_conf.transport_driver = 'fake'
conf.import_group('api', 'cloudkitty.api.app')
conf.set_override('auth_strategy', 'noauth')
conf.set_override('connection', 'sqlite:///', 'database')
conf.set_override('auth_strategy', 'noauth', enforce_type=True)
conf.set_override('connection', 'sqlite:///', 'database',
enforce_type=True)
conf.set_override('policy_file',
os.path.abspath('etc/cloudkitty/policy.json'),
group='oslo_policy')
group='oslo_policy',
enforce_type=True)
conf.import_group('storage', 'cloudkitty.storage')
conf.set_override('backend', 'sqlalchemy', 'storage')
conf.set_override('backend', 'sqlalchemy', 'storage',
enforce_type=True)
self.conf = conf
self.conn = ck_db_api.get_instance()
migration = self.conn.get_migration()

View File

@ -41,7 +41,8 @@ class StorageTest(tests.TestCase):
super(StorageTest, self).setUp()
self._tenant_id = samples.TENANT
self._other_tenant_id = '8d3ae50089ea4142-9c6e1269db6a0b64'
self.conf.set_override('backend', self.storage_backend, 'storage')
self.conf.set_override('backend', self.storage_backend, 'storage',
enforce_type=True)
self.storage = storage.get_storage()
self.storage.init()

View File

@ -70,7 +70,8 @@ def Client(**kwargs):
class KeystoneFetcherTest(tests.TestCase):
def setUp(self):
super(KeystoneFetcherTest, self).setUp()
self.conf.set_override('backend', 'keystone', 'tenant_fetcher')
self.conf.set_override('backend', 'keystone', 'tenant_fetcher',
enforce_type=True)
self.conf.import_group('keystone_fetcher',
'cloudkitty.tenant_fetcher.keystone')

View File

@ -38,7 +38,8 @@ class OrchestratorTest(tests.TestCase):
super(OrchestratorTest, self).setUp()
messaging_conf = self.useFixture(conffixture.ConfFixture(self.conf))
messaging_conf.transport_driver = 'fake'
self.conf.set_override('backend', 'keystone', 'tenant_fetcher')
self.conf.set_override('backend', 'keystone', 'tenant_fetcher',
enforce_type=True)
self.conf.import_group('keystone_fetcher',
'cloudkitty.tenant_fetcher.keystone')