Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RHELC-708] Check if shim-x64 package is present in the system #572

Merged
merged 1 commit into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions convert2rhel/special_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,33 @@ def perform_java_openjdk_workaround():


def unprotect_shim_x64():
"""Remove the shim-x64 package yum protection on UEFI-based Oracle Linux 7 systems as it causes a yum traceback.
"""Remove the shim-x64 package protection on Oracle Linux 7 as it causes yum to traceback.

The package is protected through the /etc/yum/protected.d/shim-x64.conf file. It is installed with the
Oracle Linux 7 shim-x64 package. The same package on RHEL 7 does not install this file - it's OL specific - no
need to add it back after a successful conversion to RHEL.
The package is protected through the /etc/yum/protected.d/shim-x64.conf
file. It is installed with the Oracle Linux 7 shim-x64 package. The same
package on RHEL 7 does not install this file - it's OL specific - no need to
add it back after a successful conversion to RHEL.

Related: https://bugzilla.redhat.com/show_bug.cgi?id=2009368
"""
logger.info("Removing shim-x64 package yum protection.")
if system_info.id == "oracle" and system_info.version.major == 7:
shim_x64_pkg_protection_file.backup()
try:
os.remove(shim_x64_pkg_protection_file.filepath)
logger.info(
"'%s' removed in accordance with https://bugzilla.redhat.com/show_bug.cgi?id=2009368."
% shim_x64_pkg_protection_file.filepath
)
except OSError as err:
# For permissions reasons (unlikely as we run as root) or because it does not exist
logger.error("Unable to remove '%s': %s" % (shim_x64_pkg_protection_file.filepath, err.strerror))

logger.info("Checking if shim-x64 package is installed.")
shim_x64 = system_info.is_rpm_installed(name="shim-x64")

if shim_x64:
logger.info("Removing shim-x64 package yum protection.")
if system_info.id == "oracle" and system_info.version.major == 7:
shim_x64_pkg_protection_file.backup()
try:
os.remove(shim_x64_pkg_protection_file.filepath)
logger.info(
"'%s' removed in accordance with https://bugzilla.redhat.com/show_bug.cgi?id=2009368."
% shim_x64_pkg_protection_file.filepath
)
except OSError as err:
# For permissions reasons (unlikely as we run as root) or because it does not exist
logger.error("Unable to remove '%s': %s" % (shim_x64_pkg_protection_file.filepath, err.strerror))
else:
logger.info("Relevant to Oracle Linux 7 only. Skipping.")
else:
logger.info("Relevant to Oracle Linux 7 only. Skipping.")
logger.info("shim-x64 package is not installed. Nothing to do.")
20 changes: 15 additions & 5 deletions convert2rhel/unit_tests/special_cases_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,27 @@ def test_perform_java_openjdk_workaround(


@pytest.mark.parametrize(
("sys_id", "removal_ok", "log_msg"),
("sys_id", "removal_ok", "log_msg", "is_rpm_installed"),
(
("oracle", True, "removed in accordance with"),
("oracle", False, "Unable to remove"),
("centos", True, "Relevant to Oracle Linux 7 only"),
("oracle", True, "removed in accordance with", True),
("oracle", False, "Unable to remove", True),
("centos", True, "Relevant to Oracle Linux 7 only", True),
("centos", False, "shim-x64 package is not installed. Nothing to do.", False),
),
)
@mock.patch("os.remove")
def test_unprotect_shim_x64(mock_os_remove, sys_id, removal_ok, log_msg, monkeypatch, caplog):
def test_unprotect_shim_x64(
mock_os_remove,
sys_id,
removal_ok,
log_msg,
is_rpm_installed,
monkeypatch,
caplog,
):
monkeypatch.setattr(system_info, "id", sys_id)
monkeypatch.setattr(system_info, "version", namedtuple("Version", ["major", "minor"])(7, 0))
monkeypatch.setattr(special_cases.system_info, "is_rpm_installed", value=mock.Mock(return_value=is_rpm_installed))
if not removal_ok:
mock_os_remove.side_effect = OSError()

Expand Down