[rhel6-branch][pykickstart][PATCH 1/2] Raise an error if autopart is combined with partitioning commands (#886010)

Martin Kolman mkolman at redhat.com
Fri Aug 9 13:40:24 UTC 2013


Using autopart together with the part/partition, raid, logvol or
volgroup commands in a single kickstart file can lead to a very bad
and difficult to predict behaviour. It 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 autopart is combined with any of those commands.

Signed-off-by: Martin Kolman <mkolman at redhat.com>
---
 pykickstart/commands/autopart.py  | 30 ++++++++++++++++++++++++++++++
 pykickstart/commands/logvol.py    | 10 ++++++++++
 pykickstart/commands/partition.py |  9 +++++++++
 pykickstart/commands/raid.py      | 10 ++++++++++
 pykickstart/commands/volgroup.py  | 13 +++++++++++++
 pykickstart/handlers/control.py   |  2 +-
 6 files changed, 73 insertions(+), 1 deletion(-)

diff --git a/pykickstart/commands/autopart.py b/pykickstart/commands/autopart.py
index 2885ad4..96dd6ac 100644
--- a/pykickstart/commands/autopart.py
+++ b/pykickstart/commands/autopart.py
@@ -141,3 +141,33 @@ class RHEL6_AutoPart(F12_AutoPart):
         op = F12_AutoPart._getParser(self)
         op.add_option("--cipher")
         return op
+
+    def parse(self, args):
+        # call the overriden command to do it's job first
+        retval = F12_AutoPart.parse(self, args)
+        # Using autopart together with
+        # other partitioning command such as
+        # part/partition, raid, logvol or volgroup
+        # can lead to hard to debug behavior that might
+        # among other result into an unbootable system.
+        #
+        # Therefore if any of those commands is detected
+        # in the same kickstart together with autopart,
+        # an error is raised and installation is aborted.
+        conflicting_command = ""
+        # currentCmd != "" indicates that the corresponding
+        # command has been seen in kickstart
+        if self.handler.partition.currentCmd:
+            conflicting_command = "part (or partition)"
+        elif self.handler.raid.currentCmd:
+            conflicting_command = "raid"
+        elif self.handler.volgroup.currentCmd:
+            conflicting_command = "volgroup"
+        elif self.handler.logvol.currentCmd:
+            conflicting_command = "logvol"
+
+        if conflicting_command:
+            errorMsg = _("The %s and autopart commands can't be used at the same time" 
+                         % conflicting_command)
+            raise KickstartParseError, formatErrorMsg(self.lineno, msg=errorMsg)
+        return retval
diff --git a/pykickstart/commands/logvol.py b/pykickstart/commands/logvol.py
index a51e848..6a7f62f 100644
--- a/pykickstart/commands/logvol.py
+++ b/pykickstart/commands/logvol.py
@@ -298,3 +298,13 @@ class RHEL6_LogVol(F12_LogVol):
                         default=False)
 
         return op
+
+    def parse(self, args):
+        # call the overriden method
+        retval = F12_LogVol.parse(self, args)
+        # the logvol command can't be used together with the autopart command
+        # due to the hard to debug behavior their combination introduces
+        if self.handler.autopart.currentCmd:
+            errorMsg = _("The logvol and autopart commands can't be used at the same time")
+            raise KickstartParseError, formatErrorMsg(self.lineno, msg=errorMsg)
+        return retval
diff --git a/pykickstart/commands/partition.py b/pykickstart/commands/partition.py
index d5e9c39..eb10fbe 100644
--- a/pykickstart/commands/partition.py
+++ b/pykickstart/commands/partition.py
@@ -365,3 +365,12 @@ class RHEL6_Partition(F12_Partition):
                         default=False)
         return op
 
+    def parse(self, args):
+        # first call the overriden command
+        retval = F12_Partition.parse(self, args)
+        # the part command can't be used together with the autopart command
+        # due to the hard to debug behavior their combination introduces
+        if self.handler.autopart.currentCmd:
+            errorMsg = _("The part (or partition) and autopart commands can't be used at the same time")
+            raise KickstartParseError, formatErrorMsg(self.lineno, msg=errorMsg)
+        return retval
diff --git a/pykickstart/commands/raid.py b/pykickstart/commands/raid.py
index 9f44075..3c929bb 100644
--- a/pykickstart/commands/raid.py
+++ b/pykickstart/commands/raid.py
@@ -361,3 +361,13 @@ class RHEL6_Raid(F13_Raid):
         op = F13_Raid._getParser(self)
         op.add_option("--cipher")
         return op
+
+    def parse(self, args):
+        # first call the overriden method
+        retval = F13_Raid.parse(self, args)
+        # the raid command can't be used together with the autopart command
+        # due to the hard to debug behavior their combination introduces
+        if self.handler.autopart.currentCmd:
+            errorMsg = _("The raid and autopart commands can't be used at the same time")
+            raise KickstartParseError, formatErrorMsg(self.lineno, msg=errorMsg)
+        return retval
diff --git a/pykickstart/commands/volgroup.py b/pykickstart/commands/volgroup.py
index ea63e09..01e9767 100644
--- a/pykickstart/commands/volgroup.py
+++ b/pykickstart/commands/volgroup.py
@@ -154,3 +154,16 @@ class F16_VolGroup(FC3_VolGroup):
         op.add_option("--reserved-percent", action="callback", callback=percent_cb,
                       dest="reserved_percent", type="int", nargs=1, default=0)
         return op
+
+
+class RHEL6_VolGroup(F16_VolGroup):
+
+    def parse(self, args):
+        # first call the overriden method
+        retval = F16_VolGroup.parse(self, args)
+        # the volgroup command can't be used together with the autopart command
+        # due to the hard to debug behavior their combination introduces
+        if self.handler.autopart.currentCmd:
+            errorMsg = _("The volgroup and autopart commands can't be used at the same time")
+            raise KickstartParseError, formatErrorMsg(self.lineno, msg=errorMsg)
+        return retval
diff --git a/pykickstart/handlers/control.py b/pykickstart/handlers/control.py
index 6cfa223..0d73c95 100644
--- a/pykickstart/handlers/control.py
+++ b/pykickstart/handlers/control.py
@@ -866,7 +866,7 @@ commandMap = {
         "url": method.RHEL6_Method,
         "user": user.F12_User,
         "vnc": vnc.F9_Vnc,
-        "volgroup": volgroup.F16_VolGroup,
+        "volgroup": volgroup.RHEL6_VolGroup,
         "xconfig": xconfig.F10_XConfig,
         "zerombr": zerombr.F9_ZeroMbr,
         "zfcp": zfcp.F12_ZFCP,
-- 
1.8.3.1



More information about the anaconda-patches mailing list