-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Grub on component drives if /boot is on md device
On BIOS systems, previously, if /boot was on md device such as RAID consisting of multiple partitions on different MBR/GPT partitioned drives, the part of Grub residing in the 512 Mb after MBR was only updated for one of the drives. Similar situation occurred on GPT partitioned drives and the BIOS boot partition. This resulted in outdated GRUB on the remaining drives which could cause the system to be unbootable. Now, Grub is updated on all the component devices of an md array if Grub was already installed on them before the upgrade. Jira: OAMG-7835 BZ#2219544 BZ#2140011
- Loading branch information
1 parent
030e1fc
commit c7b1e75
Showing
12 changed files
with
358 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
repos/system_upgrade/common/actors/scangrubdevice/tests/test_scangrubdevice.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from leapp.libraries.common import grub | ||
from leapp.libraries.common.config import mock_configs | ||
from leapp.models import GrubInfo | ||
|
||
|
||
def _get_grub_devices_mocked(): | ||
return ['/dev/vda', '/dev/vdb'] | ||
|
||
|
||
def test_actor_scan_grub_device(current_actor_context, monkeypatch): | ||
monkeypatch.setattr(grub, 'get_grub_devices', _get_grub_devices_mocked) | ||
current_actor_context.run(config_model=mock_configs.CONFIG) | ||
info = current_actor_context.consume(GrubInfo) | ||
assert info and info[0].orig_devices == ['/dev/vda', '/dev/vdb'] | ||
assert len(info) == 1, 'Expected just one GrubInfo message' | ||
assert not info[0].orig_device_name | ||
|
||
|
||
def test_actor_scan_grub_device_one(current_actor_context, monkeypatch): | ||
|
||
def _get_grub_devices_mocked(): | ||
return ['/dev/vda'] | ||
|
||
monkeypatch.setattr(grub, 'get_grub_devices', _get_grub_devices_mocked) | ||
current_actor_context.run(config_model=mock_configs.CONFIG) | ||
info = current_actor_context.consume(GrubInfo) | ||
assert info and info[0].orig_devices == ['/dev/vda'] | ||
assert len(info) == 1, 'Expected just one GrubInfo message' | ||
assert info[0].orig_device_name == '/dev/vda' | ||
|
||
|
||
def test_actor_scan_grub_device_s390x(current_actor_context, monkeypatch): | ||
monkeypatch.setattr(grub, 'get_grub_devices', _get_grub_devices_mocked) | ||
current_actor_context.run(config_model=mock_configs.CONFIG_S390X) | ||
assert not current_actor_context.consume(GrubInfo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 28 additions & 20 deletions
48
repos/system_upgrade/common/actors/updategrubcore/libraries/updategrubcore.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,43 @@ | ||
from leapp import reporting | ||
from leapp.exceptions import StopActorExecution | ||
from leapp.libraries.stdlib import api, CalledProcessError, config, run | ||
|
||
|
||
def update_grub_core(grub_dev): | ||
def update_grub_core(grub_devs): | ||
""" | ||
Update GRUB core after upgrade from RHEL7 to RHEL8 | ||
On legacy systems, GRUB core does not get automatically updated when GRUB packages | ||
are updated. | ||
""" | ||
cmd = ['grub2-install', grub_dev] | ||
if config.is_debug(): | ||
cmd += ['-v'] | ||
try: | ||
run(cmd) | ||
except CalledProcessError as err: | ||
reporting.create_report([ | ||
reporting.Title('GRUB core update failed'), | ||
reporting.Summary(str(err)), | ||
reporting.Groups([reporting.Groups.BOOT]), | ||
reporting.Severity(reporting.Severity.HIGH), | ||
reporting.Remediation( | ||
hint='Please run "grub2-install <GRUB_DEVICE>" manually after upgrade' | ||
) | ||
]) | ||
api.current_logger().warning('GRUB core update on {} failed'.format(grub_dev)) | ||
raise StopActorExecution() | ||
|
||
successful = [] | ||
failed = [] | ||
for dev in grub_devs: | ||
cmd = ['grub2-install', dev] | ||
if config.is_debug(): | ||
cmd += ['-v'] | ||
try: | ||
run(cmd) | ||
except CalledProcessError as err: | ||
api.current_logger().warning('GRUB core update on {} failed: {}'.format(dev, err)) | ||
failed.append(dev) | ||
continue | ||
|
||
successful.append(dev) | ||
|
||
reporting.create_report([ | ||
reporting.Title('GRUB core update failed'), | ||
reporting.Summary('Leapp failed to update GRUB on {}'.format(', '.join(failed))), | ||
reporting.Groups([reporting.Groups.BOOT]), | ||
reporting.Severity(reporting.Severity.HIGH), | ||
reporting.Remediation( | ||
hint='Please run "grub2-install <GRUB_DEVICE>" manually after upgrade' | ||
) | ||
]) | ||
|
||
reporting.create_report([ | ||
reporting.Title('GRUB core successfully updated'), | ||
reporting.Summary('GRUB core on {} was successfully updated'.format(grub_dev)), | ||
reporting.Summary('GRUB core on {} was successfully updated'.format(', '.join(successful))), | ||
reporting.Groups([reporting.Groups.BOOT]), | ||
reporting.Severity(reporting.Severity.INFO) | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from leapp.libraries.stdlib import api, CalledProcessError, run | ||
|
||
|
||
def is_mdraid_dev(dev): | ||
""" | ||
Check if a given device is an md (Multiple Device) device | ||
It is expected that the "mdadm" command is available, | ||
if it's not it is assumed the device is not an md device. | ||
:return: True if the device is an md device, False otherwise | ||
:raises CalledProcessError: If an error occurred | ||
""" | ||
fail_msg = 'Could not check if device "{}" is an md device: {}' | ||
try: | ||
result = run(['mdadm', '--query', dev]) | ||
except OSError as err: | ||
api.current_logger().warning(fail_msg.format(dev, err)) | ||
return False | ||
except CalledProcessError as err: | ||
err.message = fail_msg.format(dev, err) | ||
raise # let the calling actor handle the exception | ||
|
||
return '--detail' in result['stdout'] | ||
|
||
|
||
def get_component_devices(raid_dev): | ||
""" | ||
Get list of component devices in an md (Multiple Device) array | ||
:return: The list of component devices or None in case of error | ||
:raises ValueError: If the device is not an mdraid device | ||
""" | ||
try: | ||
# using both --verbose and --brief for medium verbosity | ||
result = run(['mdadm', '--detail', '--verbose', '--brief', raid_dev]) | ||
except (OSError, CalledProcessError) as err: | ||
api.current_logger().warning( | ||
'Could not get md array component devices: {}'.format(err) | ||
) | ||
return None | ||
# example output: | ||
# ARRAY /dev/md0 level=raid1 num-devices=2 metadata=1.2 name=localhost.localdomain:0 UUID=c4acea6e:d56e1598:91822e3f:fb26832c # noqa: E501; pylint: disable=line-too-long | ||
# devices=/dev/vda1,/dev/vdb1 | ||
if 'does not appear to be an md device' in result['stdout']: | ||
raise ValueError("Expected md device, but got: {}".format(raid_dev)) | ||
|
||
return sorted(result['stdout'].rsplit('=', 2)[-1].strip().split(',')) |
Oops, something went wrong.