diff options
| author | Julian Edwards <bigjools@gmail.com> | 2017-04-03 15:32:44 +1000 |
|---|---|---|
| committer | Julian Edwards <bigjools@gmail.com> | 2017-05-15 10:48:43 +1000 |
| commit | f57cbccf8b146152eacd99787a7ccc1097b80055 (patch) | |
| tree | 21493c4df3d1d83652ff30f54c7ee3c5826135f1 /ironic_python_agent/tests/unit/test_utils.py | |
| parent | 4be702242eb48e09eb77e46d997908b7c519127d (diff) | |
| download | ironic-python-agent-f57cbccf8b146152eacd99787a7ccc1097b80055.tar.gz | |
Prevent tests' unmocked access to utils.execute()
This change introduces a new base test class that mocks out
utils.execute and forces an exception if it gets called.
This has rooted out many tests that were doing this as a side effect of
calling other functions, doing things like modprobe and running iscsi
on the host's actual machine.
The tests are all now appropriately patched in places where this was
happening, and the new base class permanently prevents this from
accidentally happening again.
If you really want to call utils.execute() then you need to re-mock it
in your unit test.
Change-Id: Idf87d09a9c01a6bfe2767f8becabe65c02983518
Diffstat (limited to 'ironic_python_agent/tests/unit/test_utils.py')
| -rw-r--r-- | ironic_python_agent/tests/unit/test_utils.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/ironic_python_agent/tests/unit/test_utils.py b/ironic_python_agent/tests/unit/test_utils.py index dab7c14a..31c9988b 100644 --- a/ironic_python_agent/tests/unit/test_utils.py +++ b/ironic_python_agent/tests/unit/test_utils.py @@ -31,9 +31,14 @@ import six import testtools from ironic_python_agent import errors +from ironic_python_agent.tests.unit import base as ironic_agent_base from ironic_python_agent import utils +# Normally we'd use the IronicAgentTest base class which mocks out +# any use of utils.execute() to prevent accidental processes. However +# this test is checking the upcall to ironic_lib's execute(), so that +# is mocked out instead. class ExecuteTestCase(test_base.BaseTestCase): @mock.patch.object(ironic_utils, 'execute', autospec=True) @@ -43,7 +48,7 @@ class ExecuteTestCase(test_base.BaseTestCase): check_exit_code=False) -class GetAgentParamsTestCase(test_base.BaseTestCase): +class GetAgentParamsTestCase(ironic_agent_base.IronicAgentTest): @mock.patch('oslo_log.log.getLogger', autospec=True) @mock.patch('six.moves.builtins.open', autospec=True) |
