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 word, 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.
This commit also fixes violations.

Note: We can't set enforce_type=True by default in oslo.config now, it
may break all project's unit test. We can switch enforce_type=True by
default when all project fix violations like this commit.

Related-Bug: #1517839

Depends-On: I42ceeccf59111057b5a92c849c9bb5f83255b324

Change-Id: Iffce1b62625ac2a6b00547e3791b76d289066514
This commit is contained in:
ChangBo Guo(gcb) 2015-11-19 19:03:01 +08:00
parent bf2fefb6cc
commit 9383e88b84
3 changed files with 8 additions and 5 deletions

View File

@ -40,7 +40,7 @@ class SaharaTestCase(base.BaseTestCase):
tenant_name=tenant_name, **kwargs))
def override_config(self, name, override, group=None):
main.CONF.set_override(name, override, group)
main.CONF.set_override(name, override, group, enforce_type=True)
self.addCleanup(main.CONF.clear_override, name, group)

View File

@ -60,7 +60,8 @@ class BaseWalkMigrationTestCase(object):
should use oslo_config and openstack.commom.db.sqlalchemy.session with
database functionality (reset default settings and session cleanup).
"""
CONF.set_override('connection', str(engine.url), group='database')
CONF.set_override('connection', str(engine.url), group='database',
enforce_type=True)
sa.cleanup()
def _alembic_command(self, alembic_command, engine, *args, **kwargs):
@ -69,7 +70,8 @@ class BaseWalkMigrationTestCase(object):
We should redefine this setting for getting info.
"""
self.ALEMBIC_CONFIG.stdout = buf = io.StringIO()
CONF.set_override('connection', str(engine.url), group='database')
CONF.set_override('connection', str(engine.url), group='database',
enforce_type=True)
sa.cleanup()
getattr(command, alembic_command)(*args, **kwargs)
res = buf.getvalue().strip()
@ -171,7 +173,8 @@ class TestModelsMigrationsSync(t_m.ModelsMigrationsSync):
return self.engine
def db_sync(self, engine):
CONF.set_override('connection', str(engine.url), group='database')
CONF.set_override('connection', str(engine.url), group='database',
enforce_type=True)
alembic.command.upgrade(self.ALEMBIC_CONFIG, 'head')
def get_metadata(self):

View File

@ -66,7 +66,7 @@ def validate_config():
'{supported}). Falling back to Cinder API version 2.')
.format(bad=CONF.cinder.api_version,
supported=[1, 2]))
CONF.set_override('api_version', 2, group='cinder')
CONF.set_override('api_version', 2, group='cinder', enforce_type=True)
def client():