test: make enforce_type=True in CONF.set_override
Current Glance uses 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, 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. Change-Id: I2defdfff3b14828133921e97acfea6b08c8fc20a Related-Bug: #1517839
This commit is contained in:
parent
a1c844c893
commit
1999bb6cac
@ -117,7 +117,8 @@ class _ImportToFS(task.Task):
|
||||
backend.register_opts(conf)
|
||||
conf.set_override('filesystem_store_datadir',
|
||||
CONF.task.work_dir,
|
||||
group='glance_store')
|
||||
group='glance_store',
|
||||
enforce_type=True)
|
||||
|
||||
# NOTE(flaper87): Do not even try to judge me for this... :(
|
||||
# With the glance_store refactor, this code will change, until
|
||||
|
@ -21,7 +21,8 @@ from glance.tests.functional.db import base
|
||||
|
||||
|
||||
def get_db(config):
|
||||
CONF.set_override('data_api', 'glance.db.simple.api')
|
||||
CONF.set_override('data_api', 'glance.db.simple.api',
|
||||
enforce_type=True)
|
||||
db_api = glance.db.get_api()
|
||||
return db_api
|
||||
|
||||
|
@ -70,7 +70,8 @@ class TestPropertyQuotaViolations(base.ApiTest):
|
||||
self.assertEqual(0, len(image_list))
|
||||
|
||||
orig_property_quota = 10
|
||||
CONF.set_override('image_property_quota', orig_property_quota)
|
||||
CONF.set_override('image_property_quota', orig_property_quota,
|
||||
enforce_type=True)
|
||||
|
||||
# Create an image (with deployer-defined properties)
|
||||
req_body = {'name': 'testimg',
|
||||
|
@ -538,7 +538,8 @@ class MigrationsMixin(test_migrations.WalkVersionsMixin):
|
||||
|
||||
def test_legacy_parse_swift_uri_017(self):
|
||||
metadata_encryption_key = 'a' * 16
|
||||
CONF.set_override('metadata_encryption_key', metadata_encryption_key)
|
||||
CONF.set_override('metadata_encryption_key', metadata_encryption_key,
|
||||
enforce_type=True)
|
||||
self.addCleanup(CONF.reset)
|
||||
(legacy_parse_uri, encrypt_location) = from_migration_import(
|
||||
'017_quote_encrypted_swift_credentials', ['legacy_parse_uri',
|
||||
@ -553,7 +554,8 @@ class MigrationsMixin(test_migrations.WalkVersionsMixin):
|
||||
|
||||
def _pre_upgrade_017(self, engine):
|
||||
metadata_encryption_key = 'a' * 16
|
||||
CONF.set_override('metadata_encryption_key', metadata_encryption_key)
|
||||
CONF.set_override('metadata_encryption_key', metadata_encryption_key,
|
||||
enforce_type=True)
|
||||
self.addCleanup(CONF.reset)
|
||||
images = db_utils.get_table(engine, 'images')
|
||||
unquoted = 'swift://acct:usr:pass@example.com/container/obj-id'
|
||||
|
Loading…
Reference in New Issue
Block a user