Merge ~raharper/curtin:fix/partition-verify-flags-msdos-primary-types into curtin:master

Proposed by Ryan Harper
Status: Merged
Approved by: Ryan Harper
Approved revision: 669b5cf73d4cf15e1bccfb9913f15125fbb4b9c1
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~raharper/curtin:fix/partition-verify-flags-msdos-primary-types
Merge into: curtin:master
Diff against target: 771 lines (+699/-10)
5 files modified
curtin/commands/block_meta.py (+3/-1)
curtin/storage_config.py (+14/-9)
tests/data/probert_storage_msdos_mbr_extended_v2.json (+537/-0)
tests/unittests/test_commands_block_meta.py (+111/-0)
tests/unittests/test_storage_config.py (+34/-0)
Reviewer Review Type Date Requested Status
Chad Smith Approve
Lucas Albuquerque Medeiros de Moura (community) Approve
Server Team CI bot continuous-integration Approve
Ryan Harper (community) Needs Fixing
Review via email: mp+384133@code.launchpad.net

Commit message

verify_ptable_flag: dos primary partitions use ptable_uuid map for flag

Curtin currently special-cases verifying MSDOS 'boot', 'extended'
and 'logical' flags. This ignored primary DOS partitions. When
verifying partition flags on a MSDOS primary partition use
ptable_uuid_to_flag_entry map as we do for GPT partitions.

LP: #1878890

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Lucas Albuquerque Medeiros de Moura (lamoura) wrote :

I don't know if this is a possible scenario, but is it possible to have a boot type partition that is not marked as bootable ?

For example, suppose we have this type of configuration:

sfdisk_info_dos = {
            "label": "dos",
            "id": "0xb0dbdde1",
            "device": "/dev/vdb",
            "unit": "sectors",
            "partitions": [
               {"node": "/dev/vdb1", "start": 2048, "size": 8388608,
                "type": "80"},
               {"node": "/dev/vdb2", "start": 8390656, "size": 8388608,
                "type": "83"}]
}

In that scenario the boot check would fail, because we will not have the bootable key, but the MBR_TYPE_TO_CURTIN_MAP would find the expected "boot" flag as we want.

But do we want to have a boot partition that is not marked as bootable ? I think this scenario can happen if we provide a custom sfdisk_info dict to the function, but I don't know if that can actually happen, or if it does, if it is a problem.

Revision history for this message
Ryan Harper (raharper) wrote :

Good catch, and actually I need to remove the 0x80 from the MBR table, as it's a flag, not a table type. I'll add a unittest covering this scenario.

Revision history for this message
Ryan Harper (raharper) wrote :

Marking Needs Fixing so we don't land until I fix.

review: Needs Fixing
6f37807... by Ryan Harper

Drop 0x80 boot flag from MBR_TYPE map, it's a PART_ENTRY_FLAGS value only.

3368f31... by Ryan Harper

Ensure boot flag is captured even on logical partitions

7e0fb61... by Ryan Harper

Add unittest for logical partition with boot flag

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
669b5cf... by Ryan Harper

Add unittest data file

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Lucas Albuquerque Medeiros de Moura (lamoura) wrote :

To the best of knowledge, I could not find any issue with the code

review: Approve
Revision history for this message
Chad Smith (chad.smith) wrote :

 Nice one Ryan, this looks good. one minor question/suggestion about whether we can always expect a 'type' key from block.get_partition_sfdisk_info and how we should handle it.
Otherwise +1

Revision history for this message
Chad Smith (chad.smith) :
review: Approve
Revision history for this message
Ryan Harper (raharper) wrote :

@Chad

Yes, each partition entry has a type.

Revision history for this message
Ryan Harper (raharper) :
Revision history for this message
Ryan Harper (raharper) wrote :

Kicking off a few vmtests

Revision history for this message
Ryan Harper (raharper) wrote :

vmtest says yes

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/curtin/commands/block_meta.py b/curtin/commands/block_meta.py
index f2bb8da..ff0f2e9 100644
--- a/curtin/commands/block_meta.py
+++ b/curtin/commands/block_meta.py
@@ -760,7 +760,9 @@ def verify_ptable_flag(devpath, expected_flag, sfdisk_info=None):
760 elif expected_flag == 'logical':760 elif expected_flag == 'logical':
761 (_parent, partnumber) = block.get_blockdev_for_partition(devpath)761 (_parent, partnumber) = block.get_blockdev_for_partition(devpath)
762 found_flag = 'logical' if int(partnumber) > 4 else None762 found_flag = 'logical' if int(partnumber) > 4 else None
763 else:763
764 # gpt and msdos primary partitions look up flag by entry['type']
765 if found_flag is None:
764 (found_flag, _code) = ptable_uuid_to_flag_entry(entry['type'])766 (found_flag, _code) = ptable_uuid_to_flag_entry(entry['type'])
765 msg = (767 msg = (
766 'Verifying %s partition flag, expecting %s, found %s' % (768 'Verifying %s partition flag, expecting %s, found %s' % (
diff --git a/curtin/storage_config.py b/curtin/storage_config.py
index e285f98..494b142 100644
--- a/curtin/storage_config.py
+++ b/curtin/storage_config.py
@@ -34,12 +34,13 @@ GPT_GUID_TO_CURTIN_MAP = {
34MBR_TYPE_TO_CURTIN_MAP = {34MBR_TYPE_TO_CURTIN_MAP = {
35 '0XF': ('extended', 'f'),35 '0XF': ('extended', 'f'),
36 '0X5': ('extended', 'f'),36 '0X5': ('extended', 'f'),
37 '0X80': ('boot', '80'),
38 '0X83': ('linux', '83'),37 '0X83': ('linux', '83'),
39 '0X85': ('extended', 'f'),38 '0X85': ('extended', 'f'),
40 '0XC5': ('extended', 'f'),39 '0XC5': ('extended', 'f'),
41}40}
4241
42MBR_BOOT_FLAG = '0x80'
43
43PTABLE_TYPE_MAP = dict(GPT_GUID_TO_CURTIN_MAP, **MBR_TYPE_TO_CURTIN_MAP)44PTABLE_TYPE_MAP = dict(GPT_GUID_TO_CURTIN_MAP, **MBR_TYPE_TO_CURTIN_MAP)
4445
45StorageConfig = namedtuple('StorageConfig', ('type', 'schema'))46StorageConfig = namedtuple('StorageConfig', ('type', 'schema'))
@@ -820,16 +821,20 @@ class BlockdevParser(ProbertParser):
820 entry['size'] *= 512821 entry['size'] *= 512
821822
822 ptype = blockdev_data.get('ID_PART_ENTRY_TYPE')823 ptype = blockdev_data.get('ID_PART_ENTRY_TYPE')
823 # use PART_ENTRY_FLAGS if set, msdos
824 ptype_flag = blockdev_data.get('ID_PART_ENTRY_FLAGS')
825 if ptype_flag:
826 ptype = ptype_flag
827 flag_name, _flag_code = ptable_uuid_to_flag_entry(ptype)824 flag_name, _flag_code = ptable_uuid_to_flag_entry(ptype)
828825
829 # logical partitions are not tagged in data, however826 if ptable and ptable.get('label') == 'dos':
830 # the partition number > 4 (ie, not primary nor extended)827 # if the boot flag is set, use this as the flag, logical
831 if ptable and ptable.get('label') == 'dos' and entry['number'] > 4:828 # flag is not required as we can determine logical via
832 flag_name = 'logical'829 # partition number
830 ptype_flag = blockdev_data.get('ID_PART_ENTRY_FLAGS')
831 if ptype_flag in [MBR_BOOT_FLAG]:
832 flag_name = 'boot'
833 else:
834 # logical partitions are not tagged in data, however
835 # the partition number > 4 (ie, not primary nor extended)
836 if entry['number'] > 4:
837 flag_name = 'logical'
833838
834 if flag_name:839 if flag_name:
835 entry['flag'] = flag_name840 entry['flag'] = flag_name
diff --git a/tests/data/probert_storage_msdos_mbr_extended_v2.json b/tests/data/probert_storage_msdos_mbr_extended_v2.json
836new file mode 100644841new file mode 100644
index 0000000..4719f44
--- /dev/null
+++ b/tests/data/probert_storage_msdos_mbr_extended_v2.json
@@ -0,0 +1,537 @@
1{
2 "dasd": {},
3 "raid": {},
4 "zfs": {
5 "zpools": {}
6 },
7 "bcache": {
8 "backing": {},
9 "caching": {}
10 },
11 "filesystem": {
12 "/dev/vdb1": {
13 "TYPE": "vfat",
14 "USAGE": "filesystem",
15 "UUID": "5EB4-6065",
16 "UUID_ENC": "5EB4-6065",
17 "VERSION": "FAT32"
18 },
19 "/dev/vdb5": {
20 "TYPE": "ext4",
21 "USAGE": "filesystem",
22 "UUID": "a55d4dc5-dacb-48af-b589-828ee55f5208",
23 "UUID_ENC": "a55d4dc5-dacb-48af-b589-828ee55f5208",
24 "VERSION": "1.0"
25 }
26 },
27 "dmcrypt": {},
28 "multipath": {},
29 "blockdev": {
30 "/dev/vda": {
31 "DEVLINKS": "/dev/disk/by-path/virtio-pci-0000:00:08.0 /dev/disk/by-path/pci-0000:00:08.0",
32 "DEVNAME": "/dev/vda",
33 "DEVPATH": "/devices/pci0000:00/0000:00:08.0/virtio2/block/vda",
34 "DEVTYPE": "disk",
35 "ID_PATH": "pci-0000:00:08.0",
36 "ID_PATH_TAG": "pci-0000_00_08_0",
37 "MAJOR": "252",
38 "MINOR": "0",
39 "SUBSYSTEM": "block",
40 "TAGS": ":systemd:",
41 "USEC_INITIALIZED": "1159634",
42 "attrs": {
43 "alignment_offset": "0",
44 "bdi": null,
45 "cache_type": "write back",
46 "capability": "50",
47 "dev": "252:0",
48 "device": null,
49 "discard_alignment": "0",
50 "events": "",
51 "events_async": "",
52 "events_poll_msecs": "-1",
53 "ext_range": "256",
54 "hidden": "0",
55 "inflight": " 0 0",
56 "range": "16",
57 "removable": "0",
58 "ro": "0",
59 "serial": "",
60 "size": "21474836480",
61 "stat": " 490 0 22696 179 0 0 0 0 0 176 64 0 0 0 0",
62 "subsystem": "block",
63 "uevent": "MAJOR=252\nMINOR=0\nDEVNAME=vda\nDEVTYPE=disk"
64 }
65 },
66 "/dev/vdb": {
67 "DEVLINKS": "/dev/disk/by-path/pci-0000:00:09.0 /dev/disk/by-path/virtio-pci-0000:00:09.0",
68 "DEVNAME": "/dev/vdb",
69 "DEVPATH": "/devices/pci0000:00/0000:00:09.0/virtio3/block/vdb",
70 "DEVTYPE": "disk",
71 "ID_PART_TABLE_TYPE": "dos",
72 "ID_PART_TABLE_UUID": "c72f0a19",
73 "ID_PATH": "pci-0000:00:09.0",
74 "ID_PATH_TAG": "pci-0000_00_09_0",
75 "MAJOR": "252",
76 "MINOR": "16",
77 "SUBSYSTEM": "block",
78 "TAGS": ":systemd:",
79 "USEC_INITIALIZED": "1133535",
80 "attrs": {
81 "alignment_offset": "0",
82 "bdi": null,
83 "cache_type": "write back",
84 "capability": "50",
85 "dev": "252:16",
86 "device": null,
87 "discard_alignment": "0",
88 "events": "",
89 "events_async": "",
90 "events_poll_msecs": "-1",
91 "ext_range": "256",
92 "hidden": "0",
93 "inflight": " 0 0",
94 "range": "16",
95 "removable": "0",
96 "ro": "0",
97 "serial": "",
98 "size": "10737418240",
99 "stat": " 609 0 39218 164 0 0 0 0 0 212 68 0 0 0 0",
100 "subsystem": "block",
101 "uevent": "MAJOR=252\nMINOR=16\nDEVNAME=vdb\nDEVTYPE=disk"
102 },
103 "partitiontable": {
104 "label": "dos",
105 "id": "0xc72f0a19",
106 "device": "/dev/vdb",
107 "unit": "sectors",
108 "partitions": [
109 {
110 "node": "/dev/vdb1",
111 "start": 2048,
112 "size": 1048576,
113 "type": "b",
114 "bootable": true
115 },
116 {
117 "node": "/dev/vdb2",
118 "start": 1052670,
119 "size": 19916802,
120 "type": "5"
121 },
122 {
123 "node": "/dev/vdb5",
124 "start": 1052672,
125 "size": 19916800,
126 "type": "83"
127 }
128 ]
129 }
130 },
131 "/dev/vdb1": {
132 "DEVLINKS": "/dev/disk/by-partuuid/c72f0a19-01 /dev/disk/by-uuid/5EB4-6065 /dev/disk/by-path/virtio-pci-0000:00:09.0-part1 /dev/disk/by-path/pci-0000:00:09.0-part1",
133 "DEVNAME": "/dev/vdb1",
134 "DEVPATH": "/devices/pci0000:00/0000:00:09.0/virtio3/block/vdb/vdb1",
135 "DEVTYPE": "partition",
136 "ID_FS_TYPE": "vfat",
137 "ID_FS_USAGE": "filesystem",
138 "ID_FS_UUID": "5EB4-6065",
139 "ID_FS_UUID_ENC": "5EB4-6065",
140 "ID_FS_VERSION": "FAT32",
141 "ID_PART_ENTRY_DISK": "252:16",
142 "ID_PART_ENTRY_FLAGS": "0x80",
143 "ID_PART_ENTRY_NUMBER": "1",
144 "ID_PART_ENTRY_OFFSET": "2048",
145 "ID_PART_ENTRY_SCHEME": "dos",
146 "ID_PART_ENTRY_SIZE": "1048576",
147 "ID_PART_ENTRY_TYPE": "0xb",
148 "ID_PART_ENTRY_UUID": "c72f0a19-01",
149 "ID_PART_TABLE_TYPE": "dos",
150 "ID_PART_TABLE_UUID": "c72f0a19",
151 "ID_PATH": "pci-0000:00:09.0",
152 "ID_PATH_TAG": "pci-0000_00_09_0",
153 "ID_SCSI": "1",
154 "MAJOR": "252",
155 "MINOR": "17",
156 "PARTN": "1",
157 "SUBSYSTEM": "block",
158 "TAGS": ":systemd:",
159 "USEC_INITIALIZED": "1161634",
160 "attrs": {
161 "alignment_offset": "0",
162 "dev": "252:17",
163 "discard_alignment": "0",
164 "inflight": " 0 0",
165 "partition": "1",
166 "ro": "0",
167 "size": "536870912",
168 "start": "2048",
169 "stat": " 200 0 14424 72 0 0 0 0 0 104 44 0 0 0 0",
170 "subsystem": "block",
171 "uevent": "MAJOR=252\nMINOR=17\nDEVNAME=vdb1\nDEVTYPE=partition\nPARTN=1"
172 },
173 "partitiontable": {
174 "label": "dos",
175 "id": "0x00000000",
176 "device": "/dev/vdb1",
177 "unit": "sectors",
178 "partitions": []
179 }
180 },
181 "/dev/vdb2": {
182 "DEVLINKS": "/dev/disk/by-path/pci-0000:00:09.0-part2 /dev/disk/by-path/virtio-pci-0000:00:09.0-part2 /dev/disk/by-partuuid/c72f0a19-02",
183 "DEVNAME": "/dev/vdb2",
184 "DEVPATH": "/devices/pci0000:00/0000:00:09.0/virtio3/block/vdb/vdb2",
185 "DEVTYPE": "partition",
186 "ID_PART_ENTRY_DISK": "252:16",
187 "ID_PART_ENTRY_NUMBER": "2",
188 "ID_PART_ENTRY_OFFSET": "1052670",
189 "ID_PART_ENTRY_SCHEME": "dos",
190 "ID_PART_ENTRY_SIZE": "19916802",
191 "ID_PART_ENTRY_TYPE": "0x5",
192 "ID_PART_ENTRY_UUID": "c72f0a19-02",
193 "ID_PART_TABLE_TYPE": "dos",
194 "ID_PART_TABLE_UUID": "e7ad4c09",
195 "ID_PATH": "pci-0000:00:09.0",
196 "ID_PATH_TAG": "pci-0000_00_09_0",
197 "ID_SCSI": "1",
198 "MAJOR": "252",
199 "MINOR": "18",
200 "PARTN": "2",
201 "SUBSYSTEM": "block",
202 "TAGS": ":systemd:",
203 "USEC_INITIALIZED": "1149403",
204 "attrs": {
205 "alignment_offset": "0",
206 "dev": "252:18",
207 "discard_alignment": "0",
208 "inflight": " 0 0",
209 "partition": "2",
210 "ro": "0",
211 "size": "1024",
212 "start": "1052670",
213 "stat": " 9 0 18 10 0 0 0 0 0 44 8 0 0 0 0",
214 "subsystem": "block",
215 "uevent": "MAJOR=252\nMINOR=18\nDEVNAME=vdb2\nDEVTYPE=partition\nPARTN=2"
216 },
217 "partitiontable": {
218 "label": "dos",
219 "id": "0xe7ad4c09",
220 "device": "/dev/vdb2",
221 "unit": "sectors",
222 "grain": "512",
223 "partitions": [
224 {
225 "node": "/dev/vdb2p1",
226 "start": 2,
227 "size": 19916800,
228 "type": "83"
229 }
230 ]
231 }
232 },
233 "/dev/vdb5": {
234 "DEVLINKS": "/dev/disk/by-uuid/a55d4dc5-dacb-48af-b589-828ee55f5208 /dev/disk/by-path/pci-0000:00:09.0-part5 /dev/disk/by-partuuid/c72f0a19-05 /dev/disk/by-path/virtio-pci-0000:00:09.0-part5",
235 "DEVNAME": "/dev/vdb5",
236 "DEVPATH": "/devices/pci0000:00/0000:00:09.0/virtio3/block/vdb/vdb5",
237 "DEVTYPE": "partition",
238 "ID_FS_TYPE": "ext4",
239 "ID_FS_USAGE": "filesystem",
240 "ID_FS_UUID": "a55d4dc5-dacb-48af-b589-828ee55f5208",
241 "ID_FS_UUID_ENC": "a55d4dc5-dacb-48af-b589-828ee55f5208",
242 "ID_FS_VERSION": "1.0",
243 "ID_PART_ENTRY_DISK": "252:16",
244 "ID_PART_ENTRY_NUMBER": "5",
245 "ID_PART_ENTRY_OFFSET": "1052672",
246 "ID_PART_ENTRY_SCHEME": "dos",
247 "ID_PART_ENTRY_SIZE": "19916800",
248 "ID_PART_ENTRY_TYPE": "0x83",
249 "ID_PART_ENTRY_UUID": "c72f0a19-05",
250 "ID_PART_TABLE_TYPE": "dos",
251 "ID_PART_TABLE_UUID": "c72f0a19",
252 "ID_PATH": "pci-0000:00:09.0",
253 "ID_PATH_TAG": "pci-0000_00_09_0",
254 "ID_SCSI": "1",
255 "MAJOR": "252",
256 "MINOR": "21",
257 "PARTN": "5",
258 "SUBSYSTEM": "block",
259 "TAGS": ":systemd:",
260 "USEC_INITIALIZED": "1155916",
261 "attrs": {
262 "alignment_offset": "0",
263 "dev": "252:21",
264 "discard_alignment": "0",
265 "inflight": " 0 0",
266 "partition": "5",
267 "ro": "0",
268 "size": "10197401600",
269 "start": "1052672",
270 "stat": " 202 0 14888 36 0 0 0 0 0 108 8 0 0 0 0",
271 "subsystem": "block",
272 "uevent": "MAJOR=252\nMINOR=21\nDEVNAME=vdb5\nDEVTYPE=partition\nPARTN=5"
273 }
274 }
275 },
276 "lvm": {},
277 "mount": [
278 {
279 "target": "/",
280 "source": "/cow",
281 "fstype": "overlay",
282 "options": "rw,relatime,lowerdir=/installer.squashfs:/filesystem.squashfs,upperdir=/cow/upper,workdir=/cow/work",
283 "children": [
284 {
285 "target": "/sys",
286 "source": "sysfs",
287 "fstype": "sysfs",
288 "options": "rw,nosuid,nodev,noexec,relatime",
289 "children": [
290 {
291 "target": "/sys/kernel/security",
292 "source": "securityfs",
293 "fstype": "securityfs",
294 "options": "rw,nosuid,nodev,noexec,relatime"
295 },
296 {
297 "target": "/sys/fs/cgroup",
298 "source": "tmpfs",
299 "fstype": "tmpfs",
300 "options": "ro,nosuid,nodev,noexec,mode=755",
301 "children": [
302 {
303 "target": "/sys/fs/cgroup/unified",
304 "source": "cgroup2",
305 "fstype": "cgroup2",
306 "options": "rw,nosuid,nodev,noexec,relatime,nsdelegate"
307 },
308 {
309 "target": "/sys/fs/cgroup/systemd",
310 "source": "cgroup",
311 "fstype": "cgroup",
312 "options": "rw,nosuid,nodev,noexec,relatime,xattr,name=systemd"
313 },
314 {
315 "target": "/sys/fs/cgroup/rdma",
316 "source": "cgroup",
317 "fstype": "cgroup",
318 "options": "rw,nosuid,nodev,noexec,relatime,rdma"
319 },
320 {
321 "target": "/sys/fs/cgroup/cpu,cpuacct",
322 "source": "cgroup",
323 "fstype": "cgroup",
324 "options": "rw,nosuid,nodev,noexec,relatime,cpu,cpuacct"
325 },
326 {
327 "target": "/sys/fs/cgroup/net_cls,net_prio",
328 "source": "cgroup",
329 "fstype": "cgroup",
330 "options": "rw,nosuid,nodev,noexec,relatime,net_cls,net_prio"
331 },
332 {
333 "target": "/sys/fs/cgroup/hugetlb",
334 "source": "cgroup",
335 "fstype": "cgroup",
336 "options": "rw,nosuid,nodev,noexec,relatime,hugetlb"
337 },
338 {
339 "target": "/sys/fs/cgroup/pids",
340 "source": "cgroup",
341 "fstype": "cgroup",
342 "options": "rw,nosuid,nodev,noexec,relatime,pids"
343 },
344 {
345 "target": "/sys/fs/cgroup/blkio",
346 "source": "cgroup",
347 "fstype": "cgroup",
348 "options": "rw,nosuid,nodev,noexec,relatime,blkio"
349 },
350 {
351 "target": "/sys/fs/cgroup/memory",
352 "source": "cgroup",
353 "fstype": "cgroup",
354 "options": "rw,nosuid,nodev,noexec,relatime,memory"
355 },
356 {
357 "target": "/sys/fs/cgroup/cpuset",
358 "source": "cgroup",
359 "fstype": "cgroup",
360 "options": "rw,nosuid,nodev,noexec,relatime,cpuset"
361 },
362 {
363 "target": "/sys/fs/cgroup/freezer",
364 "source": "cgroup",
365 "fstype": "cgroup",
366 "options": "rw,nosuid,nodev,noexec,relatime,freezer"
367 },
368 {
369 "target": "/sys/fs/cgroup/devices",
370 "source": "cgroup",
371 "fstype": "cgroup",
372 "options": "rw,nosuid,nodev,noexec,relatime,devices"
373 },
374 {
375 "target": "/sys/fs/cgroup/perf_event",
376 "source": "cgroup",
377 "fstype": "cgroup",
378 "options": "rw,nosuid,nodev,noexec,relatime,perf_event"
379 }
380 ]
381 },
382 {
383 "target": "/sys/fs/pstore",
384 "source": "pstore",
385 "fstype": "pstore",
386 "options": "rw,nosuid,nodev,noexec,relatime"
387 },
388 {
389 "target": "/sys/firmware/efi/efivars",
390 "source": "efivarfs",
391 "fstype": "efivarfs",
392 "options": "rw,nosuid,nodev,noexec,relatime"
393 },
394 {
395 "target": "/sys/fs/bpf",
396 "source": "none",
397 "fstype": "bpf",
398 "options": "rw,nosuid,nodev,noexec,relatime,mode=700"
399 },
400 {
401 "target": "/sys/kernel/debug",
402 "source": "debugfs",
403 "fstype": "debugfs",
404 "options": "rw,nosuid,nodev,noexec,relatime"
405 },
406 {
407 "target": "/sys/kernel/tracing",
408 "source": "tracefs",
409 "fstype": "tracefs",
410 "options": "rw,nosuid,nodev,noexec,relatime"
411 },
412 {
413 "target": "/sys/fs/fuse/connections",
414 "source": "fusectl",
415 "fstype": "fusectl",
416 "options": "rw,nosuid,nodev,noexec,relatime"
417 },
418 {
419 "target": "/sys/kernel/config",
420 "source": "configfs",
421 "fstype": "configfs",
422 "options": "rw,nosuid,nodev,noexec,relatime"
423 }
424 ]
425 },
426 {
427 "target": "/proc",
428 "source": "proc",
429 "fstype": "proc",
430 "options": "rw,nosuid,nodev,noexec,relatime",
431 "children": [
432 {
433 "target": "/proc/sys/fs/binfmt_misc",
434 "source": "systemd-1",
435 "fstype": "autofs",
436 "options": "rw,relatime,fd=28,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=18206"
437 }
438 ]
439 },
440 {
441 "target": "/dev",
442 "source": "udev",
443 "fstype": "devtmpfs",
444 "options": "rw,nosuid,noexec,relatime,size=1969872k,nr_inodes=492468,mode=755",
445 "children": [
446 {
447 "target": "/dev/pts",
448 "source": "devpts",
449 "fstype": "devpts",
450 "options": "rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000"
451 },
452 {
453 "target": "/dev/shm",
454 "source": "tmpfs",
455 "fstype": "tmpfs",
456 "options": "rw,nosuid,nodev"
457 },
458 {
459 "target": "/dev/mqueue",
460 "source": "mqueue",
461 "fstype": "mqueue",
462 "options": "rw,nosuid,nodev,noexec,relatime"
463 },
464 {
465 "target": "/dev/hugepages",
466 "source": "hugetlbfs",
467 "fstype": "hugetlbfs",
468 "options": "rw,relatime,pagesize=2M"
469 }
470 ]
471 },
472 {
473 "target": "/run",
474 "source": "tmpfs",
475 "fstype": "tmpfs",
476 "options": "rw,nosuid,nodev,noexec,relatime,size=402820k,mode=755",
477 "children": [
478 {
479 "target": "/run/lock",
480 "source": "tmpfs",
481 "fstype": "tmpfs",
482 "options": "rw,nosuid,nodev,noexec,relatime,size=5120k"
483 }
484 ]
485 },
486 {
487 "target": "/cdrom",
488 "source": "/dev/loop0",
489 "fstype": "iso9660",
490 "options": "ro,relatime,nojoliet,check=s,map=n,blocksize=2048"
491 },
492 {
493 "target": "/rofs",
494 "source": "/dev/loop1",
495 "fstype": "squashfs",
496 "options": "ro,noatime"
497 },
498 {
499 "target": "/usr/lib/modules",
500 "source": "/dev/loop3",
501 "fstype": "squashfs",
502 "options": "ro,relatime"
503 },
504 {
505 "target": "/media/filesystem",
506 "source": "/dev/loop1",
507 "fstype": "squashfs",
508 "options": "ro,relatime"
509 },
510 {
511 "target": "/tmp",
512 "source": "tmpfs",
513 "fstype": "tmpfs",
514 "options": "rw,nosuid,nodev,relatime"
515 },
516 {
517 "target": "/snap/core/8935",
518 "source": "/dev/loop4",
519 "fstype": "squashfs",
520 "options": "ro,nodev,relatime"
521 },
522 {
523 "target": "/snap/subiquity/1626",
524 "source": "/dev/loop5",
525 "fstype": "squashfs",
526 "options": "ro,nodev,relatime"
527 },
528 {
529 "target": "/snap/subiquity/1632",
530 "source": "/dev/loop6",
531 "fstype": "squashfs",
532 "options": "ro,nodev,relatime"
533 }
534 ]
535 }
536 ]
537}
diff --git a/tests/unittests/test_commands_block_meta.py b/tests/unittests/test_commands_block_meta.py
index 4cc9299..b768cdc 100644
--- a/tests/unittests/test_commands_block_meta.py
+++ b/tests/unittests/test_commands_block_meta.py
@@ -2446,4 +2446,115 @@ class TestVerifySize(CiTestCase):
2446 self.devpath = self.random_string()2446 self.devpath = self.random_string()
24472447
24482448
2449class TestVerifyPtableFlag(CiTestCase):
2450
2451 def setUp(self):
2452 super(TestVerifyPtableFlag, self).setUp()
2453 base = 'curtin.commands.block_meta.'
2454 self.add_patch(base + 'block.sfdisk_info', 'm_block_sfdisk_info')
2455 self.add_patch(base + 'block.get_blockdev_for_partition',
2456 'm_block_get_blockdev_for_partition')
2457 self.sfdisk_info_dos = {
2458 "label": "dos",
2459 "id": "0xb0dbdde1",
2460 "device": "/dev/vdb",
2461 "unit": "sectors",
2462 "partitions": [
2463 {"node": "/dev/vdb1", "start": 2048, "size": 8388608,
2464 "type": "83", "bootable": True},
2465 {"node": "/dev/vdb2", "start": 8390656, "size": 8388608,
2466 "type": "83"},
2467 {"node": "/dev/vdb3", "start": 16779264, "size": 62914560,
2468 "type": "85"},
2469 {"node": "/dev/vdb5", "start": 16781312, "size": 31457280,
2470 "type": "83"},
2471 {"node": "/dev/vdb6", "start": 48240640, "size": 10485760,
2472 "type": "83"},
2473 {"node": "/dev/vdb7", "start": 58728448, "size": 20965376,
2474 "type": "83"}]}
2475 self.sfdisk_info_gpt = {
2476 "label": "gpt",
2477 "id": "AEA37E20-8E52-4B37-BDFD-9946A352A37B",
2478 "device": "/dev/vda",
2479 "unit": "sectors",
2480 "firstlba": 34,
2481 "lastlba": 41943006,
2482 "partitions": [
2483 {"node": "/dev/vda1", "start": 227328, "size": 41715679,
2484 "type": "0FC63DAF-8483-4772-8E79-3D69D8477DE4",
2485 "uuid": "42C72DE9-FF5E-4CD6-A4C8-283685DEB1D5"},
2486 {"node": "/dev/vda14", "start": 2048, "size": 8192,
2487 "type": "21686148-6449-6E6F-744E-656564454649",
2488 "uuid": "762F070A-122A-4EB8-90BF-2CA6E9171B01"},
2489 {"node": "/dev/vda15", "start": 10240, "size": 217088,
2490 "type": "C12A7328-F81F-11D2-BA4B-00A0C93EC93B",
2491 "uuid": "789133C6-8579-4792-9D61-FC9A7BEC2A15"}]}
2492
2493 def test_verify_ptable_flag_finds_boot_on_gpt(self):
2494 devpath = '/dev/vda15'
2495 expected_flag = 'boot'
2496 block_meta.verify_ptable_flag(devpath, expected_flag,
2497 sfdisk_info=self.sfdisk_info_gpt)
2498
2499 def test_verify_ptable_flag_raises_exception_missing_flag(self):
2500 devpath = '/dev/vda1'
2501 expected_flag = 'boot'
2502 with self.assertRaises(RuntimeError):
2503 block_meta.verify_ptable_flag(devpath, expected_flag,
2504 sfdisk_info=self.sfdisk_info_gpt)
2505
2506 def test_verify_ptable_flag_raises_exception_invalid_flag(self):
2507 devpath = '/dev/vda1'
2508 expected_flag = self.random_string()
2509 self.assertNotIn(expected_flag, block_meta.SGDISK_FLAGS.keys())
2510 self.assertNotIn(expected_flag, block_meta.MSDOS_FLAGS.keys())
2511 with self.assertRaises(RuntimeError):
2512 block_meta.verify_ptable_flag(devpath, expected_flag,
2513 sfdisk_info=self.sfdisk_info_gpt)
2514
2515 def test_verify_ptable_flag_checks_bootable_not_table_type(self):
2516 devpath = '/dev/vdb1'
2517 expected_flag = 'boot'
2518 del self.sfdisk_info_dos['partitions'][0]['bootable']
2519 self.sfdisk_info_dos['partitions'][0]['type'] = '0x80'
2520 with self.assertRaises(RuntimeError):
2521 block_meta.verify_ptable_flag(devpath, expected_flag,
2522 sfdisk_info=self.sfdisk_info_dos)
2523
2524 def test_verify_ptable_flag_calls_block_sfdisk_if_info_none(self):
2525 devpath = '/dev/vda15'
2526 expected_flag = 'boot'
2527 self.m_block_sfdisk_info.return_value = self.sfdisk_info_gpt
2528 block_meta.verify_ptable_flag(devpath, expected_flag, sfdisk_info=None)
2529 self.assertEqual(
2530 [call(devpath)],
2531 self.m_block_sfdisk_info.call_args_list)
2532
2533 def test_verify_ptable_flag_finds_boot_on_msdos(self):
2534 devpath = '/dev/vdb1'
2535 expected_flag = 'boot'
2536 block_meta.verify_ptable_flag(devpath, expected_flag,
2537 sfdisk_info=self.sfdisk_info_dos)
2538
2539 def test_verify_ptable_flag_finds_linux_on_dos_primary_partition(self):
2540 devpath = '/dev/vdb2'
2541 expected_flag = 'linux'
2542 block_meta.verify_ptable_flag(devpath, expected_flag,
2543 sfdisk_info=self.sfdisk_info_dos)
2544
2545 def test_verify_ptable_flag_finds_dos_extended_partition(self):
2546 devpath = '/dev/vdb3'
2547 expected_flag = 'extended'
2548 block_meta.verify_ptable_flag(devpath, expected_flag,
2549 sfdisk_info=self.sfdisk_info_dos)
2550
2551 def test_verify_ptable_flag_finds_dos_logical_partition(self):
2552 devpath = '/dev/vdb5'
2553 expected_flag = 'logical'
2554 self.m_block_get_blockdev_for_partition.return_value = (
2555 ('/dev/vdb', '5'))
2556 block_meta.verify_ptable_flag(devpath, expected_flag,
2557 sfdisk_info=self.sfdisk_info_dos)
2558
2559
2449# vi: ts=4 expandtab syntax=python2560# vi: ts=4 expandtab syntax=python
diff --git a/tests/unittests/test_storage_config.py b/tests/unittests/test_storage_config.py
index ecdc565..a38f9cd 100644
--- a/tests/unittests/test_storage_config.py
+++ b/tests/unittests/test_storage_config.py
@@ -405,6 +405,40 @@ class TestBlockdevParser(CiTestCase):
405 self.assertDictEqual(expected_dict,405 self.assertDictEqual(expected_dict,
406 self.bdevp.asdict(blockdev))406 self.bdevp.asdict(blockdev))
407407
408 def test_blockdev_detects_dos_bootable_flag(self):
409 self.probe_data = _get_data(
410 'probert_storage_msdos_mbr_extended_v2.json')
411 self.bdevp = BlockdevParser(self.probe_data)
412 blockdev = self.bdevp.blockdev_data['/dev/vdb1']
413 expected_dict = {
414 'id': 'partition-vdb1',
415 'type': 'partition',
416 'device': 'disk-vdb',
417 'number': 1,
418 'offset': 1048576,
419 'size': 536870912,
420 'flag': 'boot',
421 }
422 self.assertDictEqual(expected_dict,
423 self.bdevp.asdict(blockdev))
424
425 def test_blockdev_detects_dos_bootable_flag_on_logical_partitions(self):
426 self.probe_data = _get_data('probert_storage_lvm.json')
427 self.bdevp = BlockdevParser(self.probe_data)
428 blockdev = self.bdevp.blockdev_data['/dev/vda5']
429 blockdev['ID_PART_ENTRY_FLAGS'] = '0x80'
430 expected_dict = {
431 'id': 'partition-vda5',
432 'type': 'partition',
433 'device': 'disk-vda',
434 'number': 5,
435 'offset': 3223322624,
436 'size': 2147483648,
437 'flag': 'boot',
438 }
439 self.assertDictEqual(expected_dict,
440 self.bdevp.asdict(blockdev))
441
408 def test_blockdev_asdict_disk_omits_ptable_if_none_present(self):442 def test_blockdev_asdict_disk_omits_ptable_if_none_present(self):
409 blockdev = self.bdevp.blockdev_data['/dev/sda']443 blockdev = self.bdevp.blockdev_data['/dev/sda']
410 del blockdev['ID_PART_TABLE_TYPE']444 del blockdev['ID_PART_TABLE_TYPE']

Subscribers

People subscribed via source and target branches