From: John Mulligan Date: Tue, 6 Jun 2023 00:08:49 +0000 (-0400) Subject: cephadm: create functional mock for fchown X-Git-Tag: v19.0.0~1023^2~6 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=02b6ce8a44f234aa3fe30fe21d6f28d4e36d7af5;p=ceph.git cephadm: create functional mock for fchown The pyfakefs library apparently doesn't have its own mock for os.fchown. This means that code using fchown currently calls into a mock with no affect on the fake fs. For some reason I don't fully understand, existing test cases work because they don't always follow the pattern of open-write-rename. Switching to `write_new`, which always does a rename, breaks some of the assertions performed in the tests on the fake fs. Add a mock fchown that updates the state of the fake fs so that converting call sites to use `write_new` will continue to work. Signed-off-by: John Mulligan --- diff --git a/src/cephadm/tests/fixtures.py b/src/cephadm/tests/fixtures.py index b3926f9a9de84..879053f4860bd 100644 --- a/src/cephadm/tests/fixtures.py +++ b/src/cephadm/tests/fixtures.py @@ -71,8 +71,17 @@ def cephadm_fs( uid = os.getuid() gid = os.getgid() + def fchown(fd, _uid, _gid): + """pyfakefs doesn't provide a working fchown or fchmod. + In order to get permissions working generally across renames + we need to provide our own implemenation. + """ + file_obj = fs.get_open_file(fd).get_object() + file_obj.st_uid = _uid + file_obj.st_gid = _gid + _cephadm = import_cephadm() - with mock.patch('os.fchown'), \ + with mock.patch('os.fchown', side_effect=fchown), \ mock.patch('os.fchmod'), \ mock.patch('platform.processor', return_value='x86_64'), \ mock.patch('cephadm.extract_uid_gid', return_value=(uid, gid)):