[rhel6-branch][pykickstart][PATCH] Raise an error if part and autopart are used together (#886010)

Martin Kolman mkolman at redhat.com
Tue Aug 6 14:32:29 UTC 2013


As using the part and autopart commands together in a single kickstart
file can lead to a very bad behaviour, which can cause hard to diagnose
installation errors or even make the installed system unbootable.
Therefore, better raise a parsing error and interrupt the installation
if both commands are used in a single kickstart file.

Signed-off-by: Martin Kolman <mkolman at redhat.com>
---
 pykickstart/parser.py | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/pykickstart/parser.py b/pykickstart/parser.py
index 18e7559..f797cd9 100644
--- a/pykickstart/parser.py
+++ b/pykickstart/parser.py
@@ -733,6 +733,27 @@ class KickstartParser:
             elif self._state == STATE_END:
                 break
 
+        # Check if autopart and part/partition are used at the same time,
+        # if they are used at the same time, raise an error
+
+        # to check if a command has been "seen" by the parser,
+        # we need to check their properties
+        partSeen = self.handler.commands["partition"].dataList()
+        # if dataList() returns a nonempty list, the part/partition
+        # command has been "seen" in the kickstart
+        autopart = self.handler.commands["autopart"]
+        autopartSeen = autopart.autopart
+        # if the "autopart" property is True, the autopart command
+        # has been "seen" in the kickstart
+
+        if partSeen and autopartSeen:
+            # as we can only report one line number, report the line number
+            # of the autopart command
+            lineno = autopart.lineno
+            errorMsg = _("The part and autopart commands can't be used at the same time")
+            raise KickstartParseError, formatErrorMsg(lineno, msg=errorMsg)
+
+
     def readKickstartFromString (self, str, reset=True):
         """Process a kickstart file, provided as the string str."""
         if reset:
-- 
1.8.3.1



More information about the anaconda-patches mailing list