From 1a5a61d78fc3dae4016012bfa14e4b91ec1ae4f5 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Wed, 20 Sep 2023 15:38:50 -0400 Subject: [PATCH] cephadm: fix unit tests executing FileLock type The FileLock type doesn't play much of a role when running tests so to prevent issues, always mock it out when using with_cephadm_ctx. In particular, a future patch revealed a problem with the FileLock code that I can not understand how it was not hit before, or why this simple refactoring - not directly related to file locking - triggered it. But in short, the FakeFilesystem mocking utility only covers some syscalls. In fact, the fake filesystem was returning an fd that was then passed to real calls (fcntl and os.close). The latter then triggered issues when pytest was trying to clean up after it applied it's magic to stdio objects in sys. The fix is easy - understanding why it happens and how was hard. I still don't understand why it popped up when it did only that this is necessary to implement the following patches. Signed-off-by: John Mulligan --- src/cephadm/tests/fixtures.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cephadm/tests/fixtures.py b/src/cephadm/tests/fixtures.py index c82a138cbaed3..ebed7b3d21ca7 100644 --- a/src/cephadm/tests/fixtures.py +++ b/src/cephadm/tests/fixtures.py @@ -155,6 +155,7 @@ def with_cephadm_ctx( mock.patch('cephadm.is_available', return_value=True), \ mock.patch('cephadm.json_loads_retry', return_value={'epoch' : 1}), \ mock.patch('cephadm.logger'), \ + mock.patch('cephadm.FileLock'), \ mock.patch('socket.gethostname', return_value=hostname): ctx: _cephadm.CephadmContext = _cephadm.cephadm_init_ctx(cmd) ctx.container_engine = mock_podman() -- 2.39.5