From f47fd9ac5ee89025cb368e47001816fdff357953 Mon Sep 17 00:00:00 2001 From: Feng Shengqin Date: Thu, 1 Jun 2017 10:11:57 +0800 Subject: [PATCH] Remove usage of parameter enforce_type Oslo.config deprecated parameter enforce_type and change its default value to True. Remove the usage of it to avoid DeprecationWarning: "Using the 'enforce_type' argument is deprecated in version '4.0' and will be removed in version '5.0': The argument enforce_type has changed its default value to True and then will be removed completely." Change-Id: I59621664773ee5ad264e6da9b15231f30dbb9c40 Closes-Bug: #1694616 --- watcher/tests/api/base.py | 6 ++---- watcher/tests/api/test_hooks.py | 10 +++++----- watcher/tests/api/test_utils.py | 6 ++---- watcher/tests/api/v1/test_actions.py | 3 +-- watcher/tests/api/v1/test_actions_plans.py | 3 +-- watcher/tests/api/v1/test_audit_templates.py | 3 +-- watcher/tests/api/v1/test_audits.py | 3 +-- watcher/tests/api/v1/test_goals.py | 2 +- watcher/tests/api/v1/test_scoring_engines.py | 2 +- watcher/tests/api/v1/test_services.py | 2 +- watcher/tests/api/v1/test_strategies.py | 2 +- watcher/tests/base.py | 8 +++----- watcher/tests/db/base.py | 6 ++---- 13 files changed, 22 insertions(+), 34 deletions(-) diff --git a/watcher/tests/api/base.py b/watcher/tests/api/base.py index 9b858a307..697934777 100644 --- a/watcher/tests/api/base.py +++ b/watcher/tests/api/base.py @@ -51,11 +51,9 @@ class FunctionalTest(base.DbTestCase): def setUp(self): super(FunctionalTest, self).setUp() cfg.CONF.set_override("auth_version", "v2.0", - group='keystone_authtoken', - enforce_type=True) + group='keystone_authtoken') cfg.CONF.set_override("admin_user", "admin", - group='keystone_authtoken', - enforce_type=True) + group='keystone_authtoken') p_services = mock.patch.object(n_service, "send_service_update", new_callable=mock.PropertyMock) diff --git a/watcher/tests/api/test_hooks.py b/watcher/tests/api/test_hooks.py index 7e3622bc4..34df0cbca 100644 --- a/watcher/tests/api/test_hooks.py +++ b/watcher/tests/api/test_hooks.py @@ -120,7 +120,7 @@ class TestNoExceptionTracebackHook(base.FunctionalTest): p = mock.patch.object(root.Root, 'convert') self.root_convert_mock = p.start() self.addCleanup(p.stop) - cfg.CONF.set_override('debug', False, enforce_type=True) + cfg.CONF.set_override('debug', False) def test_hook_exception_success(self): self.root_convert_mock.side_effect = Exception(self.MSG_WITH_TRACE) @@ -164,7 +164,7 @@ class TestNoExceptionTracebackHook(base.FunctionalTest): self._test_hook_without_traceback() def test_hook_without_traceback_debug(self): - cfg.CONF.set_override('debug', True, enforce_type=True) + cfg.CONF.set_override('debug', True) self._test_hook_without_traceback() def _test_hook_on_serverfault(self): @@ -177,12 +177,12 @@ class TestNoExceptionTracebackHook(base.FunctionalTest): return actual_msg def test_hook_on_serverfault(self): - cfg.CONF.set_override('debug', False, enforce_type=True) + cfg.CONF.set_override('debug', False) msg = self._test_hook_on_serverfault() self.assertEqual(self.MSG_WITHOUT_TRACE, msg) def test_hook_on_serverfault_debug(self): - cfg.CONF.set_override('debug', True, enforce_type=True) + cfg.CONF.set_override('debug', True) msg = self._test_hook_on_serverfault() self.assertEqual(self.MSG_WITH_TRACE, msg) @@ -202,7 +202,7 @@ class TestNoExceptionTracebackHook(base.FunctionalTest): self.assertEqual(self.MSG_WITHOUT_TRACE, msg) def test_hook_on_clientfault_debug_tracebacks(self): - cfg.CONF.set_override('debug', True, enforce_type=True) + cfg.CONF.set_override('debug', True) msg = self._test_hook_on_clientfault() self.assertEqual(self.MSG_WITH_TRACE, msg) diff --git a/watcher/tests/api/test_utils.py b/watcher/tests/api/test_utils.py index a889eba4d..9c6d0ce33 100644 --- a/watcher/tests/api/test_utils.py +++ b/watcher/tests/api/test_utils.py @@ -41,8 +41,7 @@ class TestApiUtilsValidScenarios(base.TestCase): ] def test_validate_limit(self): - cfg.CONF.set_override("max_limit", self.max_limit, group="api", - enforce_type=True) + cfg.CONF.set_override("max_limit", self.max_limit, group="api") actual_limit = v1_utils.validate_limit(self.limit) self.assertEqual(self.expected, actual_limit) @@ -54,8 +53,7 @@ class TestApiUtilsInvalidScenarios(base.TestCase): ] def test_validate_limit_invalid_cases(self): - cfg.CONF.set_override("max_limit", self.max_limit, group="api", - enforce_type=True) + cfg.CONF.set_override("max_limit", self.max_limit, group="api") self.assertRaises( wsme.exc.ClientSideError, v1_utils.validate_limit, self.limit ) diff --git a/watcher/tests/api/v1/test_actions.py b/watcher/tests/api/v1/test_actions.py index b0f71045d..ca5881f7c 100644 --- a/watcher/tests/api/v1/test_actions.py +++ b/watcher/tests/api/v1/test_actions.py @@ -384,8 +384,7 @@ class TestListAction(api_base.FunctionalTest): self.assertEqual(3, len(response['actions'])) def test_collection_links_default_limit(self): - cfg.CONF.set_override('max_limit', 3, 'api', - enforce_type=True) + cfg.CONF.set_override('max_limit', 3, 'api') for id_ in range(5): obj_utils.create_test_action(self.context, id=id_, uuid=utils.generate_uuid()) diff --git a/watcher/tests/api/v1/test_actions_plans.py b/watcher/tests/api/v1/test_actions_plans.py index aaae6b09f..d04e1228d 100644 --- a/watcher/tests/api/v1/test_actions_plans.py +++ b/watcher/tests/api/v1/test_actions_plans.py @@ -273,8 +273,7 @@ class TestListActionPlan(api_base.FunctionalTest): self.assertIn(next_marker, response['next']) def test_collection_links_default_limit(self): - cfg.CONF.set_override('max_limit', 3, 'api', - enforce_type=True) + cfg.CONF.set_override('max_limit', 3, 'api') for id_ in range(5): obj_utils.create_test_action_plan( self.context, id=id_, uuid=utils.generate_uuid()) diff --git a/watcher/tests/api/v1/test_audit_templates.py b/watcher/tests/api/v1/test_audit_templates.py index b3ac65885..ace32a86d 100644 --- a/watcher/tests/api/v1/test_audit_templates.py +++ b/watcher/tests/api/v1/test_audit_templates.py @@ -231,8 +231,7 @@ class TestListAuditTemplate(FunctionalTestWithSetup): self.assertIn(next_marker, response['next']) def test_collection_links_default_limit(self): - cfg.CONF.set_override('max_limit', 3, 'api', - enforce_type=True) + cfg.CONF.set_override('max_limit', 3, 'api') for id_ in range(5): obj_utils.create_test_audit_template( self.context, id=id_, uuid=utils.generate_uuid(), diff --git a/watcher/tests/api/v1/test_audits.py b/watcher/tests/api/v1/test_audits.py index 47749ee52..a42e333eb 100644 --- a/watcher/tests/api/v1/test_audits.py +++ b/watcher/tests/api/v1/test_audits.py @@ -234,8 +234,7 @@ class TestListAudit(api_base.FunctionalTest): self.assertIn(next_marker, response['next']) def test_collection_links_default_limit(self): - cfg.CONF.set_override('max_limit', 3, 'api', - enforce_type=True) + cfg.CONF.set_override('max_limit', 3, 'api') for id_ in range(5): obj_utils.create_test_audit(self.context, id=id_, uuid=utils.generate_uuid()) diff --git a/watcher/tests/api/v1/test_goals.py b/watcher/tests/api/v1/test_goals.py index 8c6c8fe12..6c71c1598 100644 --- a/watcher/tests/api/v1/test_goals.py +++ b/watcher/tests/api/v1/test_goals.py @@ -116,7 +116,7 @@ class TestListGoal(api_base.FunctionalTest): self.context, id=idx, uuid=utils.generate_uuid(), name='GOAL_{0}'.format(idx)) - cfg.CONF.set_override('max_limit', 3, 'api', enforce_type=True) + cfg.CONF.set_override('max_limit', 3, 'api') response = self.get_json('/goals') self.assertEqual(3, len(response['goals'])) diff --git a/watcher/tests/api/v1/test_scoring_engines.py b/watcher/tests/api/v1/test_scoring_engines.py index e2b03ac73..2e7b3cc2c 100644 --- a/watcher/tests/api/v1/test_scoring_engines.py +++ b/watcher/tests/api/v1/test_scoring_engines.py @@ -109,7 +109,7 @@ class TestListScoringEngine(api_base.FunctionalTest): obj_utils.create_test_scoring_engine( self.context, id=idx, uuid=utils.generate_uuid(), name=str(idx), description='SE_{0}'.format(idx)) - cfg.CONF.set_override('max_limit', 3, 'api', enforce_type=True) + cfg.CONF.set_override('max_limit', 3, 'api') response = self.get_json('/scoring_engines') self.assertEqual(3, len(response['scoring_engines'])) diff --git a/watcher/tests/api/v1/test_services.py b/watcher/tests/api/v1/test_services.py index ccbd45ff8..c556d9597 100644 --- a/watcher/tests/api/v1/test_services.py +++ b/watcher/tests/api/v1/test_services.py @@ -127,7 +127,7 @@ class TestListService(api_base.FunctionalTest): self.context, id=idx, host='CONTROLLER', name='SERVICE_{0}'.format(idx)) - cfg.CONF.set_override('max_limit', 3, 'api', enforce_type=True) + cfg.CONF.set_override('max_limit', 3, 'api') response = self.get_json('/services') self.assertEqual(3, len(response['services'])) diff --git a/watcher/tests/api/v1/test_strategies.py b/watcher/tests/api/v1/test_strategies.py index 5be3fd448..6edcd4819 100644 --- a/watcher/tests/api/v1/test_strategies.py +++ b/watcher/tests/api/v1/test_strategies.py @@ -128,7 +128,7 @@ class TestListStrategy(api_base.FunctionalTest): self.context, id=idx, uuid=utils.generate_uuid(), name='STRATEGY_{0}'.format(idx)) - cfg.CONF.set_override('max_limit', 3, 'api', enforce_type=True) + cfg.CONF.set_override('max_limit', 3, 'api') response = self.get_json('/strategies') self.assertEqual(3, len(response['strategies'])) diff --git a/watcher/tests/base.py b/watcher/tests/base.py index 6a23a6f3b..fc5708107 100644 --- a/watcher/tests/base.py +++ b/watcher/tests/base.py @@ -59,11 +59,9 @@ class TestCase(BaseTestCase): self.messaging_conf.transport_driver = 'fake' cfg.CONF.set_override("auth_type", "admin_token", - group='keystone_authtoken', - enforce_type=True) + group='keystone_authtoken') cfg.CONF.set_override("auth_uri", "http://127.0.0.1/identity", - group='keystone_authtoken', - enforce_type=True) + group='keystone_authtoken') app_config_path = os.path.join(os.path.dirname(__file__), 'config.py') self.app = testing.load_test_app(app_config_path) @@ -128,7 +126,7 @@ class TestCase(BaseTestCase): """Override config options for a test.""" group = kw.pop('group', None) for k, v in kw.items(): - CONF.set_override(k, v, group, enforce_type=True) + CONF.set_override(k, v, group) def get_path(self, project_file=None): """Get the absolute path to a file. Used for testing the API. diff --git a/watcher/tests/db/base.py b/watcher/tests/db/base.py index 2370659cd..57d7a610e 100644 --- a/watcher/tests/db/base.py +++ b/watcher/tests/db/base.py @@ -70,11 +70,9 @@ class DbTestCase(base.TestCase): return next(self._id_gen) def setUp(self): - cfg.CONF.set_override("enable_authentication", False, - enforce_type=True) + cfg.CONF.set_override("enable_authentication", False) # To use in-memory SQLite DB - cfg.CONF.set_override("connection", "sqlite://", group="database", - enforce_type=True) + cfg.CONF.set_override("connection", "sqlite://", group="database") super(DbTestCase, self).setUp()