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 <jmulligan@redhat.com>
(cherry picked from commit
02b6ce8a44f234aa3fe30fe21d6f28d4e36d7af5)
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)):