[PATCH] Clean up after processKickstart in parse-kickstart_test.py.

Chris Lumens clumens at redhat.com
Fri May 15 15:52:45 UTC 2015


It's the responsibility of whoever calls processKickstart to clean up the
temp file afterwards, if it's no longer needed.  dracut/parse-kickstart does
the call, but the temp file is needed to be passed to anaconda.  Thus it
can't do the cleanup.  The test must therefore do so.

Also, each test should be its own function to ensure it gets cleaned up
after.  tearDown only gets called once per class, so it will only clean up
one file.
---
 tests/dracut_tests/parse-kickstart_test.py | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/tests/dracut_tests/parse-kickstart_test.py b/tests/dracut_tests/parse-kickstart_test.py
index b8fdac7..f076001 100644
--- a/tests/dracut_tests/parse-kickstart_test.py
+++ b/tests/dracut_tests/parse-kickstart_test.py
@@ -31,8 +31,16 @@ class BaseTestCase(unittest.TestCase):
     def tearDown(self):
         # remove the testing directory
         if self.tmpdir and os.path.isdir(self.tmpdir):
-            shutil.rmtree(self.tmpdir)
+            try:
+                with open(self.tmpdir + "/ks.info") as f:
+                    for line in f:
+                        if line.startswith("parsed_kickstart="):
+                            os.remove(line[18:-2])
+                            break
+            except OSError:
+                pass
 
+            shutil.rmtree(self.tmpdir)
 
 class ParseKickstartTestCase(BaseTestCase):
     @classmethod
@@ -66,6 +74,7 @@ class ParseKickstartTestCase(BaseTestCase):
 
         self.assertEqual(lines[0], "inst.repo=nfs:nolock,timeo=50:host.at.foo.com:/path/to/tree", lines)
 
+    def nfs_test_2(self):
         with tempfile.NamedTemporaryFile() as ks_file:
             ks_file.write("""nfs --server=host.at.foo.com --dir=/path/to/tree""")
             ks_file.flush()
@@ -79,7 +88,6 @@ class ParseKickstartTestCase(BaseTestCase):
             ks_file.flush()
             lines = self.execParseKickstart(ks_file.name)
 
-
         self.assertEqual(len(lines), 3, lines)
         self.assertEqual(lines[0], "inst.repo=https://host.at.foo.com/path/to/tree", lines)
         self.assertEqual(lines[1], "rd.noverifyssl", lines)
@@ -110,6 +118,7 @@ class ParseKickstartTestCase(BaseTestCase):
         dd_args_ks = open(self.tmpdir+"/dd_args_ks").readlines()
         self.assertEqual(dd_args_ks[0], "sda5", dd_args_ks)
 
+    def driverdisk_test_2(self):
         with tempfile.NamedTemporaryFile() as ks_file:
             ks_file.write("""driverdisk --source=http://host.att.foo.com/path/to/dd""")
             ks_file.flush()
@@ -125,6 +134,7 @@ class ParseKickstartTestCase(BaseTestCase):
 
             self.assertEqual(lines[0], "ip=dhcp", lines)
 
+    def network_test_2(self):
         with tempfile.NamedTemporaryFile() as ks_file:
             ks_file.write("""network --device=AA:BB:CC:DD:EE:FF --bootproto=dhcp --activate""")
             ks_file.flush()
@@ -251,6 +261,7 @@ network --device=lo --vlanid=171
 
             self.assertEqual(lines[0], "inst.cmdline", lines)
 
+    def displaymode_test_2(self):
         with tempfile.NamedTemporaryFile() as ks_file:
             ks_file.write("""graphical""")
             ks_file.flush()
@@ -258,6 +269,7 @@ network --device=lo --vlanid=171
 
             self.assertEqual(lines[0], "inst.graphical", lines)
 
+    def displaymode_test_3(self):
         with tempfile.NamedTemporaryFile() as ks_file:
             ks_file.write("""text""")
             ks_file.flush()
-- 
2.2.2



More information about the anaconda-patches mailing list