From cc00bd40e0726b89ff460053e7bfb54e5055c038 Mon Sep 17 00:00:00 2001 From: gholt Date: Mon, 24 Jan 2011 17:12:38 -0800 Subject: [PATCH] Fix tests to cleanup their /tmp dirs --- test/unit/container/test_server.py | 2 +- test/unit/container/test_updater.py | 2 +- test/unit/obj/test_auditor.py | 30 +++++++++++++---------------- test/unit/obj/test_server.py | 2 +- test/unit/proxy/test_server.py | 8 +++++--- 5 files changed, 21 insertions(+), 23 deletions(-) diff --git a/test/unit/container/test_server.py b/test/unit/container/test_server.py index 62d62a1f87..194ffff83d 100644 --- a/test/unit/container/test_server.py +++ b/test/unit/container/test_server.py @@ -45,7 +45,7 @@ class TestContainerController(unittest.TestCase): def tearDown(self): """ Tear down for testing swift.object_server.ObjectController """ - rmtree(self.testdir, ignore_errors=1) + rmtree(os.path.dirname(self.testdir), ignore_errors=1) def test_acl_container(self): # Ensure no acl by default diff --git a/test/unit/container/test_updater.py b/test/unit/container/test_updater.py index b7dbe6dd6d..a7a2094824 100644 --- a/test/unit/container/test_updater.py +++ b/test/unit/container/test_updater.py @@ -51,7 +51,7 @@ class TestContainerUpdater(unittest.TestCase): os.mkdir(self.sda1) def tearDown(self): - rmtree(self.testdir, ignore_errors=1) + rmtree(os.path.dirname(self.testdir), ignore_errors=1) def test_creation(self): cu = container_updater.ContainerUpdater({ diff --git a/test/unit/obj/test_auditor.py b/test/unit/obj/test_auditor.py index 8c1d08e522..66540a3693 100644 --- a/test/unit/obj/test_auditor.py +++ b/test/unit/obj/test_auditor.py @@ -56,7 +56,7 @@ class TestAuditor(unittest.TestCase): mount_check='false') def tearDown(self): - rmtree(self.testdir, ignore_errors=1) + rmtree(os.path.dirname(self.testdir), ignore_errors=1) def test_object_audit_extra_data(self): self.auditor = auditor.ObjectAuditor(self.conf) @@ -123,25 +123,21 @@ class TestAuditor(unittest.TestCase): self.assertEquals(self.auditor.quarantines, pre_quarantines + 1) def test_object_audit_no_meta(self): - self.auditor = auditor.ObjectAuditor(self.conf) cur_part = '0' disk_file = DiskFile(self.devices, 'sda', cur_part, 'a', 'c', 'o') - data = '0' * 1024 - etag = md5() + timestamp = str(normalize_timestamp(time.time())) + path = os.path.join(disk_file.datadir, timestamp + '.data') + mkdirs(disk_file.datadir) + fp = open(path, 'w') + fp.write('0' * 1024) + fp.close() + invalidate_hash(os.path.dirname(disk_file.datadir)) + self.auditor = auditor.ObjectAuditor(self.conf) pre_quarantines = self.auditor.quarantines - with disk_file.mkstemp() as (fd, tmppath): - os.write(fd, data) - etag.update(data) - etag = etag.hexdigest() - timestamp = str(normalize_timestamp(time.time())) - os.fsync(fd) - invalidate_hash(os.path.dirname(disk_file.datadir)) - renamer(tmppath, os.path.join(disk_file.datadir, - timestamp + '.data')) - self.auditor.object_audit( - os.path.join(disk_file.datadir, timestamp + '.data'), - 'sda', cur_part) - self.assertEquals(self.auditor.quarantines, pre_quarantines + 1) + self.auditor.object_audit( + os.path.join(disk_file.datadir, timestamp + '.data'), + 'sda', cur_part) + self.assertEquals(self.auditor.quarantines, pre_quarantines + 1) def test_object_audit_bad_args(self): self.auditor = auditor.ObjectAuditor(self.conf) diff --git a/test/unit/obj/test_server.py b/test/unit/obj/test_server.py index 735b944d2d..22d2fe20a4 100644 --- a/test/unit/obj/test_server.py +++ b/test/unit/obj/test_server.py @@ -53,7 +53,7 @@ class TestObjectController(unittest.TestCase): def tearDown(self): """ Tear down for testing swift.object_server.ObjectController """ - rmtree(self.testdir) + rmtree(os.path.dirname(self.testdir)) def test_POST_update_meta(self): """ Test swift.object_server.ObjectController.POST """ diff --git a/test/unit/proxy/test_server.py b/test/unit/proxy/test_server.py index b327b99a46..1a3a442bea 100644 --- a/test/unit/proxy/test_server.py +++ b/test/unit/proxy/test_server.py @@ -142,7 +142,7 @@ def teardown(): for server in _test_coros: server.kill() proxy_server.CONTAINER_LISTING_LIMIT = _orig_container_listing_limit - rmtree(_testdir) + rmtree(os.path.dirname(_testdir)) def fake_http_connect(*code_iter, **kwargs): @@ -3425,5 +3425,7 @@ class TestSegmentedIterable(unittest.TestCase): if __name__ == '__main__': setup() - unittest.main() - teardown() + try: + unittest.main() + finally: + teardown()