Skip to content

Commit

Permalink
Add exclude setopt to remaining repoquery calls
Browse files Browse the repository at this point in the history
We need to exclude any packages set in the /etc/yum.conf set by the user
so we can make sure that when we run repoquery, we are really gathering
all the data we want from the command. This patch introduces the
overridable --setopt=exclude= in the remaining repoquery calls.
  • Loading branch information
r0x0d authored and Venefilyn committed Aug 13, 2024
1 parent 7fbab58 commit 6ca9ad6
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 10 deletions.
5 changes: 1 addition & 4 deletions convert2rhel/actions/pre_ponr_changes/kernel_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ def _get_rhel_supported_kmods(self):
"--releasever=%s" % system_info.releasever,
"--setopt=*.skip_if_unavailable=False",
]
basecmd = [
"repoquery",
"--releasever=%s" % system_info.releasever,
]
basecmd = ["repoquery", "--releasever=%s" % system_info.releasever, "--setopt=exclude="]

if system_info.version.major >= 8:
basecmd.append("--setopt=module_platform_id=platform:el" + str(system_info.version.major))
Expand Down
1 change: 1 addition & 0 deletions convert2rhel/actions/system_checks/convert2rhel_latest.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def run(self):
"repoquery",
"--releasever=%s" % system_info.version.major,
"--setopt=reposdir=%s" % os.path.dirname(repofile_path),
"--setopt=exclude=",
"--qf",
"C2R %{NAME}-%{EPOCH}:%{VERSION}-%{RELEASE}.%{ARCH}",
"convert2rhel",
Expand Down
2 changes: 1 addition & 1 deletion convert2rhel/pkghandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def _get_package_repositories(pkgs, disable_repos=None):
# If needed, disable some repos for the repoquery
disable_repo_command = repo.get_rhel_disable_repos_command(disable_repos)

cmd = ["repoquery", "--quiet", "-q"]
cmd = ["repoquery", "--quiet", "-q", "--setopt=exclude="]
cmd.extend(disable_repo_command)
cmd.extend(pkgs)
cmd.extend(["--qf", query_format])
Expand Down
2 changes: 1 addition & 1 deletion convert2rhel/pkgmanager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def call_yum_cmd(
args = args or []
setopts = setopts or []

cmd = ["yum", command, "-y"]
cmd = ["yum", command, "--setopt=exclude=", "-y"]

# The --disablerepo yum option must be added before --enablerepo,
# otherwise the enabled repo gets disabled if --disablerepo="*" is used
Expand Down
4 changes: 4 additions & 0 deletions convert2rhel/pkgmanager/handlers/dnf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ def _set_up_base(self):
# going in with the packages in the transaction.
self._base._ds_callback = DependencySolverProgressIndicatorCallback()

# Override the exclude option that is loaded from the config and set it
# to empty.
self._base.conf.substitutions["exclude"] = []

def _enable_repos(self):
"""Enable a list of required repositories."""
self._base.read_all_repos()
Expand Down
48 changes: 46 additions & 2 deletions convert2rhel/unit_tests/pkghandler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,36 @@ def test_get_rpm_header_failure(self, monkeypatch):
pkghandler.get_rpm_header(unknown_pkg)


class TestPreserveOnlyRHELKernel:
@centos7
def test_preserve_only_rhel_kernel(self, pretend_os, monkeypatch):
monkeypatch.setattr(pkghandler, "install_rhel_kernel", lambda: True)
monkeypatch.setattr(pkghandler, "fix_invalid_grub2_entries", lambda: None)
monkeypatch.setattr(pkghandler, "remove_non_rhel_kernels", mock.Mock(return_value=[]))
monkeypatch.setattr(pkghandler, "install_gpg_keys", mock.Mock())
monkeypatch.setattr(utils, "run_subprocess", RunSubprocessMocked())
monkeypatch.setattr(
pkghandler,
"get_installed_pkgs_by_fingerprint",
GetInstalledPkgsByFingerprintMocked(return_value=[create_pkg_information(name="kernel")]),
)
monkeypatch.setattr(system_info, "name", "CentOS7")
monkeypatch.setattr(system_info, "arch", "x86_64")
monkeypatch.setattr(utils, "store_content_to_file", StoreContentToFileMocked())

pkghandler.preserve_only_rhel_kernel()

assert utils.run_subprocess.cmd == [
"yum",
"update",
"--setopt=exclude=",
"-y",
"--releasever=7Server",
"kernel",
]
assert pkghandler.get_installed_pkgs_by_fingerprint.call_count == 1


class TestGetKernelAvailability:
@pytest.mark.parametrize(
("subprocess_output", "expected_installed", "expected_available"),
Expand Down Expand Up @@ -267,7 +297,14 @@ def test_handle_older_rhel_kernel_available(self, pretend_os, monkeypatch):

pkghandler.handle_no_newer_rhel_kernel_available()

assert utils.run_subprocess.cmd == ["yum", "install", "-y", "--releasever=7Server", "kernel-4.7.2-201.fc24"]
assert utils.run_subprocess.cmd == [
"yum",
"install",
"--setopt=exclude=",
"-y",
"--releasever=7Server",
"kernel-4.7.2-201.fc24",
]

@centos7
def test_handle_older_rhel_kernel_not_available(self, pretend_os, monkeypatch):
Expand All @@ -294,7 +331,14 @@ def test_handle_older_rhel_kernel_not_available_multiple_installed(self, pretend

assert len(utils.remove_pkgs.pkgs) == 1
assert utils.remove_pkgs.pkgs[0] == "kernel-4.7.4-200.fc24"
assert utils.run_subprocess.cmd == ["yum", "install", "-y", "--releasever=7Server", "kernel-4.7.4-200.fc24"]
assert utils.run_subprocess.cmd == [
"yum",
"install",
"--setopt=exclude=",
"-y",
"--releasever=7Server",
"kernel-4.7.4-200.fc24",
]


class TestReplaceNonRHELInstalledKernel:
Expand Down
11 changes: 9 additions & 2 deletions convert2rhel/unit_tests/pkgmanager/pkgmanager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def test_call_yum_cmd(self, monkeypatch):
assert utils.run_subprocess.cmd == [
"yum",
"install",
"--setopt=exclude=",
"-y",
"--releasever=8",
"--setopt=module_platform_id=platform:el8",
Expand All @@ -110,7 +111,7 @@ def test_call_yum_cmd_not_setting_releasever(self, pretend_os, monkeypatch):

pkgmanager.call_yum_cmd("install", set_releasever=False)

assert utils.run_subprocess.cmd == ["yum", "install", "-y"]
assert utils.run_subprocess.cmd == ["yum", "install", "--setopt=exclude=", "-y"]

@centos7
def test_call_yum_cmd_with_disablerepo_and_enablerepo(self, pretend_os, monkeypatch):
Expand All @@ -124,6 +125,7 @@ def test_call_yum_cmd_with_disablerepo_and_enablerepo(self, pretend_os, monkeypa
assert utils.run_subprocess.cmd == [
"yum",
"install",
"--setopt=exclude=",
"-y",
"--disablerepo=*",
"--releasever=7Server",
Expand All @@ -141,6 +143,7 @@ def test_call_yum_cmd_with_submgr_enabled_repos(self, pretend_os, monkeypatch):
assert utils.run_subprocess.cmd == [
"yum",
"install",
"--setopt=exclude=",
"-y",
"--releasever=7Server",
"--enablerepo=rhel-7-extras-rpm",
Expand All @@ -154,7 +157,7 @@ def test_call_yum_cmd_with_repo_overrides(self, pretend_os, monkeypatch):

pkgmanager.call_yum_cmd("install", ["pkg"], enable_repos=[], disable_repos=[])

assert utils.run_subprocess.cmd == ["yum", "install", "-y", "--releasever=7Server", "pkg"]
assert utils.run_subprocess.cmd == ["yum", "install", "--setopt=exclude=", "-y", "--releasever=7Server", "pkg"]

pkgmanager.call_yum_cmd(
"install",
Expand All @@ -166,6 +169,7 @@ def test_call_yum_cmd_with_repo_overrides(self, pretend_os, monkeypatch):
assert utils.run_subprocess.cmd == [
"yum",
"install",
"--setopt=exclude=",
"-y",
"--disablerepo=disable-repo",
"--releasever=7Server",
Expand All @@ -185,6 +189,7 @@ def test_call_yum_cmd_nothing_to_do(self, pretend_os, monkeypatch, caplog):
assert utils.run_subprocess.cmd == [
"yum",
"install",
"--setopt=exclude=",
"-y",
"--releasever=8.5",
"--setopt=module_platform_id=platform:el8",
Expand All @@ -206,6 +211,7 @@ def test_call_yum_cmd_custom_release_set(self, pretend_os, monkeypatch, caplog):
assert utils.run_subprocess.cmd == [
"yum",
"install",
"--setopt=exclude=",
"-y",
"--releasever=8",
"--setopt=module_platform_id=platform:el8",
Expand Down Expand Up @@ -245,6 +251,7 @@ def test_call_yum_cmd_setopts_override(self, setopts, pretend_os, monkeypatch, c
expected_cmd = [
"yum",
"install",
"--setopt=exclude=",
"-y",
"--setopt=module_platform_id=platform:el8",
]
Expand Down

0 comments on commit 6ca9ad6

Please sign in to comment.