From c20073f425c9a58263c902b553d92e86ed621e05 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Wed, 29 Jan 2025 19:10:47 -0500 Subject: [PATCH] cephadm: add support for not mocking certain call methods Add support for not mocking certain call methods that are usually mocked out when with_cephadm_ctx is called. These mocks are fairly limited and do not coordinate well when other mocks (esp. funkypatch) is being used in a test. Allow the caller to set `mock_cephadm_call_fn=False` and skip setting these mocks. Signed-off-by: John Mulligan --- src/cephadm/tests/fixtures.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/cephadm/tests/fixtures.py b/src/cephadm/tests/fixtures.py index f770bcbf3fd..3b3a4937dda 100644 --- a/src/cephadm/tests/fixtures.py +++ b/src/cephadm/tests/fixtures.py @@ -154,6 +154,8 @@ def with_cephadm_ctx( cmd: List[str], list_networks: Optional[Dict[str, Dict[str, List[str]]]] = None, hostname: Optional[str] = None, + *, + mock_cephadm_call_fn: bool = True, ): """ :param cmd: cephadm command argv @@ -166,10 +168,6 @@ def with_cephadm_ctx( _cephadm = import_cephadm() with contextlib.ExitStack() as stack: stack.enter_context(mock.patch('cephadmlib.net_utils.attempt_bind')) - stack.enter_context(mock.patch('cephadmlib.call_wrappers.call', return_value=('', '', 0))) - stack.enter_context(mock.patch('cephadmlib.call_wrappers.call_timeout', return_value=0)) - stack.enter_context(mock.patch('cephadm.call', return_value=('', '', 0))) - stack.enter_context(mock.patch('cephadm.call_timeout', return_value=0)) stack.enter_context(mock.patch('cephadmlib.exe_utils.find_executable', return_value='foo')) stack.enter_context(mock.patch('cephadm.get_container_info', return_value=None)) stack.enter_context(mock.patch('cephadm.is_available', return_value=True)) @@ -177,6 +175,11 @@ def with_cephadm_ctx( stack.enter_context(mock.patch('cephadm.logger')) stack.enter_context(mock.patch('cephadm.FileLock')) stack.enter_context(mock.patch('socket.gethostname', return_value=hostname)) + if mock_cephadm_call_fn: + stack.enter_context(mock.patch('cephadmlib.call_wrappers.call', return_value=('', '', 0))) + stack.enter_context(mock.patch('cephadmlib.call_wrappers.call_timeout', return_value=0)) + stack.enter_context(mock.patch('cephadm.call', return_value=('', '', 0))) + stack.enter_context(mock.patch('cephadm.call_timeout', return_value=0)) if list_networks is not None: stack.enter_context(mock.patch('cephadm.list_networks', return_value=list_networks)) ctx: _cephadm.CephadmContext = _cephadm.cephadm_init_ctx(cmd) -- 2.39.5