diff --git a/subiquity/common/filesystem/sizes.py b/subiquity/common/filesystem/sizes.py index b63c9dbf..851f0a70 100644 --- a/subiquity/common/filesystem/sizes.py +++ b/subiquity/common/filesystem/sizes.py @@ -115,6 +115,7 @@ def calculate_guided_resize(part_min: int, part_size: int, install_min: int, raw_recommended = math.ceil(resize_window * ratio) + other_min recommended = align_up(raw_recommended, part_align) return GuidedResizeValues( + install_max=plausible_free_space, minimum=other_min, recommended=recommended, maximum=other_max) diff --git a/subiquity/common/filesystem/tests/test_sizes.py b/subiquity/common/filesystem/tests/test_sizes.py index 048f06cd..bd233b03 100644 --- a/subiquity/common/filesystem/tests/test_sizes.py +++ b/subiquity/common/filesystem/tests/test_sizes.py @@ -97,6 +97,7 @@ class TestCalculateGuidedResize(unittest.TestCase): actual = calculate_guided_resize( part_min=8 << 30, part_size=100 << 30, install_min=size) expected = GuidedResizeValues( + install_max=(100 << 30) - size, minimum=size, recommended=50 << 30, maximum=(100 << 30) - size) self.assertEqual(expected, actual) @@ -104,6 +105,7 @@ class TestCalculateGuidedResize(unittest.TestCase): actual = calculate_guided_resize( part_min=40 << 30, part_size=240 << 30, install_min=10 << 30) expected = GuidedResizeValues( + install_max=190 << 30, minimum=50 << 30, recommended=200 << 30, maximum=230 << 30) self.assertEqual(expected, actual) diff --git a/subiquity/common/types.py b/subiquity/common/types.py index ec1796fb..9ba24505 100644 --- a/subiquity/common/types.py +++ b/subiquity/common/types.py @@ -333,6 +333,7 @@ class StorageResponseV2: @attr.s(auto_attribs=True) class GuidedResizeValues: + install_max: int minimum: int recommended: int maximum: int diff --git a/subiquity/server/controllers/filesystem.py b/subiquity/server/controllers/filesystem.py index d2e6c4b5..a79aefbe 100644 --- a/subiquity/server/controllers/filesystem.py +++ b/subiquity/server/controllers/filesystem.py @@ -360,19 +360,18 @@ class FilesystemController(SubiquityController, FilesystemManipulator): Results are sorted by the size of the space potentially available to the install.""" - possible = [] + scenarios = [] install_min = self.calculate_suggested_install_min() for disk in self.get_guided_disks(with_reformatting=True): - possible.append(GuidedStorageTargetReformat(disk_id=disk.id)) + reformat = GuidedStorageTargetReformat(disk_id=disk.id) + scenarios.append((disk.size, reformat)) for disk in self.get_guided_disks(with_reformatting=False): gap = gaps.largest_gap(disk) - # FIXME this gap size check can mean that a disk that is - # accepted is ignored by use_gap - if gap is not None and gap.size > install_min: - possible.append(GuidedStorageTargetUseGap( - disk_id=disk.id, gap=gap)) + if gap is not None and gap.size >= install_min: + use_gap = GuidedStorageTargetUseGap(disk_id=disk.id, gap=gap) + scenarios.append((gap.size, use_gap)) for disk in self.get_guided_disks(check_boot=False): part_align = disk.alignment_data().part_align @@ -381,11 +380,12 @@ class FilesystemController(SubiquityController, FilesystemManipulator): partition.estimated_min_size, partition.size, install_min, part_align=part_align) if vals is not None: - possible.append( - GuidedStorageTargetResize.from_recommendations( - partition, vals)) - # FIXME sort at the end - return GuidedStorageResponseV2(possible=possible) + resize = GuidedStorageTargetResize.from_recommendations( + partition, vals) + scenarios.append((vals.install_max, resize)) + + scenarios.sort(reverse=True, key=lambda x: x[0]) + return GuidedStorageResponseV2(possible=[s[1] for s in scenarios]) async def v2_guided_POST(self, data: GuidedChoiceV2) \ -> GuidedStorageResponseV2: