From edde0965401669d2df93a58dcde1ae41228c9ee2 Mon Sep 17 00:00:00 2001 From: Dan Bungert Date: Mon, 28 Aug 2023 18:23:40 -0600 Subject: [PATCH] filesystem: capability flags in a specific order Show DIRECT first, list CORE_BOOT ones later. LP: #2033244 --- subiquity/common/tests/test_types.py | 3 +++ subiquity/common/types.py | 5 +++++ subiquity/server/controllers/filesystem.py | 4 +++- subiquity/tests/api/test_api.py | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/subiquity/common/tests/test_types.py b/subiquity/common/tests/test_types.py index ae6930b0..3bff29d1 100644 --- a/subiquity/common/tests/test_types.py +++ b/subiquity/common/tests/test_types.py @@ -38,3 +38,6 @@ class TestCapabilities(unittest.TestCase): def test_is_zfs(self): self.assertTrue(GuidedCapability.ZFS.is_zfs()) + + def test_order(self): + self.assertLess(GuidedCapability.DIRECT, GuidedCapability.CORE_BOOT_ENCRYPTED) diff --git a/subiquity/common/types.py b/subiquity/common/types.py index c29a4380..708f45c4 100644 --- a/subiquity/common/types.py +++ b/subiquity/common/types.py @@ -340,6 +340,8 @@ class Disk: class GuidedCapability(enum.Enum): + # The order listed here is the order they will be presented as options + MANUAL = enum.auto() DIRECT = enum.auto() LVM = enum.auto() @@ -354,6 +356,9 @@ class GuidedCapability(enum.Enum): DD = enum.auto() + def __lt__(self, other) -> bool: + return self.value < other.value + def is_lvm(self) -> bool: return self in [GuidedCapability.LVM, GuidedCapability.LVM_LUKS] diff --git a/subiquity/server/controllers/filesystem.py b/subiquity/server/controllers/filesystem.py index c0fbf1a6..067ffa26 100644 --- a/subiquity/server/controllers/filesystem.py +++ b/subiquity/server/controllers/filesystem.py @@ -128,6 +128,8 @@ class CapabilityInfo: new_disallowed.append(disallowed_cap) seen_disallowed.add(disallowed_cap.capability) self.disallowed = new_disallowed + self.allowed.sort() + self.disallowed.sort() @attr.s(auto_attribs=True) @@ -967,7 +969,7 @@ class FilesystemController(SubiquityController, FilesystemManipulator): continue if not info.is_core_boot_classic(): classic_capabilities.update(info.capability_info.allowed) - return sorted(classic_capabilities, key=lambda x: x.name) + return sorted(classic_capabilities) async def v2_guided_GET(self, wait: bool = False) -> GuidedStorageResponseV2: """Acquire a list of possible guided storage configuration scenarios. diff --git a/subiquity/tests/api/test_api.py b/subiquity/tests/api/test_api.py index f76fcd2e..2591fda7 100644 --- a/subiquity/tests/api/test_api.py +++ b/subiquity/tests/api/test_api.py @@ -349,6 +349,7 @@ class TestFlow(TestAPI): resp = await inst.get("/storage/v2/guided?wait=true") [reformat, manual] = resp["targets"] + self.assertEqual("DIRECT", reformat["allowed"][0]) await inst.post( "/storage/v2/guided", {