test: fix module state pollution

The disable_fallocate function provided in common.utils doesn't really
have a way to undo it - it's tested independently in test_utils.
It shouldn't be used on test_diskfile or else test_utils fallocate tests
will fail afterwards.
Change-Id: I6ffa97b39111ba25f85ba7cfde21440d975dc760
Signed-off-by: Clay Gerrard <clay.gerrard@gmail.com>
This commit is contained in:
Clay Gerrard
2025年09月15日 14:07:36 -05:00
parent c26c7b8edd
commit 815393dff4

View File

@@ -5029,19 +5029,18 @@ class DiskFileMixin(BaseDiskFileTestMixin):
self.assertEqual(raised.exception.errno, errno.EACCES)
def test_create_close_oserror(self):
# This is a horrible hack so you can run this test in isolation.
# Some of the ctypes machinery calls os.close(), and that runs afoul
# of our mock.
with mock.patch.object(utils, '_sys_fallocate', None):
utils.disable_fallocate()
err = OSError(errno.EACCES, os.strerror(errno.EACCES))
# Disable fallocate for this test. Otherwise, the ctypes machinery may
# also call os.close (for example, when this test is run in isolation),
# but we're only interested in what diskfile is doing.
with mock.patch.object(utils, '_fallocate_enabled', False):
df = self.df_mgr.get_diskfile(self.existing_device, '0', 'abc',
'123', 'xyz', policy=POLICIES.legacy)
with mock.patch("swift.obj.diskfile.os.close",
mock.MagicMock(side_effect=OSError(
errno.EACCES, os.strerror(errno.EACCES)))):
with df.create(size=200):
pass
with mock.patch("swift.obj.diskfile.os.close") as mock_close:
mock_close.side_effect= err
with df.create(size=200) as dfw:
fd = dfw._fd
self.assertEqual([mock.call(fd)], mock_close.call_args_list)
def test_write_metadata(self):
df, df_data = self._create_test_file(b'1234567890')
Reference in New Issue
openstack/swift
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.

The note is not visible to the blocked user.