[PATCH] Allow some sizes in kickstart to take the form of a blivet size spec.

David Lehman dlehman at redhat.com
Fri May 2 18:45:27 UTC 2014



On 05/02/2014 10:36 AM, Chris Lumens wrote:
> This covers the logvol, part, and volgroup commands.  It requires pykickstart
> support in that it should not blindly assume those arguments will be passed in
> as ints.

It might be better to use decimal.Decimal as your "is this a number or a 
size spec?" test, since that would allow anything that Size accepts 
instead of limiting it to integers for the numeric part. Otherwise these 
look good to me.

David

> ---
>   anaconda.spec.in        |  2 +-
>   pyanaconda/kickstart.py | 59 +++++++++++++++++++++++++++++++++++--------------
>   2 files changed, 44 insertions(+), 17 deletions(-)
>
> diff --git a/anaconda.spec.in b/anaconda.spec.in
> index 89f4df2..18c75c0 100755
> --- a/anaconda.spec.in
> +++ b/anaconda.spec.in
> @@ -21,7 +21,7 @@ Source0: %{name}-%{version}.tar.bz2
>   # Also update in AM_GNU_GETTEXT_VERSION in configure.ac
>   %define gettextver 0.18.3
>   %define intltoolver 0.31.2-3
> -%define pykickstartver 1.99.52
> +%define pykickstartver 1.99.55
>   %define yumver 3.4.3-91
>   %define dnfver 0.4.18
>   %define partedver 1.8.1
> diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py
> index 0881c5d..b49ee29 100644
> --- a/pyanaconda/kickstart.py
> +++ b/pyanaconda/kickstart.py
> @@ -1,7 +1,7 @@
>   #
>   # kickstart.py: kickstart install support
>   #
> -# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
> +# Copyright (C) 1999-2014
>   # Red Hat, Inc.  All rights reserved.
>   #
>   # This program is free software; you can redistribute it and/or modify
> @@ -223,6 +223,24 @@ def getAvailableDiskSpace(storage):
>
>       return disk_space
>
> +def makeSize(s, default="MiB"):
> +    try:
> +        _n = int(s)
> +    except ValueError:
> +        # It's not just an integer, so treat the input string as a size spec.
> +        spec = s
> +    else:
> +        # It's just an integer, so treat the input string in terms of the
> +        # default unit.
> +        spec = "%d %s" % (s, default)
> +
> +    try:
> +        return Size(spec=spec)
> +    except (ValueError, SizeParamsError):
> +        raise
> +    except TypeError:
> +        return None
> +
>   ###
>   ### SUBCLASSES OF PYKICKSTART COMMAND HANDLERS
>   ###
> @@ -713,11 +731,9 @@ class LogVolData(commands.logvol.F20_LogVolData):
>           vgname = ksdata.onPart.get(self.vgname, self.vgname)
>
>           try:
> -            size = Size(spec="%d MiB" % self.size)
> +            size = makeSize(self.size)
>           except (ValueError, SizeParamsError):
>               raise KickstartValueError(formatErrorMsg(self.lineno, msg="The size %s is not valid." % self.size))
> -        except TypeError:
> -            pass
>
>           if self.mountpoint == "swap":
>               ty = "swap"
> @@ -850,18 +866,28 @@ class LogVolData(commands.logvol.F20_LogVolData):
>                   parents = [vg]
>
>               if self.thin_pool:
> -                pool_args = { "metadatasize": Size(spec="%d MiB" % self.metadata_size),
> -                              "chunksize": Size(spec="%d KiB" % self.chunk_size) }
> +                try:
> +                    metadata_size = makeSize(self.metadata_size)
> +                except (ValueError, SizeParamsError):
> +                    raise KickstartValueError(formatErrorMsg(self.lineno,
> +                            msg=_("The size \"%s\" is invalid.") % self.metadata_size))
> +
> +                try:
> +                    chunk_size = makeSize(self.chunk_size, default="KiB")
> +                except (ValueError, SizeParamsError):
> +                    raise KickstartValueError(formatErrorMsg(self.lineno,
> +                            msg=_("The size \"%s\" is invalid.") % self.chunk_size))
> +
> +                pool_args = { "metadatasize": metadata_size,
> +                              "chunksize": chunk_size }
>               else:
>                   pool_args = {}
>
>               if self.maxSizeMB:
>                   try:
> -                    maxsize = Size(spec="%d MiB" % self.maxSizeMB)
> +                    maxsize = makeSize(self.maxSizeMB)
>                   except (ValueError, SizeParamsError):
>                       raise KickstartValueError(formatErrorMsg(self.lineno, msg="The maximum size %s is not valid." % self.maxSizeMB))
> -                except TypeError:
> -                    pass
>               else:
>                   maxsize = None
>
> @@ -949,11 +975,9 @@ class PartitionData(commands.partition.F18_PartData):
>           storage.doAutoPart = False
>
>           try:
> -            size = Size(spec="%d MiB" % self.size)
> +            size = makeSize(self.size)
>           except (ValueError, SizeParamsError):
>               raise KickstartValueError(formatErrorMsg(self.lineno, msg="The size %s is not valid." % self.size))
> -        except TypeError:
> -            pass
>
>           if self.onbiosdisk != "":
>               for (disk, biosdisk) in storage.eddDict.iteritems():
> @@ -1105,11 +1129,9 @@ class PartitionData(commands.partition.F18_PartData):
>           kwargs["size"] = size
>           if self.maxSizeMB:
>               try:
> -                maxsize = Size(spec="%d MiB" % self.maxSizeMB)
> +                maxsize = makeSize(self.maxSizeMB)
>               except (ValueError, SizeParamsError):
>                   raise KickstartValueError(formatErrorMsg(self.lineno, msg="The maximum size %s is not valid." % self.maxSizeMB))
> -            except TypeError:
> -                pass
>           else:
>               maxsize = None
>
> @@ -1506,7 +1528,12 @@ class VolGroupData(commands.volgroup.FC16_VolGroupData):
>           if len(pvs) == 0 and not self.preexist:
>               raise KickstartValueError(formatErrorMsg(self.lineno, msg="Volume group defined without any physical volumes.  Either specify physical volumes or use --useexisting."))
>
> -        pesize = Size(spec="%d KiB" % self.pesize)
> +        try:
> +            pesize = makeSize(self.pesize, default="KiB")
> +        except (ValueError, SizeParamsError):
> +            raise KickstartValueError(formatErrorMsg(self.lineno,
> +                    msg=_("The size \"%s\" is invalid.") % self.pesize))
> +
>           if pesize not in getPossiblePhysicalExtents():
>               raise KickstartValueError(formatErrorMsg(self.lineno, msg="Volume group specified invalid pesize"))
>
>


More information about the anaconda-patches mailing list