storage: guided_zfs must align the swap part size

This commit is contained in:
Dan Bungert 2023-09-08 11:04:08 -06:00
parent 705c752320
commit baa475aa15
2 changed files with 14 additions and 1 deletions

View File

@ -563,7 +563,7 @@ class FilesystemController(SubiquityController, FilesystemManipulator):
bpart = self.create_partition(device, gap_boot, dict(fstype=None))
avail = gap_rest.size - self._info.min_size
swap_size = swap.suggested_swapsize(avail=avail)
swap_size = align_down(swap.suggested_swapsize(avail=avail), part_align)
if swap_size > 0:
gap_swap, gap_rootfs = gap_rest.split(swap_size)
self.create_partition(device, gap_swap, dict(fstype="swap"))

View File

@ -526,6 +526,19 @@ class TestGuided(IsolatedAsyncioTestCase):
zfs_boot = self.model._mount_for_path("/boot")
self.assertEqual("zfs", zfs_boot.type)
@mock.patch("subiquity.server.controllers.filesystem.swap.suggested_swapsize")
async def test_guided_zfs_swap_size_lp_2034939(self, suggested):
suggested.return_value = (1 << 30) + 1
# crash due to add_partition for swap with unaligned size
await self._guided_setup(Bootloader.UEFI, "gpt")
target = GuidedStorageTargetReformat(
disk_id=self.d1.id, allowed=default_capabilities
)
await self.controller.guided(
GuidedChoiceV2(target=target, capability=GuidedCapability.ZFS)
)
# just checking that this doesn't throw
async def _guided_side_by_side(self, bl, ptable):
await self._guided_setup(bl, ptable, storage_version=2)
self.controller.add_boot_disk(self.d1)