From fa81e0981e9d0c6028ecdbc835b9ca2750a232e1 Mon Sep 17 00:00:00 2001 From: Dan Bungert Date: Fri, 7 Apr 2023 08:59:34 -0600 Subject: [PATCH 1/3] test/api: regression test for LP: #2015521 --- subiquity/tests/api/test_api.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/subiquity/tests/api/test_api.py b/subiquity/tests/api/test_api.py index fd75ca5b..72a1f4a1 100644 --- a/subiquity/tests/api/test_api.py +++ b/subiquity/tests/api/test_api.py @@ -1469,6 +1469,38 @@ class TestRegression(TestAPI): v1resp = await inst.get('/storage') self.assertEqual([], match(v1resp['config'], type='format')) + @timeout() + async def test_guided_v2_resize_logical_middle_partition(self): + '''LP: #2015521 - a logical partition that wasn't the physically last + logical partition was resized to allow creation of more partitions, but + the 1MiB space was not left between the newly created partition and the + physically last partition.''' + cfg = 'examples/threebuntu-on-msdos.json' + extra = ['--storage-version', '2'] + async with start_server(cfg, extra_args=extra) as inst: + resp = await inst.get('/storage/v2/guided') + [resize] = match(resp['possible'], partition_number=5, + _type='GuidedStorageTargetResize') + data = { + 'target': resize, + 'capability': resize['capabilities'][0], + } + resp = await inst.post('/storage/v2/guided', data) + self.assertEqual(resize, resp['configured']['target']) + + resp = await inst.get('/storage') + parts = match(resp['config'], type='partition', flag='logical') + logicals = [] + for part in parts: + part['end'] = part['offset'] + part['size'] + logicals.append(part) + + logicals.sort(key=lambda p: p['offset']) + for i in range(len(logicals) - 1): + cur, nxt = logicals[i:i+2] + self.assertLessEqual(cur['end'] + (1 << 20), nxt['offset'], + f'partition overlap {cur} {nxt}') + class TestCancel(TestAPI): @timeout() From dc810414d89f0d421052f804530b346bbc73e5ec Mon Sep 17 00:00:00 2001 From: Dan Bungert Date: Fri, 7 Apr 2023 09:37:17 -0600 Subject: [PATCH 2/3] gaps: add unittests for gap before part on msdos --- .../common/filesystem/tests/test_gaps.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/subiquity/common/filesystem/tests/test_gaps.py b/subiquity/common/filesystem/tests/test_gaps.py index 0db2bbf4..2ef18d44 100644 --- a/subiquity/common/filesystem/tests/test_gaps.py +++ b/subiquity/common/filesystem/tests/test_gaps.py @@ -333,6 +333,32 @@ class TestDiskGaps(unittest.TestCase): gaps.Gap(d, 50, 50, False), ]) + def test_gap_before_primary(self): + # 0----10---20---30---40---50---60---70---80---90---100 + # [ g1 ][ p1 (primary) ] + info = PartitionAlignmentData( + part_align=5, min_gap_size=1, min_start_offset=0, min_end_offset=0, + ebr_space=1, primary_part_limit=10) + m, d = make_model_and_disk(size=100, ptable='dos') + p1 = make_partition(m, d, offset=50, size=50) + self.assertEqual( + gaps.find_disk_gaps_v2(d, info), + [gaps.Gap(d, 0, 50, False), p1]) + + def test_gap_in_extended_before_logical(self): + # 0----10---20---30---40---50---60---70---80---90---100 + # [ p1 (extended) ] + # [ g1 ] [ p5 (logical) ] + info = PartitionAlignmentData( + part_align=5, min_gap_size=1, min_start_offset=0, min_end_offset=0, + ebr_space=1, primary_part_limit=10) + m, d = make_model_and_disk(size=100, ptable='dos') + p1 = make_partition(m, d, offset=0, size=100, flag='extended') + p5 = make_partition(m, d, offset=50, size=50, flag='logical') + self.assertEqual( + gaps.find_disk_gaps_v2(d, info), + [p1, gaps.Gap(d, 5, 40, True), p5]) + def test_unusable_gap_primaries(self): info = PartitionAlignmentData( part_align=10, min_gap_size=1, min_start_offset=0, From 5219ecf50c9f4a42b0c5388421a88f6442fd9269 Mon Sep 17 00:00:00 2001 From: Dan Bungert Date: Fri, 7 Apr 2023 09:26:42 -0600 Subject: [PATCH 3/3] gaps: fix gap when before a partition in extended We need the ebr space if we're doing logical partitions, but not for the primaries. --- subiquity/common/filesystem/gaps.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/subiquity/common/filesystem/gaps.py b/subiquity/common/filesystem/gaps.py index fd319c6b..37ff3518 100644 --- a/subiquity/common/filesystem/gaps.py +++ b/subiquity/common/filesystem/gaps.py @@ -150,7 +150,10 @@ def find_disk_gaps_v2(device, info=None): if part is None: gap_end = ad(device.size - info.min_end_offset) else: - gap_end = ad(part.offset) + if part.is_logical: + gap_end = ad(part.offset - info.ebr_space) + else: + gap_end = ad(part.offset) gap_start = au(prev_end)