|
| 1 | +from leapp import reporting |
| 2 | +from leapp.exceptions import StopActorExecution |
| 3 | +from leapp.libraries.common import grub as grub_lib |
| 4 | +from leapp.libraries.stdlib import api, CalledProcessError, run |
| 5 | +from leapp.reporting import create_report |
| 6 | + |
| 7 | +# There is no grub legacy package on RHEL7, therefore, the system must have been upgraded from RHEL6 |
| 8 | +MIGRATION_TO_GRUB2_GUIDE_URL = 'https://access.redhat.com/solutions/2643721' |
| 9 | + |
| 10 | + |
| 11 | +def has_legacy_grub(device): |
| 12 | + try: |
| 13 | + output = run(['file', '-s', device]) |
| 14 | + except CalledProcessError as err: |
| 15 | + msg = 'Failed to determine the file type for the special device `{0}`. Full error: `{1}`' |
| 16 | + api.current_logger().warning(msg.format(device, str(err))) |
| 17 | + |
| 18 | + # According to `file` manpage, the exit code > 0 iff the file does not exists (meaning) |
| 19 | + # that grub_lib.get_grub_devices() is unreliable for some reason (better stop the upgrade), |
| 20 | + # or because the file type could not be determined. However, its manpage directly gives examples |
| 21 | + # of file -s being used on block devices, so this should be unlikely - especially if one would |
| 22 | + # consider that get_grub_devices was able to determine that it is a grub device. |
| 23 | + raise StopActorExecution() |
| 24 | + |
| 25 | + grub_legacy_version_string = 'GRUB version 0.94' |
| 26 | + return grub_legacy_version_string in output['stdout'] |
| 27 | + |
| 28 | + |
| 29 | +def check_grub_disks_for_legacy_grub(): |
| 30 | + # Both GRUB2 and Grub Legacy are recognized by `get_grub_devices` |
| 31 | + grub_devices = grub_lib.get_grub_devices() |
| 32 | + |
| 33 | + legacy_grub_devices = [] |
| 34 | + for device in grub_devices: |
| 35 | + if has_legacy_grub(device): |
| 36 | + legacy_grub_devices.append(device) |
| 37 | + |
| 38 | + if legacy_grub_devices: |
| 39 | + details = ( |
| 40 | + 'Leapp detected GRUB Legacy to be installed on the system. ' |
| 41 | + 'The GRUB Legacy bootloader is unsupported on RHEL7 and GRUB2 must be used instead. ' |
| 42 | + 'The presence of GRUB Legacy is possible on systems that have been upgraded from RHEL 6 in the past, ' |
| 43 | + 'but required manual post-upgrade steps have not been performed. ' |
| 44 | + 'Note that the in-place upgrade from RHEL 6 to RHEL 7 systems is in such a case ' |
| 45 | + 'considered as unfinished.\n\n' |
| 46 | + |
| 47 | + 'GRUB Legacy has been detected on following devices:\n' |
| 48 | + '{block_devices_fmt}\n' |
| 49 | + ) |
| 50 | + |
| 51 | + hint = ( |
| 52 | + 'Migrate to the GRUB2 bootloader on the reported devices. ' |
| 53 | + 'Also finish other post-upgrade steps related to the previous in-place upgrade, the majority of which ' |
| 54 | + 'is a part of the related preupgrade report for upgrades from RHEL 6 to RHEL 7.' |
| 55 | + 'If you are not sure whether all previously required post-upgrade steps ' |
| 56 | + 'have been performed, consider a clean installation of the RHEL 8 system instead. ' |
| 57 | + 'Note that the in-place upgrade to RHEL 8 can fail in various ways ' |
| 58 | + 'if the RHEL 7 system is misconfigured.' |
| 59 | + ) |
| 60 | + |
| 61 | + block_devices_fmt = '\n'.join(legacy_grub_devices) |
| 62 | + create_report([ |
| 63 | + reporting.Title("GRUB Legacy is used on the system"), |
| 64 | + reporting.Summary(details.format(block_devices_fmt=block_devices_fmt)), |
| 65 | + reporting.Severity(reporting.Severity.HIGH), |
| 66 | + reporting.Groups([reporting.Groups.BOOT]), |
| 67 | + reporting.Remediation(hint=hint), |
| 68 | + reporting.Groups([reporting.Groups.INHIBITOR]), |
| 69 | + reporting.ExternalLink(url=MIGRATION_TO_GRUB2_GUIDE_URL, |
| 70 | + title='How to install GRUB2 after a RHEL6 to RHEL7 upgrade'), |
| 71 | + ]) |
0 commit comments