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>
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()