Merge ~blake-rouse/maas:fix-1792401-2.3 into maas:2.3

Proposed by Blake Rouse
Status: Merged
Approved by: Blake Rouse
Approved revision: 2504ed45be3e040e2d7926922b75d97cc3392053
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~blake-rouse/maas:fix-1792401-2.3
Merge into: maas:2.3
Diff against target: 174 lines (+154/-1)
2 files modified
src/maasserver/models/partition.py (+6/-1)
src/maasserver/tests/test_preseed_storage.py (+148/-0)
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Review via email: mp+355338@code.launchpad.net

Commit message

Backport of 05c17ea3132e89d70dbaea759aa90ef9287d5098.

Fixes LP: #1792401 - Fix partition number onvirtual block devices to not expect a bios_grub partition on top of GPT.

To post a comment you must log in.
Revision history for this message
Blake Rouse (blake-rouse) wrote :

Self-approving backport.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/models/partition.py b/src/maasserver/models/partition.py
2index b2e27a1..a3bcbfb 100644
3--- a/src/maasserver/models/partition.py
4+++ b/src/maasserver/models/partition.py
5@@ -197,7 +197,12 @@ class Partition(CleanSave, TimestampedModel):
6 if (arch == "ppc64el" and block_device.id == boot_disk.id):
7 return idx + 2
8 elif arch == "amd64" and bios_boot_method != "uefi":
9- return idx + 2
10+ # Delay the `type` check because it can cause a query. Only
11+ # physical block devices get the bios_grub partition.
12+ if block_device.type == 'physical':
13+ return idx + 2
14+ else:
15+ return idx + 1
16 else:
17 return idx + 1
18 elif self.partition_table.table_type == PARTITION_TABLE_TYPE.MBR:
19diff --git a/src/maasserver/tests/test_preseed_storage.py b/src/maasserver/tests/test_preseed_storage.py
20index 20f376c..1892e11 100644
21--- a/src/maasserver/tests/test_preseed_storage.py
22+++ b/src/maasserver/tests/test_preseed_storage.py
23@@ -1872,3 +1872,151 @@ class TestBootableRaidLayoutGPT(MAASServerTestCase, AssertStorageConfigMixin):
24 node._create_acquired_filesystems()
25 config = compose_curtin_storage_config(node)
26 self.assertStorageConfig(self.STORAGE_CONFIG, config)
27+
28+
29+class TestBootableRaidLayoutGPTWithPartition(
30+ MAASServerTestCase, AssertStorageConfigMixin):
31+
32+ STORAGE_CONFIG = dedent("""\
33+ config:
34+ - id: sda
35+ model: vendor
36+ name: sda
37+ ptable: gpt
38+ serial: serial-a
39+ type: disk
40+ wipe: superblock
41+ grub_device: true
42+ - device: sda
43+ flag: bios_grub
44+ id: sda-part1
45+ number: 1
46+ offset: 4194304B
47+ size: 1048576B
48+ type: partition
49+ wipe: zero
50+ - grub_device: true
51+ id: sdb
52+ model: vendor
53+ name: sdb
54+ ptable: gpt
55+ serial: serial-b
56+ type: disk
57+ wipe: superblock
58+ - device: sdb
59+ flag: bios_grub
60+ id: sdb-part1
61+ number: 1
62+ offset: 4194304B
63+ size: 1048576B
64+ type: partition
65+ wipe: zero
66+ - grub_device: true
67+ id: sdc
68+ model: vendor
69+ name: sdc
70+ ptable: gpt
71+ serial: serial-c
72+ type: disk
73+ wipe: superblock
74+ - device: sdc
75+ flag: bios_grub
76+ id: sdc-part1
77+ number: 1
78+ offset: 4194304B
79+ size: 1048576B
80+ type: partition
81+ wipe: zero
82+ - device: sda
83+ flag: boot
84+ id: sda-part2
85+ name: sda-part2
86+ number: 2
87+ size: 5497549750272B
88+ type: partition
89+ uuid: uuid-a
90+ wipe: superblock
91+ - device: sdb
92+ flag: boot
93+ id: sdb-part2
94+ name: sdb-part2
95+ number: 2
96+ size: 5497549750272B
97+ type: partition
98+ uuid: uuid-b
99+ wipe: superblock
100+ - device: sdc
101+ flag: boot
102+ id: sdc-part2
103+ name: sdc-part2
104+ number: 2
105+ size: 5497549750272B
106+ type: partition
107+ uuid: uuid-c
108+ wipe: superblock
109+ - devices:
110+ - sda-part2
111+ - sdb-part2
112+ - sdc-part2
113+ id: md0
114+ name: md0
115+ ptable: gpt
116+ raidlevel: 1
117+ spare_devices: []
118+ type: raid
119+ - device: md0
120+ id: md0-part1
121+ name: md0-part1
122+ number: 1
123+ offset: 4194304B
124+ size: 1099511627776B
125+ type: partition
126+ uuid: uuid-raid-part
127+ wipe: superblock
128+ - fstype: ext4
129+ id: md0-part1_format
130+ label: null
131+ type: format
132+ uuid: root-part
133+ volume: md0-part1
134+ - device: md0-part1_format
135+ id: md0-part1_mount
136+ path: /
137+ type: mount
138+ """)
139+
140+ def test__renders_expected_output(self):
141+ node = factory.make_Node(
142+ status=NODE_STATUS.ALLOCATED, architecture="amd64/generic",
143+ with_boot_disk=False)
144+ size = 5 * 1024 ** 4 # 5Tb
145+ partitions = []
146+ for letter in 'abc':
147+ disk = factory.make_PhysicalBlockDevice(
148+ node=node, model='vendor', serial='serial-' + letter,
149+ size=size, name='sd' + letter)
150+ table_type = PARTITION_TABLE_TYPE.GPT
151+ part_table = factory.make_PartitionTable(
152+ table_type=table_type, block_device=disk)
153+ partitions.append(
154+ factory.make_Partition(
155+ partition_table=part_table,
156+ uuid='uuid-' + letter,
157+ size=size - PARTITION_TABLE_EXTRA_SPACE,
158+ bootable=True))
159+ raid = RAID.objects.create_raid(
160+ level=FILESYSTEM_GROUP_TYPE.RAID_1,
161+ name="md0", uuid='uuid-raid',
162+ partitions=partitions)
163+ raid_part_table = factory.make_PartitionTable(
164+ table_type=PARTITION_TABLE_TYPE.GPT,
165+ block_device=raid.virtual_device)
166+ raid_partition = factory.make_Partition(
167+ partition_table=raid_part_table, uuid='uuid-raid-part',
168+ size=1 * 1024 ** 4, bootable=False)
169+ factory.make_Filesystem(
170+ partition=raid_partition, fstype=FILESYSTEM_TYPE.EXT4,
171+ uuid="root-part", mount_point="/", mount_options=None)
172+ node._create_acquired_filesystems()
173+ config = compose_curtin_storage_config(node)
174+ self.assertStorageConfig(self.STORAGE_CONFIG, config)

Subscribers

People subscribed via source and target branches