Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept a fixed partition size for reset partition in autoinstall.yaml #1880

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions subiquity/common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ class GuidedChoiceV2:

sizing_policy: Optional[SizingPolicy] = SizingPolicy.SCALED
reset_partition: bool = False
reset_partition_size: Optional[int] = None


@attr.s(auto_attribs=True)
Expand Down
23 changes: 21 additions & 2 deletions subiquity/server/controllers/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from curtin import swap
from curtin.commands.extract import AbstractSourceHandler
from curtin.storage_config import ptable_part_type_to_flag
from curtin.util import human2bytes

from subiquity.common.apidef import API
from subiquity.common.errorreport import ErrorReportKind
Expand Down Expand Up @@ -707,7 +708,10 @@ async def guided(
raise Exception("failed to locate gap after adding boot")

if choice.reset_partition:
if self.app.opts.dry_run:
if choice.reset_partition_size is not None:
part_align = disk.alignment_data().part_align
reset_size = align_up(choice.reset_partition_size, part_align)
elif self.app.opts.dry_run:
reset_size = DRY_RUN_RESET_SIZE
else:
cp = await arun_command(["du", "-sb", "/cdrom"])
Expand Down Expand Up @@ -1410,6 +1414,20 @@ async def run_autoinstall_guided(self, layout):
disk_id=gap.device.id, gap=gap, allowed=[]
)

reset_partition = False
reset_partition_size = None
rp_input = layout.get("reset-partition", None)
if rp_input:
reset_partition = True
if isinstance(rp_input, (str, int)):
reset_partition_size = int(human2bytes(rp_input))
log.info(
"autoinstall: will install reset partition "
f"of size {reset_partition_size}"
medicalwei marked this conversation as resolved.
Show resolved Hide resolved
)
else:
log.info("autoinstall: will install reset partition")

log.info(
f"autoinstall: running guided {capability} install in "
f"mode {mode} using {target}"
Expand All @@ -1421,7 +1439,8 @@ async def run_autoinstall_guided(self, layout):
password=password,
recovery_key=guided_recovery_key,
sizing_policy=sizing_policy,
reset_partition=layout.get("reset-partition", False),
reset_partition=reset_partition,
reset_partition_size=reset_partition_size,
),
reset_partition_only=layout.get("reset-partition-only", False),
)
Expand Down
20 changes: 20 additions & 0 deletions subiquity/server/controllers/tests/test_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,26 @@ async def test_guided_reset_partition(self):
self.assertEqual(DRY_RUN_RESET_SIZE, d1p2.size)
self.assertEqual("/", d1p3.mount)

async def test_fixed_reset_partition(self):
await self._guided_setup(Bootloader.UEFI, "gpt")
target = GuidedStorageTargetReformat(
disk_id=self.d1.id, allowed=default_capabilities
)
fixed_reset_size = 12 << 30
await self.controller.guided(
GuidedChoiceV2(
target=target,
capability=GuidedCapability.DIRECT,
reset_partition=True,
reset_partition_size=fixed_reset_size,
)
)
[d1p1, d1p2, d1p3] = self.d1.partitions()
self.assertEqual("/boot/efi", d1p1.mount)
self.assertIsNone(d1p2.mount)
self.assertEqual(fixed_reset_size, d1p2.size)
self.assertEqual("/", d1p3.mount)

async def test_guided_reset_partition_only(self):
await self._guided_setup(Bootloader.UEFI, "gpt")
target = GuidedStorageTargetReformat(
Expand Down
Loading