Francesco Romani has uploaded a new change for review.

Change subject: tests: janitorial: cleanup temporary directories.
......................................................................

tests: janitorial: cleanup temporary directories.

A few tests don't cleanup the temporary directories they created to run.
A the end of the day, you can easily end up with tons of
entries in /tmp.

This patch ensures each testcase does its own cleanup.

Change-Id: If6581771479de9f72360ea537de32abcdad496b3
Signed-off-by: Francesco Romani <[email protected]>
---
M tests/hooksTests.py
M tests/netconfTests.py
2 files changed, 15 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/77/22377/1

diff --git a/tests/hooksTests.py b/tests/hooksTests.py
index 1018a4e..7f27c77 100644
--- a/tests/hooksTests.py
+++ b/tests/hooksTests.py
@@ -23,6 +23,7 @@
 import tempfile
 import os
 import os.path
+import shutil
 from testrunner import VdsmTestCase as TestCaseBase
 
 import hooks
@@ -108,6 +109,8 @@
         os.unlink(sName)
         expectedRes = dict([(os.path.basename(sName), {'md5': md5})])
         self.assertEqual(expectedRes, info)
+        NEscript.close()
+        os.rmdir(dir)
 
     def _deviceCustomPropertiesTestFile(self):
         dirName = tempfile.mkdtemp()
@@ -132,6 +135,7 @@
         result = hooks._runHooksDir("oVirt", dirName,
                                     params={'customProperty': ' rocks!'})
         self.assertEqual(result, "oVirt rocks!")
+        shutil.rmtree(dirName)
 
     def test_deviceVmConfProperties(self):
         dirName = self._deviceCustomPropertiesTestFile()
@@ -144,3 +148,4 @@
                                     params={'customProperty': ' rocks!'},
                                     vmconf=vmconf)
         self.assertEqual(result, "oVirt rocks more!")
+        shutil.rmtree(dirName)
diff --git a/tests/netconfTests.py b/tests/netconfTests.py
index 919a5eb..a887703 100644
--- a/tests/netconfTests.py
+++ b/tests/netconfTests.py
@@ -42,19 +42,6 @@
     INITIAL_CONTENT = '123-testing'
     SOME_GARBAGE = '456'
 
-    def __init__(self, *args, **kwargs):
-        TestCaseBase.__init__(self, *args, **kwargs)
-        self._tempdir = tempfile.mkdtemp()
-        self._files = tuple((os.path.join(self._tempdir, bn), init, makeDirty)
-                            for bn, init, makeDirty in
-                            (('ifcfg-eth0', self.INITIAL_CONTENT, True),
-                             ('ifcfg-eth1', None, True),
-                             ('ifcfg-eth2', None, False),
-                             ('ifcfg-eth3', self.INITIAL_CONTENT, False),))
-
-    def __del__(self):
-        shutil.rmtree(self._tempdir)
-
     def _createFiles(self):
         for fn, content, _ in self._files:
             if content is not None:
@@ -85,8 +72,18 @@
         self.assertEqual(aXmlNrml, bXmlNrml, msg)
 
     def setUp(self):
+        self._tempdir = tempfile.mkdtemp()
+        self._files = tuple((os.path.join(self._tempdir, bn), init, makeDirty)
+                            for bn, init, makeDirty in
+                            (('ifcfg-eth0', self.INITIAL_CONTENT, True),
+                             ('ifcfg-eth1', None, True),
+                             ('ifcfg-eth2', None, False),
+                             ('ifcfg-eth3', self.INITIAL_CONTENT, False),))
         self._cw = ifcfg.ConfigWriter()
 
+    def tearDown(self):
+        shutil.rmtree(self._tempdir)
+
     @MonkeyPatch(subprocess, 'Popen', lambda x: None)
     def testAtomicRestore(self):
         self._createFiles()


-- 
To view, visit http://gerrit.ovirt.org/22377
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If6581771479de9f72360ea537de32abcdad496b3
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to