diff --git a/convert2rhel/checks.py b/convert2rhel/checks.py index cebe70cb7..e76af0fc1 100644 --- a/convert2rhel/checks.py +++ b/convert2rhel/checks.py @@ -51,10 +51,14 @@ def is_initramfs_file_valid(filepath): return False logger.debug("Checking if the '%s' file is not corrupted.", filepath) - out, return_code = run_subprocess( - cmd=["/usr/bin/lsinitrd", filepath], - print_output=False, - ) + try: + out, return_code = run_subprocess( + cmd=["/usr/bin/lsinitrd", filepath], + print_output=False, + ) + except UnicodeDecodeError as e: + out = e + return_code = 99 # Having this a high number to not mess with the actual process return codes. if return_code != 0: logger.info("Couldn't verify initramfs file. It may be corrupted.") diff --git a/convert2rhel/unit_tests/checks_test.py b/convert2rhel/unit_tests/checks_test.py index a0397c5ac..074be2840 100644 --- a/convert2rhel/unit_tests/checks_test.py +++ b/convert2rhel/unit_tests/checks_test.py @@ -16,6 +16,8 @@ # along with this program. If not, see . __metaclass__ = type +import os + import pytest from convert2rhel import checks @@ -44,3 +46,14 @@ def testis_initramfs_file_valid(latest_installed_kernel, subprocess_output, expe if not expected: assert "Couldn't verify initramfs file. It may be corrupted." in caplog.records[-2].message assert "Output of lsinitrd: {}".format(subprocess_output[0]) in caplog.records[-1].message + + +def test_is_initramfs_file_valid_unicodedecodeerror(monkeypatch): + def mock_run(*args, **kwargs): + raise UnicodeDecodeError("utf-8", b"", 0, 1, "can't decode bytes") + + monkeypatch.setattr(checks, "run_subprocess", mock_run) + monkeypatch.setattr(os.path, "exists", lambda x: True) + result = checks.is_initramfs_file_valid("mock_file") + + assert result is False diff --git a/plans/tier1.fmf b/plans/tier1.fmf index 3413a7a50..f3a51d080 100644 --- a/plans/tier1.fmf +++ b/plans/tier1.fmf @@ -217,12 +217,6 @@ adjust+: - kernel-boot-files/missing_kernel_boot_files /corrupted_initramfs_file: - adjust+: - - enabled: false - when: distro == alma-8-latest, alma-9-latest, rocky-8.8 - because: | - An unhandled UnicodeDecodeError breaks the conversion. - Reference https://issues.redhat.com/browse/RHELC-1711 discover+: test+<: - kernel-boot-files/corrupted_initramfs_file