From d2742e15ae14c9ab9f7567a3abf4308b78343c99 Mon Sep 17 00:00:00 2001 From: Xing Yang Date: Wed, 20 Feb 2013 13:22:59 -0500 Subject: [PATCH] Uses tempdir module to create/delete xml file 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 | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cinder/tests/test_emc.py b/cinder/tests/test_emc.py index 62ff3ddd4..639528e48 100644 --- a/cinder/tests/test_emc.py +++ b/cinder/tests/test_emc.py @@ -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() -- 2.45.2