Skip to content

Commit

Permalink
[RHELC-1677] Fix missing repository directory
Browse files Browse the repository at this point in the history
Some packages (e.g. rocky-release or alma-release on EL9) can remove
repository directory as their part. Without the directory, sub-man is
unable to generate redhat.repo file. This results in inaccessibility of
all rhel repositories.
  • Loading branch information
hosekadam authored and Venefilyn committed Oct 9, 2024
1 parent da9502d commit 80d9a2d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
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

0 comments on commit 80d9a2d

Please sign in to comment.