From 20848f44b70cb40abc698adc7ea261173f21f547 Mon Sep 17 00:00:00 2001 From: Dan Bungert Date: Tue, 5 Sep 2023 11:53:03 -0600 Subject: [PATCH] storage: fix crash when guided and a small disk In LP: #2034270, a 1MiB disk is present. This is triggering a crash while attempting to decide if we can do a guided install. --- subiquity/server/controllers/filesystem.py | 6 ++++- .../controllers/tests/test_filesystem.py | 24 ++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/subiquity/server/controllers/filesystem.py b/subiquity/server/controllers/filesystem.py index 2d70bc13..5af288a3 100644 --- a/subiquity/server/controllers/filesystem.py +++ b/subiquity/server/controllers/filesystem.py @@ -162,7 +162,11 @@ class VariationInfo: ) -> CapabilityInfo: r = CapabilityInfo() r.disallowed = list(self.capability_info.disallowed) - if self.capability_info.allowed and gap.size < install_min: + if gap is None: + gap_size = 0 + else: + gap_size = gap.size + if self.capability_info.allowed and gap_size < install_min: for capability in self.capability_info.allowed: r.disallowed.append( GuidedDisallowedCapability( diff --git a/subiquity/server/controllers/tests/test_filesystem.py b/subiquity/server/controllers/tests/test_filesystem.py index c9734bdd..f891d789 100644 --- a/subiquity/server/controllers/tests/test_filesystem.py +++ b/subiquity/server/controllers/tests/test_filesystem.py @@ -695,7 +695,7 @@ class TestGuidedV2(IsolatedAsyncioTestCase): self.assertEqual([reformat, manual], guided_get_resp.targets) @parameterized.expand(bootloaders_and_ptables) - async def test_small_blank_disk(self, bootloader, ptable): + async def test_small_blank_disk_1GiB(self, bootloader, ptable): await self._setup(bootloader, ptable, size=1 << 30) resp = await self.fsc.v2_guided_GET() expected = [ @@ -708,6 +708,28 @@ class TestGuidedV2(IsolatedAsyncioTestCase): ] self.assertEqual(expected, resp.targets) + @parameterized.expand(bootloaders_and_ptables) + async def test_small_blank_disk_1MiB(self, bootloader, ptable): + await self._setup(bootloader, ptable, size=1 << 20) + resp = await self.fsc.v2_guided_GET() + + reformat = GuidedStorageTargetReformat( + disk_id=self.disk.id, + allowed=[], + disallowed=default_capabilities_disallowed_too_small, + ) + manual = GuidedStorageTargetManual() + + # depending on bootloader/ptable combo, GuidedStorageTargetReformat may + # show up but it will all be disallowed. + for target in resp.targets: + if isinstance(target, GuidedStorageTargetManual): + self.assertEqual(target, manual) + elif isinstance(target, GuidedStorageTargetReformat): + self.assertEqual(target, reformat) + else: + raise Exception(f"unexpected target {target}") + @parameterized.expand(bootloaders_and_ptables) async def test_used_half_disk(self, bootloader, ptable): await self._setup(bootloader, ptable, size=100 << 30)