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-1677] Fix missing /etc/yum.repos.d/ directory on EL9 #1389

Merged
merged 1 commit into from
Oct 9, 2024
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
17 changes: 17 additions & 0 deletions convert2rhel/actions/pre_ponr_changes/handle_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@

__metaclass__ = type

import os

from convert2rhel import actions, pkghandler, repo, utils
from convert2rhel.backup import backup_control, get_backedup_system_repos
from convert2rhel.backup.packages import RestorablePackage
from convert2rhel.logger import root_logger
from convert2rhel.repo import DEFAULT_YUM_REPOFILE_DIR
from convert2rhel.systeminfo import system_info


Expand Down Expand Up @@ -132,6 +134,13 @@ def run(self):
# There is needed for avoid reaching out RHEL repositories while requesting info about pkgs.
disable_repos = repo.get_rhel_repos_to_disable()
pkgs_removed = _remove_packages_unless_from_redhat(pkgs_list=all_pkgs, disable_repos=disable_repos)

# https://issues.redhat.com/browse/RHELC-1677
# In some cases the {system}-release package takes ownership of the /etc/yum.repos.d/ directory,
# when the package gets forcefully removed, the directory gets removed as well. Subscription-manager
# doesn't expect this and without the directory the redhat.repo isn't re-created. This results in an inability
# to access any repositories as the repository directory doesn't exist.
_fix_repos_directory()
except SystemExit as e:
# TODO(r0x0d): Places where we raise SystemExit and need to be
# changed to something more specific.
Expand Down Expand Up @@ -193,3 +202,11 @@ def _remove_packages_unless_from_redhat(pkgs_list, disable_repos=None):
logger.debug("Successfully removed {} packages".format(len(pkgs_list)))

return pkgs_removed


def _fix_repos_directory():
"""Check if repository directory is present. If the directory is missing, create it."""
repo_dir = DEFAULT_YUM_REPOFILE_DIR
if not os.path.exists(repo_dir):
os.mkdir(repo_dir)
logger.debug("Recreated repository directory {} as it was removed with some special package.".format(repo_dir))
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

__metaclass__ = type

import os

import pytest
import six

Expand Down Expand Up @@ -272,3 +274,15 @@ def test_remove_packages_unless_from_redhat(pkgs_to_remove, monkeypatch, caplog)

assert "Removing the following {} packages".format(len(pkgs_to_remove)) in caplog.records[-3].message
assert "Successfully removed {} packages".format(len(pkgs_to_remove)) in caplog.records[-1].message


@pytest.mark.parametrize("dir_exists", (True, False))
def test_fix_repos_directory(monkeypatch, tmpdir, dir_exists):
repo_dir = tmpdir.join("repo")
if dir_exists:
repo_dir.mkdir()
monkeypatch.setattr(handle_packages, "DEFAULT_YUM_REPOFILE_DIR", str(repo_dir))

handle_packages._fix_repos_directory()

assert os.path.exists(str(repo_dir))
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,6 @@ def test_override_inhibitor_os_release_restored(

c2r.expect("'CONVERT2RHEL_INCOMPLETE_ROLLBACK' environment variable detected, continuing conversion.")

# Apparently the whole "/etc/yum.repos.d" dir is missing when the *-release package gets erased
# re-create it, so sub-man is able to refresh the redhat.repo file
# TODO remove this part when/if https://issues.redhat.com/browse/RHELC-1677 gets fixed
c2r.expect("Ensure kernel modules compatibility with RHEL")
missing_dir = "/etc/yum.repos.d"
if not os.path.exists(missing_dir):
os.mkdir(missing_dir)

c2r.expect("Continue with the system conversion")
c2r.sendline("n")
assert c2r.exitstatus == 1
Expand Down
Loading