From: John Mulligan Date: Wed, 20 Sep 2023 19:38:50 +0000 (-0400) Subject: cephadm: fix unit tests executing FileLock type X-Git-Tag: v19.0.0~421^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1a5a61d78fc3dae4016012bfa14e4b91ec1ae4f5;p=ceph-ci.git 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 --- diff --git a/src/cephadm/tests/fixtures.py b/src/cephadm/tests/fixtures.py index c82a138cbae..ebed7b3d21c 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()