[PATCH] Allow some sizes in kickstart to take the form of a blivet size spec.
Chris Lumens
clumens at redhat.com
Fri May 2 15:36:41 UTC 2014
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.
---
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"))
--
1.8.3.1
More information about the anaconda-patches
mailing list