From fc05e77a4c39c1ae40be95f1acccfe36d5016fd3 Mon Sep 17 00:00:00 2001 From: Dan Bungert Date: Fri, 22 Mar 2024 16:33:21 -0600 Subject: [PATCH] filesystem: handle empty string fstype partitions This should not result in a format object being created, which curtin doesn't like. Normalize to None as the fstype to skip format object creation. LP: #2058394 --- subiquity/server/controllers/filesystem.py | 4 +++- subiquity/tests/api/test_api.py | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/subiquity/server/controllers/filesystem.py b/subiquity/server/controllers/filesystem.py index 8111f42b8..98a4e09c7 100644 --- a/subiquity/server/controllers/filesystem.py +++ b/subiquity/server/controllers/filesystem.py @@ -1199,9 +1199,11 @@ async def v2_add_partition_POST(self, data: AddPartitionV2) -> StorageResponseV2 raise ValueError("new partition too large") if requested_size < 1: requested_size = data.gap.size + # empty string is an unformatted partition + fstype = data.partition.format or None spec = { "size": requested_size, - "fstype": data.partition.format, + "fstype": fstype, "mount": data.partition.mount, } diff --git a/subiquity/tests/api/test_api.py b/subiquity/tests/api/test_api.py index 2d9f33c1b..9468e112d 100644 --- a/subiquity/tests/api/test_api.py +++ b/subiquity/tests/api/test_api.py @@ -782,6 +782,28 @@ async def test_add_format_required(self): with self.assertRaises(ClientResponseError, msg=f"data {data}"): await inst.post("/storage/v2/add_partition", data) + @timeout() + async def test_add_unformatted_ok(self): + disk_id = "disk-sda" + async with start_server("examples/machines/simple.json") as inst: + for fmt in ("", None): + await inst.post("/storage/v2/reset") + disk_id = "disk-sda" + resp = await inst.get("/storage/v2") + [sda] = match(resp["disks"], id=disk_id) + [gap] = sda["partitions"] + + data = { + "disk_id": disk_id, + "gap": gap, + "partition": dict(format=fmt, mount="/"), + } + await inst.post("/storage/v2/add_partition", data) + + v1resp = await inst.get("/storage") + empties = match(v1resp["config"], type="format", fstype="") + self.assertEqual(0, len(empties), "invalid format object") + @timeout() async def test_add_default_size_handling(self): async with start_server("examples/machines/simple.json") as inst: