]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Use tmpdir and avoid leaving test files behind
authorJohn Griffith <john.griffith@solidfire.com>
Wed, 12 Sep 2012 22:52:02 +0000 (16:52 -0600)
committerJohn Griffith <john.griffith@solidfire.com>
Wed, 12 Sep 2012 23:35:44 +0000 (17:35 -0600)
 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

index 8fac430599b2e6cb2a1c3de17fdf6c0f9fd24c68..362ddf0b7e83465124a4940ef37ae3e3ee942d7a 100644 (file)
@@ -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):