boot: handle small disk case

The BIOS boot plan check assumes that there is at least one result in
the list from gaps.parts_and_gaps(), but that isn't the case if the disk
is small.

Showed up in VM testing using cloud-localds to seed the autoinstall
file.
This commit is contained in:
Dan Bungert 2022-06-17 13:34:15 -06:00
parent 01db706867
commit e61a504810
2 changed files with 11 additions and 2 deletions

View File

@ -154,6 +154,7 @@ def get_boot_device_plan_bios(device) -> Optional[MakeBootDevicePlan]:
if device.ptable == 'msdos':
return attr_plan
pgs = gaps.parts_and_gaps(device)
if len(pgs) > 0:
if isinstance(pgs[0], Partition) and pgs[0].flag == "bios_grub":
return attr_plan

View File

@ -457,6 +457,14 @@ class TestFilesystemManipulator(unittest.TestCase):
preserve=True)
self.assertFalse(boot.can_be_boot_device(disk))
@parameterized.expand([(1,), (2,)])
def test_no_add_boot_BIOS_gpt_teeny_disk(self, version):
# Showed up in VM testing - the ISO created cloud-localds shows up as a
# potential install target, and weird things happen.
manipulator = make_manipulator(Bootloader.BIOS, version)
disk = make_disk(manipulator.model, ptable='gpt', size=1 << 20)
self.assertFalse(boot.can_be_boot_device(disk))
@parameterized.expand([(1,), (2,)])
def test_add_boot_BIOS_msdos(self, version):
manipulator = make_manipulator(Bootloader.BIOS, version)