]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: fix unit tests executing FileLock type
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 20 Sep 2023 19:38:50 +0000 (15:38 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Thu, 21 Sep 2023 13:46:41 +0000 (09:46 -0400)
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 <jmulligan@redhat.com>
src/cephadm/tests/fixtures.py

index c82a138cbaed310948198681f7666f085852dd67..ebed7b3d21ca76740b897eb15ee7a21a8413741c 100644 (file)
@@ -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()