From baa475aa15612e8e14890553662f20bc12f0ffcc Mon Sep 17 00:00:00 2001 From: Dan Bungert Date: Fri, 8 Sep 2023 11:04:08 -0600 Subject: [PATCH] storage: guided_zfs must align the swap part size --- subiquity/server/controllers/filesystem.py | 2 +- .../server/controllers/tests/test_filesystem.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/subiquity/server/controllers/filesystem.py b/subiquity/server/controllers/filesystem.py index bda5f03a..eb40eded 100644 --- a/subiquity/server/controllers/filesystem.py +++ b/subiquity/server/controllers/filesystem.py @@ -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")) diff --git a/subiquity/server/controllers/tests/test_filesystem.py b/subiquity/server/controllers/tests/test_filesystem.py index 36fd47cb..cf6cb6bb 100644 --- a/subiquity/server/controllers/tests/test_filesystem.py +++ b/subiquity/server/controllers/tests/test_filesystem.py @@ -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)