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.
This commit is contained in:
parent
674727595e
commit
20848f44b7
|
@ -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(
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue