[PATCH] Add --root-device to upgrade command

Chris Lumens clumens at redhat.com
Thu Dec 11 18:53:01 UTC 2008


> the attached patch adds new option to the
> upgrade command in kickstart.
>
> upgrade [--root-device=/dev/sda2]
>
> The purpose is to be able to automatically upgrade systems that are dual boot.
> Specifying which is the root device makes upgrades more flexible.
>
> More info is available at anaconda-devel-list:
> https://www.redhat.com/archives/anaconda-devel-list/2008-December/msg00162.html

Note that we do actually have a bug number for this - 471232.

> diff --git a/pykickstart/commands/upgrade.py b/pykickstart/commands/upgrade.py
> index b7dba86..8510fbe 100644
> --- a/pykickstart/commands/upgrade.py
> +++ b/pykickstart/commands/upgrade.py
> @@ -30,20 +30,37 @@ class FC3_Upgrade(KickstartCommand):
>  
>      def __init__(self, writePriority=0, *args, **kwargs):
>          KickstartCommand.__init__(self, writePriority, *args, **kwargs)
> +        self.op = self._getParser()
> +
>          self.upgrade = kwargs.get("upgrade", None)
> +        self.root_device = kwargs.get("root_device", None)
>  
>      def __str__(self):
>          if self.upgrade is None:
> -            return ""
> +            retval=""
>  
>          if self.upgrade:
> -            return "# Upgrade existing installation\nupgrade\n"
> +            if (self.root_device is not None):
> +                retval="# Upgrade existing installation\nupgrade --root-device=%s\n" % self.root_device
> +            else:
> +                retval="# Upgrade existing installation\nupgrade\n"
>          else:
> -            return "# Install OS instead of upgrade\ninstall\n"
> +            retval="# Install OS instead of upgrade\ninstall\n"
> +
> +        return retval
> +
> +    def _getParser(self):
> +        op = KSOptionParser(lineno=self.lineno)
> +        op.add_option("--root-device", dest="root_device")
> +        return op
>  
>      def parse(self, args):
> -        if len(args) > 0:
> -            raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Kickstart command %s does not take any arguments") % "upgrade")
> +        (opts, extra) = self.op.parse_args(args=args)
> +
> +        if (opts.root_device is not None) and (opts.root_device == ""):
> +            raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Kickstart command %s does not accept empty parameter %s") % ("upgrade", "--root-device"))
> +        else:
> +            self.root_device = opts.root_device
>  
>          if self.currentCmd == "upgrade":
>             self.upgrade = True
> 

Thanks for fetching pykickstart first and following all my recent
stylistic changes (like the kwargs.get stuff)!

However, you don't want to add this option to FC3_Upgrade.  You'll want
to make a new F11_Upgrade object that inherits from FC3_Upgrade, then
modify the appropriate commandMap entry in handlers/control.py to
reference the F11_Upgrade object.  Then the F11_Upgrade class gets the
new option and the FC3_Upgrade class goes untouched.

Before you can do that, I will need to add support for F11 throughout,
which will only take a second.  I'll do that just as soon as I send this
mail.

Aside from that one comment, I'm happy with the name of the parameter
and how you've implemented it.  I'm sure a second run of the patch with
the new class will be fine.

- Chris




More information about the Kickstart-list mailing list