diff --git a/swift/common/utils.py b/swift/common/utils.py index c2499821f4..51b656c5c3 100644 --- a/swift/common/utils.py +++ b/swift/common/utils.py @@ -975,14 +975,13 @@ class _LibcWrapper(object): # spurious AttributeError. func_handle = load_libc_function( func_name, fail_if_missing=True) + self._func_handle = func_handle except AttributeError: # We pass fail_if_missing=True to load_libc_function and # then ignore the error. It's weird, but otherwise we have # to check if self._func_handle is noop_libc_function, and # that's even weirder. pass - else: - self._func_handle = func_handle self._loaded = True @property diff --git a/test/unit/common/test_utils.py b/test/unit/common/test_utils.py index 8f26565e12..448ae66a89 100644 --- a/test/unit/common/test_utils.py +++ b/test/unit/common/test_utils.py @@ -7980,6 +7980,15 @@ class TestFallocate(unittest.TestCase): # work the way you'd expect with ctypes :-/ self.assertEqual(sys_fallocate_mock.mock_calls[0][1][2].value, 0) self.assertEqual(sys_fallocate_mock.mock_calls[0][1][3].value, 0) + sys_fallocate_mock.reset_mock() + + # negative size will be adjusted as 0 + utils.fallocate(0, -1, 0) + self.assertEqual( + [mock.call(0, utils.FALLOC_FL_KEEP_SIZE, mock.ANY, mock.ANY)], + sys_fallocate_mock.mock_calls) + self.assertEqual(sys_fallocate_mock.mock_calls[0][1][2].value, 0) + self.assertEqual(sys_fallocate_mock.mock_calls[0][1][3].value, 0) @patch.object(os, 'fstatvfs') @@ -8171,6 +8180,8 @@ class TestPunchHole(unittest.TestCase): with self.assertRaises(ValueError): utils.punch_hole(0, 1, -1) + with self.assertRaises(ValueError): + utils.punch_hole(0, 1 << 64, 1) with self.assertRaises(ValueError): utils.punch_hole(0, -1, 1) with self.assertRaises(ValueError):