diff options
author | LiuNanke <nanke.liu@easystack.cn> | 2016-01-12 20:57:31 +0800 |
---|---|---|
committer | LiuNanke <nanke.liu@easystack.cn> | 2016-01-12 20:57:31 +0800 |
commit | b563196a37dc6975d1ffeb15e93003894a3d14a3 (patch) | |
tree | 97d950bb219a4389727def26e554fcba9a97aec7 | |
parent | a70d99405ec7f37dc94c65d445cca6dd3902ee67 (diff) | |
download | ironic-python-agent-b563196a37dc6975d1ffeb15e93003894a3d14a3.tar.gz |
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.
Change-Id: Iba3e7fca01fc91e4396e698fc00cad35ba8f3543
Related-Bug: #1517839
-rw-r--r-- | ironic_python_agent/tests/unit/test_agent.py | 5 | ||||
-rw-r--r-- | ironic_python_agent/tests/unit/test_inspector.py | 14 |
2 files changed, 12 insertions, 7 deletions
diff --git a/ironic_python_agent/tests/unit/test_agent.py b/ironic_python_agent/tests/unit/test_agent.py index b41de50a..b818b59e 100644 --- a/ironic_python_agent/tests/unit/test_agent.py +++ b/ironic_python_agent/tests/unit/test_agent.py @@ -168,7 +168,7 @@ class TestBaseAgent(test_base.BaseTestCase): @mock.patch('wsgiref.simple_server.make_server', autospec=True) @mock.patch.object(hardware.HardwareManager, 'list_hardware_info') def test_run(self, mocked_list_hardware, wsgi_server_cls): - CONF.set_override('inspection_callback_url', '') + CONF.set_override('inspection_callback_url', '', enforce_type=True) wsgi_server = wsgi_server_cls.return_value wsgi_server.start.side_effect = KeyboardInterrupt() @@ -197,7 +197,8 @@ class TestBaseAgent(test_base.BaseTestCase): @mock.patch.object(hardware.HardwareManager, 'list_hardware_info') def test_run_with_inspection(self, mocked_list_hardware, wsgi_server_cls, mocked_inspector): - CONF.set_override('inspection_callback_url', 'http://foo/bar') + CONF.set_override('inspection_callback_url', 'http://foo/bar', + enforce_type=True) wsgi_server = wsgi_server_cls.return_value wsgi_server.start.side_effect = KeyboardInterrupt() diff --git a/ironic_python_agent/tests/unit/test_inspector.py b/ironic_python_agent/tests/unit/test_inspector.py index 2a41deb8..1b7eb3fb 100644 --- a/ironic_python_agent/tests/unit/test_inspector.py +++ b/ironic_python_agent/tests/unit/test_inspector.py @@ -67,8 +67,9 @@ class TestMisc(unittest.TestCase): class TestInspect(unittest.TestCase): def setUp(self): super(TestInspect, self).setUp() - CONF.set_override('inspection_callback_url', 'http://foo/bar') - CONF.set_override('inspection_collectors', '') + CONF.set_override('inspection_callback_url', 'http://foo/bar', + enforce_type=True) + CONF.set_override('inspection_collectors', '', enforce_type=True) self.mock_collect = AcceptingFailure() self.mock_ext = mock.Mock(spec=['plugin', 'name'], plugin=self.mock_collect) @@ -85,7 +86,8 @@ class TestInspect(unittest.TestCase): mock_setup_ipmi.assert_called_once_with(mock_call.return_value) def test_collectors_option(self, mock_ext_mgr, mock_call, mock_setup_ipmi): - CONF.set_override('inspection_collectors', 'foo,bar') + CONF.set_override('inspection_collectors', 'foo,bar', + enforce_type=True) mock_ext_mgr.return_value = [ mock.Mock(spec=['name', 'plugin'], plugin=AcceptingFailure()), mock.Mock(spec=['name', 'plugin'], plugin=AcceptingFailure()), @@ -109,7 +111,8 @@ class TestInspect(unittest.TestCase): self.assertFalse(mock_setup_ipmi.called) def test_extensions_failed(self, mock_ext_mgr, mock_call, mock_setup_ipmi): - CONF.set_override('inspection_collectors', 'foo,bar') + CONF.set_override('inspection_collectors', 'foo,bar', + enforce_type=True) mock_ext_mgr.side_effect = RuntimeError('boom') self.assertRaisesRegexp(RuntimeError, 'boom', inspector.inspect) @@ -133,7 +136,8 @@ class TestInspect(unittest.TestCase): class TestCallInspector(unittest.TestCase): def setUp(self): super(TestCallInspector, self).setUp() - CONF.set_override('inspection_callback_url', 'url') + CONF.set_override('inspection_callback_url', 'url', + enforce_type=True) def test_ok(self, mock_post): failures = utils.AccumulatedFailures() |