]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Uses tempdir module to create/delete xml file
authorXing Yang <xing.yang@emc.com>
Wed, 20 Feb 2013 18:22:59 +0000 (13:22 -0500)
committerXing Yang <xing.yang@emc.com>
Wed, 20 Feb 2013 18:28:42 +0000 (13:28 -0500)
The emc test in cinder is leaving behind its test generated
cinder_emc_config.xml file in /cinder/tests directory.  This
fix uses tempdir module to create the xml file and delete it
when tearDown is called.

Change-Id: I7fd1dda83a097d1122c58cd3ed723ed7f5de30d8
Fixes: bug #1130495
cinder/tests/test_emc.py

index 62ff3ddd4ea114a6e82415e14753c733189b582c..639528e484b3e412675fbadc5b8097fb4d195cae 100644 (file)
@@ -18,6 +18,8 @@
 
 import mox
 import os
+import shutil
+import tempfile
 from xml.dom.minidom import Document
 
 from cinder import exception
@@ -577,6 +579,7 @@ class FakeEcomConnection():
 class EMCSMISISCSIDriverTestCase(test.TestCase):
 
     def setUp(self):
+        self.tempdir = tempfile.mkdtemp()
         super(EMCSMISISCSIDriverTestCase, self).setUp()
         self.config_file_path = None
         self.create_fake_config_file()
@@ -622,8 +625,7 @@ class EMCSMISISCSIDriverTestCase(test.TestCase):
         emc.appendChild(ecompassword)
         ecompassword.appendChild(ecompasswordtext)
 
-        dir_path = os.getcwd()
-        self.config_file_path = dir_path + '/' + config_file_name
+        self.config_file_path = self.tempdir + '/' + config_file_name
         f = open(self.config_file_path, 'w')
         doc.writexml(f)
         f.close()
@@ -743,8 +745,12 @@ class EMCSMISISCSIDriverTestCase(test.TestCase):
                           self.driver.delete_volume,
                           failed_delete_vol)
 
-    def TearDown(self):
+    def _cleanup(self):
         bExists = os.path.exists(self.config_file_path)
         if bExists:
             os.remove(self.config_file_path)
+        shutil.rmtree(self.tempdir)
+
+    def tearDown(self):
+        self._cleanup()
         super(EMCSMISISCSIDriverTestCase, self).tearDown()