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 committed Sep 25, 2024
1 parent 065ff23 commit 96a5bc4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
16 changes: 16 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,12 @@ 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)

# RHELC-1677
# Some repofile packages can remove /etc/yum.repos.d/ when they are removed. Subscription-manager
# doesn't expect this and without the directory the redhat.repo isn't created. This results in unability
# to access repositories as the repository directory doesn't exist.
_check_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 +201,11 @@ def _remove_packages_unless_from_redhat(pkgs_list, disable_repos=None):
logger.debug("Successfully removed %s packages" % len(pkgs_list))

return pkgs_removed


def _check_repos_directory():
"""Check if repository directory is present."""
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 %s packages" % len(pkgs_to_remove) in caplog.records[-3].message
assert "Successfully removed %s packages" % len(pkgs_to_remove) in caplog.records[-1].message


@pytest.mark.parametrize("dir_exists", (True, False))
def test_check_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._check_repos_directory()

assert os.path.exists(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 96a5bc4

Please sign in to comment.