[pykickstart] Allow %include in %pre and %post (#827269)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Brian C. Lane" <bcl@xxxxxxxxxx>

The %pre and %post sections could contain %include. This restores that
functionality and adds a couple of tests.
---
 pykickstart/parser.py   |    3 +-
 tests/parser/include.py |   52 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 1 deletions(-)

diff --git a/pykickstart/parser.py b/pykickstart/parser.py
index 531e639..f59b694 100644
--- a/pykickstart/parser.py
+++ b/pykickstart/parser.py
@@ -535,7 +535,8 @@ class KickstartParser:
                 # valid for that script.  So, don't do the split below unless
                 # we're sure.
                 possibleSectionStart = line.split()[0]
-                if not self._validState(possibleSectionStart) and possibleSectionStart != "%end":
+                if not self._validState(possibleSectionStart) \
+                   and possibleSectionStart not in ("%end", "%include"):
                     obj.handleLine(line)
                     continue
 
diff --git a/tests/parser/include.py b/tests/parser/include.py
index a454b99..efc14a8 100644
--- a/tests/parser/include.py
+++ b/tests/parser/include.py
@@ -85,5 +85,57 @@ ls /tmp
         # Also verify the body, which is the most important part.
         self.assertEqual(script.script.rstrip(), "ls /tmp")
 
+class Include_Post_TestCase(Base_Include):
+    ks = """
+%%post
+%%include %s
+%%end
+"""
+
+    includeKS = """
+ls /tmp
+"""
+
+    def runTest(self):
+        self.parser.readKickstartFromString(self.ks % self._path)
+        self.assertEqual(len(self.handler.scripts), 1)
+
+        # Verify the script defaults.
+        script = self.handler.scripts[0]
+        self.assertEqual(script.interp, "/bin/sh")
+        self.assertTrue(script.inChroot)
+        self.assertEqual(script.lineno, 2)
+        self.assertFalse(script.errorOnFail)
+        self.assertEqual(script.type, constants.KS_SCRIPT_POST)
+
+        # Also verify the body, which is the most important part.
+        self.assertEqual(script.script.rstrip(), "ls /tmp")
+
+class Include_Pre_TestCase(Base_Include):
+    ks = """
+%%pre
+%%include %s
+%%end
+"""
+
+    includeKS = """
+ls /tmp
+"""
+
+    def runTest(self):
+        self.parser.readKickstartFromString(self.ks % self._path)
+        self.assertEqual(len(self.handler.scripts), 1)
+
+        # Verify the script defaults.
+        script = self.handler.scripts[0]
+        self.assertEqual(script.interp, "/bin/sh")
+        self.assertFalse(script.inChroot)
+        self.assertEqual(script.lineno, 2)
+        self.assertFalse(script.errorOnFail)
+        self.assertEqual(script.type, constants.KS_SCRIPT_PRE)
+
+        # Also verify the body, which is the most important part.
+        self.assertEqual(script.script.rstrip(), "ls /tmp")
+
 if __name__ == "__main__":
     unittest.main()
-- 
1.7.7.6

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux