diff --git a/watcher/tests/__init__.py b/watcher/tests/__init__.py index cd9ff346d..13ddc57ab 100644 --- a/watcher/tests/__init__.py +++ b/watcher/tests/__init__.py @@ -32,7 +32,8 @@ class FunctionalTest(unittest.TestCase): """ def setUp(self): - cfg.CONF.set_override("enable_authentication", False) + cfg.CONF.set_override("enable_authentication", False, + enforce_type=True) self.app = testing.load_test_app(os.path.join( os.path.dirname(__file__), 'config.py' diff --git a/watcher/tests/api/base.py b/watcher/tests/api/base.py index 806d68def..d2fe347ee 100644 --- a/watcher/tests/api/base.py +++ b/watcher/tests/api/base.py @@ -47,9 +47,11 @@ class FunctionalTest(base.DbTestCase): def setUp(self): super(FunctionalTest, self).setUp() cfg.CONF.set_override("auth_version", "v2.0", - group='keystone_authtoken') + group='keystone_authtoken', + enforce_type=True) cfg.CONF.set_override("admin_user", "admin", - group='keystone_authtoken') + group='keystone_authtoken', + enforce_type=True) self.app = self._make_app() def reset_pecan(): diff --git a/watcher/tests/api/test_hooks.py b/watcher/tests/api/test_hooks.py index d1fc6ea85..905a11f1a 100644 --- a/watcher/tests/api/test_hooks.py +++ b/watcher/tests/api/test_hooks.py @@ -120,7 +120,7 @@ class TestNoExceptionTracebackHook(api_base.FunctionalTest): self.assertEqual(msg, actual_msg) def test_hook_server_debug_on_serverfault(self): - cfg.CONF.set_override('debug', True) + cfg.CONF.set_override('debug', True, enforce_type=True) self.root_convert_mock.side_effect = Exception(self.MSG_WITH_TRACE) response = self.get_json('/', path_prefix='', expect_errors=True) @@ -130,7 +130,7 @@ class TestNoExceptionTracebackHook(api_base.FunctionalTest): self.assertEqual(self.MSG_WITHOUT_TRACE, actual_msg) def test_hook_server_debug_on_clientfault(self): - cfg.CONF.set_override('debug', True) + cfg.CONF.set_override('debug', True, enforce_type=True) client_error = Exception(self.MSG_WITH_TRACE) client_error.code = 400 self.root_convert_mock.side_effect = client_error diff --git a/watcher/tests/api/test_utils.py b/watcher/tests/api/test_utils.py index 1aedfd3ba..3a84be21f 100644 --- a/watcher/tests/api/test_utils.py +++ b/watcher/tests/api/test_utils.py @@ -41,7 +41,8 @@ class TestApiUtilsValidScenarios(base.TestCase): ] def test_validate_limit(self): - cfg.CONF.set_override("max_limit", self.max_limit, group="api") + cfg.CONF.set_override("max_limit", self.max_limit, group="api", + enforce_type=True) actual_limit = v1_utils.validate_limit(self.limit) self.assertEqual(actual_limit, self.expected) @@ -53,7 +54,8 @@ class TestApiUtilsInvalidScenarios(base.TestCase): ] def test_validate_limit_invalid_cases(self): - cfg.CONF.set_override("max_limit", self.max_limit, group="api") + cfg.CONF.set_override("max_limit", self.max_limit, group="api", + enforce_type=True) 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 4dcd093c8..62bec785d 100644 --- a/watcher/tests/api/v1/test_actions.py +++ b/watcher/tests/api/v1/test_actions.py @@ -410,7 +410,8 @@ class TestListAction(api_base.FunctionalTest): self.assertIn(next_marker, response['next']) def test_collection_links_default_limit(self): - cfg.CONF.set_override('max_limit', 3, 'api') + cfg.CONF.set_override('max_limit', 3, 'api', + enforce_type=True) 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 e52fadf1f..3d55491b2 100644 --- a/watcher/tests/api/v1/test_actions_plans.py +++ b/watcher/tests/api/v1/test_actions_plans.py @@ -267,7 +267,8 @@ 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') + cfg.CONF.set_override('max_limit', 3, 'api', + enforce_type=True) for id_ in range(5): obj_utils.create_action_plan_without_audit( 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 0b6b0acb4..5224132af 100644 --- a/watcher/tests/api/v1/test_audit_templates.py +++ b/watcher/tests/api/v1/test_audit_templates.py @@ -195,7 +195,8 @@ class TestListAuditTemplate(api_base.FunctionalTest): self.assertIn(next_marker, response['next']) def test_collection_links_default_limit(self): - cfg.CONF.set_override('max_limit', 3, 'api') + cfg.CONF.set_override('max_limit', 3, 'api', + enforce_type=True) 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 29fac9e90..e0f4a6307 100644 --- a/watcher/tests/api/v1/test_audits.py +++ b/watcher/tests/api/v1/test_audits.py @@ -204,7 +204,8 @@ 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') + cfg.CONF.set_override('max_limit', 3, 'api', + enforce_type=True) 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 ada455277..2b4e32a5c 100644 --- a/watcher/tests/api/v1/test_goals.py +++ b/watcher/tests/api/v1/test_goals.py @@ -26,7 +26,7 @@ class TestListGoal(api_base.FunctionalTest): "DUMMY_1": "dummy", "DUMMY_2": "dummy", "DUMMY_3": "dummy", "DUMMY_4": "dummy", }, - group='watcher_goals') + group='watcher_goals', enforce_type=True) def _assert_goal_fields(self, goal): goal_fields = ['name', 'strategy'] @@ -65,6 +65,6 @@ class TestListGoal(api_base.FunctionalTest): self.assertEqual(2, len(response['goals'])) def test_goals_collection_links_default_limit(self): - cfg.CONF.set_override('max_limit', 3, 'api') + cfg.CONF.set_override('max_limit', 3, 'api', enforce_type=True) response = self.get_json('/goals') self.assertEqual(3, len(response['goals'])) diff --git a/watcher/tests/base.py b/watcher/tests/base.py index 1bfb62d5a..b82f8dee7 100644 --- a/watcher/tests/base.py +++ b/watcher/tests/base.py @@ -34,7 +34,7 @@ from watcher.tests import conf_fixture CONF = cfg.CONF log.register_options(CONF) -CONF.set_override('use_stderr', False) +CONF.set_override('use_stderr', False, enforce_type=True) class BaseTestCase(testscenarios.WithScenarios, base.BaseTestCase): @@ -103,7 +103,7 @@ class TestCase(BaseTestCase): """Override config options for a test.""" group = kw.pop('group', None) for k, v in six.iteritems(kw): - CONF.set_override(k, v, group) + CONF.set_override(k, v, group, enforce_type=True) def path_get(self, project_file=None): """Get the absolute path to a file. Used for testing the API. diff --git a/watcher/tests/cmd/test_db_manage.py b/watcher/tests/cmd/test_db_manage.py index 08c458aa8..b0380ee46 100644 --- a/watcher/tests/cmd/test_db_manage.py +++ b/watcher/tests/cmd/test_db_manage.py @@ -39,18 +39,18 @@ class TestDBManageRunApp(TestCase): @patch("watcher.cmd.dbmanage.service.prepare_service") @patch("watcher.cmd.dbmanage.sys") def test_run_db_manage_app(self, m_sys, m_prepare_service): - # Patch command arguments + # Patch command function m_func = Mock() - cfg.CONF.register_opt(cfg.Opt("func"), group="command") - cfg.CONF.set_override("func", m_func, group="command") + cfg.CONF.register_opt(cfg.SubCommandOpt("command")) + cfg.CONF.command.func = m_func + # Only append if the command is not None m_sys.argv = list(filter(None, ["watcher-db-manage", self.command])) dbmanage.main() self.assertEqual(m_func.call_count, 1) m_prepare_service.assert_called_once_with( - ["watcher-db-manage", self.expected] - ) + ["watcher-db-manage", self.expected]) class TestDBManageRunCommand(TestCase): diff --git a/watcher/tests/common/test_ceilometer.py b/watcher/tests/common/test_ceilometer.py index ff695de31..78f2ebc71 100644 --- a/watcher/tests/common/test_ceilometer.py +++ b/watcher/tests/common/test_ceilometer.py @@ -49,7 +49,8 @@ class TestCeilometer(BaseTestCase): @mock.patch('ceilometerclient.v2.client.Client', autospec=True) def test_get_ceilometer_v2(self, mock_keystone, mock_ceilometer): cfg.CONF.set_override( - 'auth_uri', "http://127.0.0.1:9898/v2", group="keystone_authtoken" + 'auth_uri', "http://127.0.0.1:9898/v2", group="keystone_authtoken", + enforce_type=True ) c = CeilometerClient(api_version='2') from ceilometerclient.v2 import Client diff --git a/watcher/tests/common/test_keystone.py b/watcher/tests/common/test_keystone.py index 409d00a9b..bd284f2f2 100644 --- a/watcher/tests/common/test_keystone.py +++ b/watcher/tests/common/test_keystone.py @@ -35,7 +35,8 @@ class TestKeystone(BaseTestCase): def test_get_endpoint_v2(self, keystone): expected_endpoint = "http://ip:port/v2" cfg.CONF.set_override( - 'auth_uri', expected_endpoint, group="keystone_authtoken" + 'auth_uri', expected_endpoint, group="keystone_authtoken", + enforce_type=True ) ks = mock.Mock() ks.service_catalog.url_for.return_value = expected_endpoint diff --git a/watcher/tests/db/base.py b/watcher/tests/db/base.py index ad58896c5..24f751250 100644 --- a/watcher/tests/db/base.py +++ b/watcher/tests/db/base.py @@ -90,7 +90,8 @@ class Database(fixtures.Fixture): class DbTestCase(base.TestCase): def setUp(self): - cfg.CONF.set_override("enable_authentication", False) + cfg.CONF.set_override("enable_authentication", False, + enforce_type=True) super(DbTestCase, self).setUp() self.dbapi = dbapi.get_instance() diff --git a/watcher/tests/decision_engine/strategy/selector/test_strategy_selector.py b/watcher/tests/decision_engine/strategy/selector/test_strategy_selector.py index 2d6f5e280..144ba53f4 100644 --- a/watcher/tests/decision_engine/strategy/selector/test_strategy_selector.py +++ b/watcher/tests/decision_engine/strategy/selector/test_strategy_selector.py @@ -32,7 +32,8 @@ class TestStrategySelector(TestCase): @patch.object(DefaultStrategyLoader, 'load') def test_define_from_goal(self, mock_call): cfg.CONF.set_override('goals', - {"DUMMY": "fake"}, group='watcher_goals') + {"DUMMY": "fake"}, group='watcher_goals', + enforce_type=True) expected_goal = 'DUMMY' expected_strategy = CONF.watcher_goals.goals[expected_goal] self.strategy_selector.define_from_goal(expected_goal) @@ -40,7 +41,8 @@ class TestStrategySelector(TestCase): @patch.object(DefaultStrategyLoader, 'load') def test_define_from_goal_with_incorrect_mapping(self, mock_call): - cfg.CONF.set_override('goals', {}, group='watcher_goals') + cfg.CONF.set_override('goals', {}, group='watcher_goals', + enforce_type=True) self.assertRaises(WatcherException, self.strategy_selector.define_from_goal, "DUMMY") diff --git a/watcher/tests/policy_fixture.py b/watcher/tests/policy_fixture.py index 1bf4814ff..eb380f65a 100644 --- a/watcher/tests/policy_fixture.py +++ b/watcher/tests/policy_fixture.py @@ -34,6 +34,7 @@ class PolicyFixture(fixtures.Fixture): 'policy.json') with open(self.policy_file_name, 'w') as policy_file: policy_file.write(fake_policy.get_policy_data(self.compat)) - CONF.set_override('policy_file', self.policy_file_name) + CONF.set_override('policy_file', self.policy_file_name, + enforce_type=True) w_policy._ENFORCER = None self.addCleanup(w_policy.get_enforcer().clear)