Merge ~ltrager/curtin:lp1895067 into curtin:master

Proposed by Lee Trager
Status: Merged
Approved by: Chad Smith
Approved revision: 840b8ae4e3743c8b0f652f5bb207d9e9082d43e8
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~ltrager/curtin:lp1895067
Merge into: curtin:master
Diff against target: 81 lines (+54/-6)
2 files modified
curtin/commands/install_grub.py (+13/-6)
tests/unittests/test_commands_install_grub.py (+41/-0)
Reviewer Review Type Date Requested Status
Chad Smith Approve
Server Team CI bot continuous-integration Approve
Ryan Harper (community) Approve
Review via email: mp+390517@code.launchpad.net

Commit message

Don't install grub if it is already found on CentOS/RHEL

LP: #1895067

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
Ryan Harper (raharper) :
review: Needs Fixing
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

ltrager any further updates on this? or should someone else pick this up?

Revision history for this message
Lee Trager (ltrager) wrote :

Sorry for taking so long I was investing another issue I thought was related and got caught up with other things. Updated as suggested and verified.

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

Thanks, LGTM

review: Approve
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Chad Smith (chad.smith) wrote :

LGTM. Review comments addressed, logic addresses the bug.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/curtin/commands/install_grub.py b/curtin/commands/install_grub.py
2index 5f8311f..030087c 100644
3--- a/curtin/commands/install_grub.py
4+++ b/curtin/commands/install_grub.py
5@@ -254,12 +254,19 @@ def gen_uefi_install_commands(grub_name, grub_target, grub_cmd, update_nvram,
6 install_cmds.append(['update-grub'])
7 elif distroinfo.family == distro.DISTROS.redhat:
8 loader = find_efi_loader(target, bootid)
9- if loader and update_nvram:
10- grub_cmd = None # don't install just add entry
11- efi_disk, efi_part_num = get_efi_disk_part(devices)
12- install_cmds.append(['efibootmgr', '--create', '--write-signature',
13- '--label', bootid, '--disk', efi_disk,
14- '--part', efi_part_num, '--loader', loader])
15+ if loader:
16+ # Disable running grub's install command. CentOS/RHEL ships
17+ # a pre-built signed grub which installs into /boot. grub2-install
18+ # will generated a new unsigned grub which breaks UEFI secure boot.
19+ grub_cmd = None
20+ if update_nvram:
21+ efi_disk, efi_part_num = get_efi_disk_part(devices)
22+ # Add entry to the EFI boot menu
23+ install_cmds.append(['efibootmgr', '--create',
24+ '--write-signature', '--label', bootid,
25+ '--disk', efi_disk,
26+ '--part', efi_part_num,
27+ '--loader', loader])
28 post_cmds.append(['grub2-mkconfig', '-o',
29 '/boot/efi/EFI/%s/grub.cfg' % bootid])
30 else:
31diff --git a/tests/unittests/test_commands_install_grub.py b/tests/unittests/test_commands_install_grub.py
32index 8808159..b1d132e 100644
33--- a/tests/unittests/test_commands_install_grub.py
34+++ b/tests/unittests/test_commands_install_grub.py
35@@ -774,6 +774,47 @@ class TestGenUefiInstallCommands(CiTestCase):
36 grub_name, grub_target, grub_cmd, update_nvram, distroinfo,
37 devices, self.target))
38
39+ def test_redhat_install_existing_no_nvram(self):
40+ # verify grub install command is not executed if update_nvram is False
41+ # on redhat.
42+ def _enable_loaders(bootid):
43+ efi_path = 'boot/efi/EFI'
44+ target_efi_path = os.path.join(self.target, efi_path)
45+ loaders = [
46+ os.path.join(target_efi_path, bootid, 'shimx64.efi'),
47+ os.path.join(target_efi_path, 'BOOT', 'BOOTX64.EFI'),
48+ os.path.join(target_efi_path, bootid, 'grubx64.efi'),
49+ ]
50+ for loader in loaders:
51+ util.write_file(loader, content="")
52+
53+ self.m_os_release.return_value = {'ID': 'redhat'}
54+ distroinfo = install_grub.distro.get_distroinfo()
55+ bootid = distroinfo.variant
56+ _enable_loaders(bootid)
57+ grub_name = 'grub2-efi-x64'
58+ grub_target = 'x86_64-efi'
59+ grub_cmd = 'grub2-install'
60+ update_nvram = False
61+ devices = ['/dev/disk-a-part1']
62+ disk = '/dev/disk-a'
63+ part = '1'
64+ self.m_get_disk_part.return_value = (disk, part)
65+
66+ expected_install = [
67+ ['efibootmgr', '-v'],
68+ ]
69+ expected_post = [
70+ ['grub2-mkconfig', '-o', '/boot/efi/EFI/%s/grub.cfg' % bootid],
71+ ['efibootmgr', '-v']
72+ ]
73+
74+ self.assertEqual(
75+ (expected_install, expected_post),
76+ install_grub.gen_uefi_install_commands(
77+ grub_name, grub_target, grub_cmd, update_nvram, distroinfo,
78+ devices, self.target))
79+
80
81 class TestGenInstallCommands(CiTestCase):
82

Subscribers

People subscribed via source and target branches