Skip to content

Commit

Permalink
filesystem: reset-partition size bug
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
Chris-Peterson444 committed May 6, 2024
1 parent 396e4d5 commit 652f732
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion subiquity/server/controllers/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,8 @@ async def run_autoinstall_guided(self, layout):
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 "
Expand Down
21 changes: 21 additions & 0 deletions subiquity/server/controllers/tests/test_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,27 @@ async def test_guided_reset_partition_only(self):
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(
Expand Down

0 comments on commit 652f732

Please sign in to comment.