diff --git a/src/pylorax/creator.py b/src/pylorax/creator.py index 10972ff5..6ccda92a 100644 --- a/src/pylorax/creator.py +++ b/src/pylorax/creator.py @@ -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 diff --git a/tests/pylorax/test_creator.py b/tests/pylorax/test_creator.py index 14db20d2..ad05ec77 100644 --- a/tests/pylorax/test_creator.py +++ b/tests/pylorax/test_creator.py @@ -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"""