From 1999bb6cac8c9519c8d462ccfe82880b54607e29 Mon Sep 17 00:00:00 2001 From: "ChangBo Guo(gcb)" Date: Thu, 19 Nov 2015 18:48:05 +0800 Subject: [PATCH] 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 --- glance/async/flows/base_import.py | 3 ++- glance/tests/functional/db/test_simple.py | 3 ++- .../tests/integration/v2/test_property_quota_violations.py | 3 ++- glance/tests/unit/test_migrations.py | 6 ++++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/glance/async/flows/base_import.py b/glance/async/flows/base_import.py index e884e96e..b2676ed3 100644 --- a/glance/async/flows/base_import.py +++ b/glance/async/flows/base_import.py @@ -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 diff --git a/glance/tests/functional/db/test_simple.py b/glance/tests/functional/db/test_simple.py index 8e978022..4c1d4487 100644 --- a/glance/tests/functional/db/test_simple.py +++ b/glance/tests/functional/db/test_simple.py @@ -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 diff --git a/glance/tests/integration/v2/test_property_quota_violations.py b/glance/tests/integration/v2/test_property_quota_violations.py index 8fdebd5c..25b65b1f 100644 --- a/glance/tests/integration/v2/test_property_quota_violations.py +++ b/glance/tests/integration/v2/test_property_quota_violations.py @@ -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', diff --git a/glance/tests/unit/test_migrations.py b/glance/tests/unit/test_migrations.py index 57b74bdb..2a2a7037 100644 --- a/glance/tests/unit/test_migrations.py +++ b/glance/tests/unit/test_migrations.py @@ -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'