Stop requiring mocking of utils.execute if ironic-lib execute is mocked

Based on unit tests, this was done intentionally, but I don't see
reasons for that. It makes refactoring much harder, because sometimes
you need to mock both execute functions and test them separately.

In the end, utils.execute should be removed.

Change-Id: I5a9c694ebe626c54f219d4870eab0a592777518d
This commit is contained in:
Dmitry Tantsur 2021-10-27 14:24:00 +02:00
parent c824dda7a5
commit b360214cf2
2 changed files with 1 additions and 17 deletions

View File

@ -25,7 +25,6 @@ from oslotest import base as test_base
from ironic_python_agent.extensions import base as ext_base
from ironic_python_agent import hardware
from ironic_python_agent import utils
CONF = cfg.CONF
@ -58,7 +57,7 @@ class IronicAgentTest(test_base.BaseTestCase):
self.patch(subprocess, 'call', do_not_call)
self.patch(subprocess, 'check_call', do_not_call)
self.patch(subprocess, 'check_output', do_not_call)
self.patch(utils, 'execute', do_not_call)
# ironic_python_agent.utils.execute is an alias of ironic_lib one
ext_base._EXT_MANAGER = None
hardware._CACHED_HW_INFO = None

View File

@ -50,21 +50,6 @@ class BlockExecuteTestCase(ironic_agent_base.IronicAgentTest):
utils.execute("echo")
self.assertEqual(2, mock_exec.call_count)
@mock.patch.object(ironic_lib.utils, "execute", autospec=True)
def test_exception_raised_for_execute_parent_mocked(self, mock_exec):
# Make sure that even if we mock the parent execute function, that we
# still get an exception for a child. So in this case utils.execute()
# calls ironic_lib.utils.execute(). Make sure an exception is raised
# even though we mocked ironic_lib.utils.execute()
exc = self.assertRaises(Exception, utils.execute, "ls") # noqa
# Have to use 'noqa' as we are raising plain Exception and we will get
# H202 error in 'pep8' check.
self.assertEqual(
"Don't call ironic_lib.utils.execute() / "
"processutils.execute() or similar functions in tests!",
"%s" % exc)
class DontBlockExecuteTestCase(ironic_agent_base.IronicAgentTest):
"""Ensure we can turn off blocking access to 'execute' type functions"""