Skip to content

Commit e10f052

Browse files
committed
Fix UEFI record regex
I accidently put colons on the test data and remembered taking the colon character out of the regex I was working on, but apparently left it in, and accounted for the active entry indicator flag which appears to have inconsistent support across vendors. The regex has been fixed, and a test added from a Lenovo SR650 which has some additional string entry data in the UEFI output which may separate entries. Change-Id: I1f67b0fb1f645fa82e98bd7c7bba3ffc7755cc74
1 parent 33b3970 commit e10f052

File tree

3 files changed

+75
-6
lines changed

3 files changed

+75
-6
lines changed

ironic_python_agent/extensions/image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def _run_efibootmgr(valid_efi_bootloaders, device, efi_partition,
277277
original_efi_output = utils.execute('efibootmgr', '-v')
278278
# NOTE(TheJulia): regex used to identify entries in the efibootmgr
279279
# output on stdout.
280-
entry_label = re.compile(r'Boot([0-9a-f-A-F]+):\s(.*).*$')
280+
entry_label = re.compile(r'Boot([0-9a-f-A-F]+)\*?\s(.*).*$')
281281
label_id = 1
282282
for v_bl in valid_efi_bootloaders:
283283
if 'csv' in v_bl.lower():

ironic_python_agent/tests/unit/extensions/test_image.py

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,9 @@ def test__uefi_bootloader_with_entry_removal(
323323
BootCurrent: 0001
324324
Timeout: 0 seconds
325325
BootOrder: 0000,00001
326-
Boot0000: ironic1 HD(1, GPT,4f3c6294-bf9b-4208-9808-be45dfc34b5c)File(\EFI\Boot\BOOTX64.EFI)
327-
Boot0001: ironic2 HD(1, GPT,4f3c6294-bf9b-4208-9808-111111111112)File(\EFI\Boot\BOOTX64.EFI)
328-
Boot0002: VENDMAGIC FvFile(9f3c6294-bf9b-4208-9808-be45dfc34b51)
326+
Boot0000 ironic1 HD(1,GPT,4f3c6294-bf9b-4208-9808-be45dfc34b5c)File(\EFI\Boot\BOOTX64.EFI)
327+
Boot0001 ironic2 HD(1,GPT,4f3c6294-bf9b-4208-9808-111111111112)File(\EFI\Boot\BOOTX64.EFI)
328+
Boot0002 VENDMAGIC FvFile(9f3c6294-bf9b-4208-9808-be45dfc34b51)
329329
""" # noqa This is a giant literal string for testing.
330330
mock_execute.side_effect = iter([('', ''), ('', ''),
331331
('', ''), ('', ''),
@@ -361,6 +361,68 @@ def test__uefi_bootloader_with_entry_removal(
361361
mock_utils_efi_part.assert_called_once_with(self.fake_dev)
362362
self.assertEqual(9, mock_execute.call_count)
363363

364+
@mock.patch.object(hardware, 'is_md_device', lambda *_: False)
365+
@mock.patch.object(os.path, 'exists', lambda *_: False)
366+
@mock.patch.object(image, '_get_efi_bootloaders', autospec=True)
367+
@mock.patch.object(image, '_get_partition', autospec=True)
368+
@mock.patch.object(utils, 'get_efi_part_on_device', autospec=True)
369+
@mock.patch.object(os, 'makedirs', autospec=True)
370+
def test__uefi_bootloader_with_entry_removal_lenovo(
371+
self, mkdir_mock, mock_utils_efi_part, mock_partition,
372+
mock_efi_bl, mock_execute, mock_dispatch):
373+
mock_dispatch.side_effect = [
374+
self.fake_dev, hardware.BootInfo(current_boot_mode='uefi')
375+
]
376+
mock_partition.return_value = self.fake_dev
377+
mock_utils_efi_part.return_value = '1'
378+
mock_efi_bl.return_value = ['EFI/BOOT/BOOTX64.EFI']
379+
# NOTE(TheJulia): This test string was derived from a lenovo SR650
380+
# which does do some weird things with additional entries.
381+
# most notabley
382+
stdout_msg = """
383+
BootCurrent: 0000
384+
Timeout: 1 seconds
385+
BootOrder: 0000,0003,0002,0001
386+
Boot0000* ironic1 HD(1,GPT,55db8d03-c8f6-4a5b-9155-790dddc348fa,0x800,0x64000)/File(\EFI\boot\shimx64.efi)
387+
Boot0001* CD/DVD Rom VenHw(1fad3248-0000-7950-2166-a1e506fdb83a,02000000)..GO
388+
Boot0002* Hard Disk VenHw(1fad3248-0000-7950-2166-a1e506fdb83a,01000000)..GO..NO..........V.U.E.F.I.:. . . .S.C.S.I. .H.a.r.d. .D.r.i.v.e........A....................................*[email protected]..[J.Uy...H.......BO
389+
Boot0003* Network VenHw(1fad3248-0000-7950-2166-a1e506fdb83a,05000000)..GO..NO............U.E.F.I.:. . . .S.L.O.T.2. .(.2.F./.0./.0.). .P.X.E. .I.P.4. . .Q.L.o.g.i.c. .Q.L.4.1.2.6.2. .P.C.I.e. .2.5.G.b. .2.-.P.o.r.t. .S.F.P.2.8. .E.t.h.e.r.n.e.t. .A.d.a.p.t.e.r. .-. .P.X.E........A....................%.4..Z...............................................................Gd-.;.A..MQ..L.P.X.E. .I.P.4. .Q.L.o.g.i.c. .Q.L.4.1.2.6.2. .P.C.I.e. .2.5.G.b. .2.-.P.o.r.t. .S.F.P.2.8. .E.t.h.e.r.n.e.t. .A.d.a.p.t.e.r. .-. .P.X.E.......BO..NO............U.E.F.I.:. . . .S.L.O.T.1. .(.3.0./.0./.0.). .P.X.E. .I.P.4. . .Q.L.o.g.i.c. .Q.L.4.1.2.6.2. .P.C.I.e. .2.5.G.b. .2.-.P.o.r.t. .S.F.P.2.8. .E.t.h.e.r.n.e.t. .A.d.a.p.t.e.r. .-.
390+
Boot0004* ironic1 HD(1,GPT,55db8d03-c8f6-4a5b-9155-790dddc348fa,0x800,0x64000)/File(\EFI\boot\shimx64.efi)
391+
""" # noqa This is a giant literal string for testing.
392+
mock_execute.side_effect = iter([('', ''), ('', ''),
393+
('', ''), ('', ''),
394+
(stdout_msg, ''), ('', ''),
395+
('', ''), ('', ''),
396+
('', ''), ('', '')])
397+
expected = [mock.call('efibootmgr', '--version'),
398+
mock.call('partx', '-u', '/dev/fake', attempts=3,
399+
delay_on_retry=True),
400+
mock.call('udevadm', 'settle'),
401+
mock.call('mount', self.fake_efi_system_part,
402+
self.fake_dir + '/boot/efi'),
403+
mock.call('efibootmgr', '-v'),
404+
mock.call('efibootmgr', '-b', '0000', '-B'),
405+
mock.call('efibootmgr', '-b', '0004', '-B'),
406+
mock.call('efibootmgr', '-v', '-c', '-d', self.fake_dev,
407+
'-p', '1', '-w',
408+
'-L', 'ironic1', '-l',
409+
'\\EFI\\BOOT\\BOOTX64.EFI'),
410+
mock.call('umount', self.fake_dir + '/boot/efi',
411+
attempts=3, delay_on_retry=True),
412+
mock.call('sync')]
413+
414+
self.agent_extension.install_bootloader(
415+
root_uuid=self.fake_root_uuid,
416+
efi_system_part_uuid=None).join()
417+
418+
mock_dispatch.assert_any_call('get_os_install_device')
419+
mock_dispatch.assert_any_call('get_boot_info')
420+
mkdir_mock.assert_called_once_with(self.fake_dir + '/boot/efi')
421+
mock_efi_bl.assert_called_once_with(self.fake_dir + '/boot/efi')
422+
mock_execute.assert_has_calls(expected)
423+
mock_utils_efi_part.assert_called_once_with(self.fake_dev)
424+
self.assertEqual(10, mock_execute.call_count)
425+
364426
@mock.patch.object(hardware, 'is_md_device', lambda *_: False)
365427
@mock.patch.object(os.path, 'exists', lambda *_: False)
366428
@mock.patch.object(image, '_get_efi_bootloaders', autospec=True)
@@ -2268,8 +2330,8 @@ def test__manage_uefi_found_csv(self, mkdir_mock, mock_utils_efi_part,
22682330
BootCurrent: 0001
22692331
Timeout: 0 seconds
22702332
BootOrder: 0000,00001
2271-
Boot0000: Vendor String HD(1, GPT,4f3c6294-bf9b-4208-9808-be45dfc34b5c)File(\EFI\Boot\BOOTX64.EFI)
2272-
Boot0001: Vendor String HD(2, GPT,4f3c6294-bf9b-4208-9808-be45dfc34b5c)File(\EFI\Boot\BOOTX64.EFI)
2333+
Boot0000* Vendor String HD(1,GPT,4f3c6294-bf9b-4208-9808-be45dfc34b5c)File(\EFI\Boot\BOOTX64.EFI)
2334+
Boot0001 Vendor String HD(2,GPT,4f3c6294-bf9b-4208-9808-be45dfc34b5c)File(\EFI\Boot\BOOTX64.EFI)
22732335
Boot0002: VENDMAGIC FvFile(9f3c6294-bf9b-4208-9808-be45dfc34b51)
22742336
""" # noqa This is a giant literal string for testing.
22752337

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
fixes:
3+
- |
4+
Fixes a minor issue with the regular expression used for UEFI duplicate
5+
entry cleanup which was introduced in a prior change to refactor the
6+
cleanup operation to avoid UEFI firmware which treats deletion of
7+
entries after addition as an invalid operation.

0 commit comments

Comments
 (0)