From 96f72f2cfd0afa6e60399dadd30bb83b0ab8ee0e Mon Sep 17 00:00:00 2001 From: John Griffith Date: Wed, 12 Sep 2012 16:52:02 -0600 Subject: [PATCH] Use tmpdir and avoid leaving test files behind We were just creating a file for testing iscsi persist files and weren't cleaning up after the test. Change this to use a tmpdir and make sure we leave no tracks. Fixes bug #1050086 Change-Id: I9b9a2400a172d52987d76f3132793cb042fd201c --- cinder/tests/test_iscsi.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cinder/tests/test_iscsi.py b/cinder/tests/test_iscsi.py index 8fac43059..362ddf0b7 100644 --- a/cinder/tests/test_iscsi.py +++ b/cinder/tests/test_iscsi.py @@ -15,7 +15,9 @@ # under the License. import os.path +import shutil import string +import tempfile from cinder import test from cinder.volume import iscsi @@ -89,12 +91,20 @@ class TgtAdmTestCase(test.TestCase, TargetAdminTestCase): def setUp(self): super(TgtAdmTestCase, self).setUp() TargetAdminTestCase.setUp(self) + self.persist_tempdir = tempfile.mkdtemp() self.flags(iscsi_helper='tgtadm') - self.flags(volumes_dir="./") + self.flags(volumes_dir=self.persist_tempdir) self.script_template = "\n".join([ - 'tgt-admin --conf ./blaa --update iqn.2011-09.org.foo.bar:blaa', + 'tgt-admin --conf %s/blaa --update iqn.2011-09.org.foo.bar:blaa' + % self.persist_tempdir, 'tgt-admin --delete iqn.2010-10.org.openstack:volume-blaa']) + def tearDown(self): + try: + shutil.rmtree(self.persist_tempdir) + except OSError: + pass + class IetAdmTestCase(test.TestCase, TargetAdminTestCase): -- 2.45.2