filesystem: reset-partition size bug

In python, bool is a subclass of int so we can't use isinstance
to check if the user specified a size for the reset partition.
This causes autoinstall with "reset-partition: True" and
"reset-partition-only: true" to crash the installer due to creating
a reset-partition of size 1 (LP: #2061042).
This commit is contained in:
Chris Peterson 2024-04-12 15:44:27 -07:00
parent 396e4d5a87
commit 652f73209c
2 changed files with 23 additions and 1 deletions

View File

@ -1457,7 +1457,8 @@ class FilesystemController(SubiquityController, FilesystemManipulator):
rp_input = layout.get("reset-partition", None)
if rp_input:
reset_partition = True
if isinstance(rp_input, (str, int)):
# bool is a subclass of int -- check for int explicitly
if isinstance(rp_input, str) or type(rp_input) is int:
reset_partition_size = int(human2bytes(rp_input))
log.info(
"autoinstall: will install reset partition "

View File

@ -546,6 +546,27 @@ class TestGuided(IsolatedAsyncioTestCase):
self.assertEqual(None, d1p2.mount)
self.assertEqual(DRY_RUN_RESET_SIZE, d1p2.size)
@parameterized.expand(
(
({}, False, None),
({"reset-partition": True}, True, None),
({"reset-partition": False}, False, None),
({"reset-partition": "12345"}, True, 12345),
({"reset-partition": "10G"}, True, 10737418240),
({"reset-partition": 100000}, True, 100000),
)
)
async def test_rest_partition_size(
self, ai_data, reset_partition, reset_partition_size
):
await self._guided_setup(Bootloader.UEFI, "gpt")
self.controller.guided = mock.AsyncMock()
layout = ai_data | {"name": "direct"}
await self.controller.run_autoinstall_guided(layout)
guided_choice = self.controller.guided.call_args.args[0]
self.assertEqual(guided_choice.reset_partition, reset_partition)
self.assertEqual(guided_choice.reset_partition_size, reset_partition_size)
async def test_guided_direct_BIOS_MSDOS(self):
await self._guided_setup(Bootloader.BIOS, "msdos")
target = GuidedStorageTargetReformat(