Fix tests to cleanup their /tmp dirs

This commit is contained in:
gholt 2011-01-24 17:12:38 -08:00
parent 0a01bd07e2
commit cc00bd40e0
5 changed files with 21 additions and 23 deletions

View File

@ -45,7 +45,7 @@ class TestContainerController(unittest.TestCase):
def tearDown(self): def tearDown(self):
""" Tear down for testing swift.object_server.ObjectController """ """ 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): def test_acl_container(self):
# Ensure no acl by default # Ensure no acl by default

View File

@ -51,7 +51,7 @@ class TestContainerUpdater(unittest.TestCase):
os.mkdir(self.sda1) os.mkdir(self.sda1)
def tearDown(self): def tearDown(self):
rmtree(self.testdir, ignore_errors=1) rmtree(os.path.dirname(self.testdir), ignore_errors=1)
def test_creation(self): def test_creation(self):
cu = container_updater.ContainerUpdater({ cu = container_updater.ContainerUpdater({

View File

@ -56,7 +56,7 @@ class TestAuditor(unittest.TestCase):
mount_check='false') mount_check='false')
def tearDown(self): 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): def test_object_audit_extra_data(self):
self.auditor = auditor.ObjectAuditor(self.conf) self.auditor = auditor.ObjectAuditor(self.conf)
@ -123,25 +123,21 @@ class TestAuditor(unittest.TestCase):
self.assertEquals(self.auditor.quarantines, pre_quarantines + 1) self.assertEquals(self.auditor.quarantines, pre_quarantines + 1)
def test_object_audit_no_meta(self): def test_object_audit_no_meta(self):
self.auditor = auditor.ObjectAuditor(self.conf)
cur_part = '0' cur_part = '0'
disk_file = DiskFile(self.devices, 'sda', cur_part, 'a', 'c', 'o') disk_file = DiskFile(self.devices, 'sda', cur_part, 'a', 'c', 'o')
data = '0' * 1024 timestamp = str(normalize_timestamp(time.time()))
etag = md5() 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 pre_quarantines = self.auditor.quarantines
with disk_file.mkstemp() as (fd, tmppath): self.auditor.object_audit(
os.write(fd, data) os.path.join(disk_file.datadir, timestamp + '.data'),
etag.update(data) 'sda', cur_part)
etag = etag.hexdigest() self.assertEquals(self.auditor.quarantines, pre_quarantines + 1)
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)
def test_object_audit_bad_args(self): def test_object_audit_bad_args(self):
self.auditor = auditor.ObjectAuditor(self.conf) self.auditor = auditor.ObjectAuditor(self.conf)

View File

@ -53,7 +53,7 @@ class TestObjectController(unittest.TestCase):
def tearDown(self): def tearDown(self):
""" Tear down for testing swift.object_server.ObjectController """ """ Tear down for testing swift.object_server.ObjectController """
rmtree(self.testdir) rmtree(os.path.dirname(self.testdir))
def test_POST_update_meta(self): def test_POST_update_meta(self):
""" Test swift.object_server.ObjectController.POST """ """ Test swift.object_server.ObjectController.POST """

View File

@ -142,7 +142,7 @@ def teardown():
for server in _test_coros: for server in _test_coros:
server.kill() server.kill()
proxy_server.CONTAINER_LISTING_LIMIT = _orig_container_listing_limit proxy_server.CONTAINER_LISTING_LIMIT = _orig_container_listing_limit
rmtree(_testdir) rmtree(os.path.dirname(_testdir))
def fake_http_connect(*code_iter, **kwargs): def fake_http_connect(*code_iter, **kwargs):
@ -3425,5 +3425,7 @@ class TestSegmentedIterable(unittest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
setup() setup()
unittest.main() try:
teardown() unittest.main()
finally:
teardown()