Merge "Protect against hash cleanup errors on PUTs"

This commit is contained in:
Jenkins 2013-11-28 02:08:06 +00:00 committed by Gerrit Code Review
commit d412f6c05d
2 changed files with 22 additions and 1 deletions

View File

@ -662,7 +662,10 @@ class DiskFileWriter(object):
# After the rename completes, this object will be available for other
# requests to reference.
renamer(self._tmppath, target_path)
hash_cleanup_listdir(self._datadir)
try:
hash_cleanup_listdir(self._datadir)
except OSError:
logging.exception(_('Problem cleaning up %s'), self._datadir)
def put(self, metadata):
"""

View File

@ -1577,6 +1577,24 @@ class TestDiskFile(unittest.TestCase):
with df.open():
self.assertEqual(df.timestamp, '1383181759.12345')
def test_error_in_hashdir_cleanup_listdir(self):
def mock_hcl(*args, **kwargs):
raise OSError()
df = self._get_open_disk_file()
ts = time()
with mock.patch("swift.obj.diskfile.hash_cleanup_listdir",
mock_hcl):
try:
df.delete(ts)
except OSError:
self.fail("OSError raised when it should have been swallowed")
exp_name = '%s.ts' % str(normalize_timestamp(ts))
dl = os.listdir(df._datadir)
self.assertEquals(len(dl), 2)
self.assertTrue(exp_name in set(dl))
if __name__ == '__main__':
unittest.main()