From daa057d5979d7a9557cde29e50a489d393b56c77 Mon Sep 17 00:00:00 2001 From: David Goetz Date: Tue, 30 Aug 2011 14:29:19 -0700 Subject: [PATCH 1/2] make sure files always get closed --- swift/obj/auditor.py | 51 ++++++++++++++++++----------------- test/unit/obj/test_auditor.py | 18 +++++++++++++ 2 files changed, 45 insertions(+), 24 deletions(-) diff --git a/swift/obj/auditor.py b/swift/obj/auditor.py index a512f3d670..50b8c2a1ed 100644 --- a/swift/obj/auditor.py +++ b/swift/obj/auditor.py @@ -134,31 +134,34 @@ class AuditorWorker(object): df = object_server.DiskFile(self.devices, device, partition, account, container, obj, self.logger, keep_data_fp=True) - if df.data_file is None: - # file is deleted, we found the tombstone - return try: - obj_size = df.get_data_file_size() - except DiskFileError, e: - raise AuditException(str(e)) - except DiskFileNotExist: - return - if self.zero_byte_only_at_fps and obj_size: - self.passes += 1 - return - for chunk in df: - self.bytes_running_time = ratelimit_sleep( - self.bytes_running_time, self.max_bytes_per_second, - incr_by=len(chunk)) - self.bytes_processed += len(chunk) - self.total_bytes_processed += len(chunk) - df.close() - if df.quarantined_dir: - self.quarantines += 1 - self.logger.error( - _("ERROR Object %(path)s failed audit and will be " - "quarantined: ETag and file's md5 do not match"), - {'path': path}) + if df.data_file is None: + # file is deleted, we found the tombstone + return + try: + obj_size = df.get_data_file_size() + except DiskFileError, e: + raise AuditException(str(e)) + except DiskFileNotExist: + return + if self.zero_byte_only_at_fps and obj_size: + self.passes += 1 + return + for chunk in df: + self.bytes_running_time = ratelimit_sleep( + self.bytes_running_time, self.max_bytes_per_second, + incr_by=len(chunk)) + self.bytes_processed += len(chunk) + self.total_bytes_processed += len(chunk) + df.close() + if df.quarantined_dir: + self.quarantines += 1 + self.logger.error( + _("ERROR Object %(path)s failed audit and will be " + "quarantined: ETag and file's md5 do not match"), + {'path': path}) + finally: + df.close(verify_file=False) except AuditException, err: self.quarantines += 1 self.logger.error(_('ERROR Object %(obj)s failed audit and will ' diff --git a/test/unit/obj/test_auditor.py b/test/unit/obj/test_auditor.py index 0aa05bcce4..9b629ff764 100644 --- a/test/unit/obj/test_auditor.py +++ b/test/unit/obj/test_auditor.py @@ -315,6 +315,24 @@ class TestAuditor(unittest.TestCase): my_auditor._sleep() self.assertEquals(round(time.time() - start, 2), 0.01) + def test_object_run_fast_track_zero_check_closed(self): + rat = [False] + + class FakeFile(DiskFile): + + def close(self, verify_file=True): + rat[0] = True + DiskFile.close(self, verify_file=verify_file) + self.setup_bad_zero_byte() + was_df = object_server.DiskFile + object_server.DiskFile = FakeFile + self.auditor.run_once(zero_byte_fps=50) + quarantine_path = os.path.join(self.devices, + 'sda', 'quarantined', 'objects') + self.assertTrue(os.path.isdir(quarantine_path)) + self.assertTrue(rat[0]) + object_server.DiskFile = was_df + def test_run_forever(self): class StopForever(Exception): From fc4f6feb8f769aac8f62afb6fdedac86262c2c26 Mon Sep 17 00:00:00 2001 From: David Goetz Date: Wed, 31 Aug 2011 07:28:36 -0700 Subject: [PATCH 2/2] fix for unit test --- test/unit/obj/test_auditor.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/test/unit/obj/test_auditor.py b/test/unit/obj/test_auditor.py index 9b629ff764..cc08c2cd60 100644 --- a/test/unit/obj/test_auditor.py +++ b/test/unit/obj/test_auditor.py @@ -325,13 +325,15 @@ class TestAuditor(unittest.TestCase): DiskFile.close(self, verify_file=verify_file) self.setup_bad_zero_byte() was_df = object_server.DiskFile - object_server.DiskFile = FakeFile - self.auditor.run_once(zero_byte_fps=50) - quarantine_path = os.path.join(self.devices, - 'sda', 'quarantined', 'objects') - self.assertTrue(os.path.isdir(quarantine_path)) - self.assertTrue(rat[0]) - object_server.DiskFile = was_df + try: + object_server.DiskFile = FakeFile + self.auditor.run_once(zero_byte_fps=50) + quarantine_path = os.path.join(self.devices, + 'sda', 'quarantined', 'objects') + self.assertTrue(os.path.isdir(quarantine_path)) + self.assertTrue(rat[0]) + finally: + object_server.DiskFile = was_df def test_run_forever(self):