livemedia-creator: Add support for reqpart kickstart command

reqpart can be used to make kickstarts more platform agnostic, creating
needed partitions without lmc having to keep track of the arch-specific
needs. eg. ppc64 needs prepboot and /boot

This increases the size of the disk based on whether reqpart or
reqpart --add-boot is in the kickstart.

Note that this is only valid for partitioned disk output types, not
for filesystem images or live iso output.

Related: rhbz#1673744
This commit is contained in:
Brian C. Lane 2019-02-13 16:03:05 -08:00
parent aa240fb591
commit 776bb18cee
2 changed files with 79 additions and 0 deletions

View File

@ -445,6 +445,8 @@ def calculate_disk_size(opts, ks):
:param str ks: Path to the kickstart to use for the installation
:returns: Disk size in MiB
:rtype: int
Also takes into account the use of reqpart or reqpart --add-boot
"""
# Disk size for a filesystem image should only be the size of /
# to prevent surprises when using the same kickstart for different installations.
@ -453,6 +455,17 @@ def calculate_disk_size(opts, ks):
disk_size = 2 + sum(p.size for p in unique_partitions.values() if p.mountpoint == "/")
else:
disk_size = 2 + sum(p.size for p in unique_partitions.values())
# reqpart can add 1M, 2M, 200M based on platform. Add 500M to be sure
if ks.handler.reqpart.seen:
log.info("Adding 500M for reqpart")
disk_size += 500
# It can also request adding /boot which is 1G
if ks.handler.reqpart.addBoot:
log.info("Adding 1024M for reqpart --addboot")
disk_size += 1024
log.info("Using disk size of %sMiB", disk_size)
return disk_size

View File

@ -27,6 +27,7 @@ from ..lib import get_file_magic
from pylorax import find_templates
from pylorax.base import DataHolder
from pylorax.creator import FakeDNF, create_pxe_config, make_appliance, make_squashfs, squashfs_args
from pylorax.creator import calculate_disk_size
from pylorax.creator import get_arch, find_ostree_root, check_kickstart
from pylorax.executils import runcmd
from pylorax.imgutils import mksparse
@ -244,6 +245,71 @@ class CreatorTest(unittest.TestCase):
errors = check_kickstart(ks, opts)
self.assertTrue("must include shutdown when using virt" in errors[0])
def disk_size_simple_test(self):
"""Test calculating the disk size with a simple / partition"""
opts = DataHolder(no_virt=True, make_fsimage=False, make_iso=False, make_pxe_live=False)
ks_version = makeVersion()
ks = KickstartParser(ks_version, errorsAreFatal=False, missingIncludeIsFatal=False)
ks.readKickstartFromString("url --url=http://dl.fedoraproject.com\n"
"network --bootproto=dhcp --activate\n"
"repo --name=other --baseurl=http://dl.fedoraproject.com\n"
"part / --size=4096\n"
"shutdown\n")
self.assertEqual(calculate_disk_size(opts, ks), 4098)
def disk_size_boot_test(self):
"""Test calculating the disk size with / and /boot partitions"""
opts = DataHolder(no_virt=True, make_fsimage=False, make_iso=False, make_pxe_live=False)
ks_version = makeVersion()
ks = KickstartParser(ks_version, errorsAreFatal=False, missingIncludeIsFatal=False)
ks.readKickstartFromString("url --url=http://dl.fedoraproject.com\n"
"network --bootproto=dhcp --activate\n"
"repo --name=other --baseurl=http://dl.fedoraproject.com\n"
"part / --size=4096\n"
"part /boot --size=512\n"
"shutdown\n")
self.assertEqual(calculate_disk_size(opts, ks), 4610)
def disk_size_boot_fsimage_test(self):
"""Test calculating the disk size with / and /boot partitions on a fsimage"""
opts = DataHolder(no_virt=True, make_fsimage=True, make_iso=False, make_pxe_live=False)
ks_version = makeVersion()
ks = KickstartParser(ks_version, errorsAreFatal=False, missingIncludeIsFatal=False)
ks.readKickstartFromString("url --url=http://dl.fedoraproject.com\n"
"network --bootproto=dhcp --activate\n"
"repo --name=other --baseurl=http://dl.fedoraproject.com\n"
"part / --size=4096\n"
"part /boot --size=512\n"
"shutdown\n")
self.assertEqual(calculate_disk_size(opts, ks), 4098)
def disk_size_reqpart_test(self):
"""Test calculating the disk size with reqpart and a / partition"""
opts = DataHolder(no_virt=True, make_fsimage=False, make_iso=False, make_pxe_live=False)
ks_version = makeVersion()
ks = KickstartParser(ks_version, errorsAreFatal=False, missingIncludeIsFatal=False)
ks.readKickstartFromString("url --url=http://dl.fedoraproject.com\n"
"network --bootproto=dhcp --activate\n"
"repo --name=other --baseurl=http://dl.fedoraproject.com\n"
"part / --size=4096\n"
"reqpart\n"
"shutdown\n")
self.assertEqual(calculate_disk_size(opts, ks), 4598)
def disk_size_reqpart_boot_test(self):
"""Test calculating the disk size with reqpart --add-boot and a / partition"""
opts = DataHolder(no_virt=True, make_fsimage=False, make_iso=False, make_pxe_live=False)
ks_version = makeVersion()
ks = KickstartParser(ks_version, errorsAreFatal=False, missingIncludeIsFatal=False)
ks.readKickstartFromString("url --url=http://dl.fedoraproject.com\n"
"network --bootproto=dhcp --activate\n"
"repo --name=other --baseurl=http://dl.fedoraproject.com\n"
"part / --size=4096\n"
"reqpart --add-boot\n"
"shutdown\n")
self.assertEqual(calculate_disk_size(opts, ks), 5622)
@unittest.skipUnless(os.geteuid() == 0 and not os.path.exists("/.in-container"), "requires root privileges, and no containers")
def boot_over_root_test(self):
"""Test the mount_boot_part_over_root ostree function"""