Skip to content

Commit dafb3db

Browse files
r0x0dVenefilyn
authored andcommitted
Use no_rhsm to detect if enablerepos should be disabled
We have a special function that returns a list of repositories that needs to be disabled during various command calls, and that list is returning always the user enablerepos command line switch in it. This patch only add the enablerepos option to the list when the --no-rhsm switch is also applied.
1 parent 0877f03 commit dafb3db

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

convert2rhel/repo.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,28 @@ def get_rhel_repoids():
5858

5959

6060
def get_rhel_repos_to_disable():
61-
"""Get the list of repositories which should be disabled when performing pre-conversion checks. Avoid downloading
62-
backup and up-to-date checks from them. The output list can looks like:
63-
['rhel*', 'user-provided', 'user-provided1']
61+
"""Get the list of repositories which should be disabled when performing pre-conversion checks.
62+
63+
Avoid downloading backup and up-to-date checks from them. The output list can looks like: ["rhel*"]
64+
65+
.. note::
66+
If --enablerepo switch is enabled, we will return a combination of repositories to disable as following:
67+
68+
>>> # tool_opts.enablerepo comes from the CLI option `--enablerepo`.
69+
>>> repos_to_disable = ["rhel*"]
70+
>>> repos_to_disable.extend(tool_opts.enablerepo) # returns: ["rhel*", "rhel-7-server-optional-rpms"]
6471
6572
:return: List of repositories to disable when performing checks.
66-
:rtype: List[str]
73+
:rtype: list[str]
6774
"""
6875
# RHELC-884 disable the RHEL repos to avoid reaching them when checking original system.
69-
# Also disable repositories enabled by the user for the conversion.
70-
return ["rhel*"] + tool_opts.enablerepo
76+
repos_to_disable = ["rhel*"]
77+
78+
# In case we want to disable also the custom repositories set by the user in CLI
79+
if tool_opts.no_rhsm:
80+
repos_to_disable.extend(tool_opts.enablerepo)
81+
82+
return repos_to_disable
7183

7284

7385
def get_rhel_disable_repos_command(disable_repos):

convert2rhel/unit_tests/actions/system_checks/is_loaded_kernel_latest_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,6 @@ def test_is_loaded_kernel_latest_system_exit(self, monkeypatch, is_loaded_kernel
787787
"--setopt=exclude=",
788788
"--quiet",
789789
"--disablerepo=rhel*",
790-
"--disablerepo=test-repo",
791790
"--qf",
792791
"C2R\\t%{BUILDTIME}\\t%{VERSION}-%{RELEASE}\\t%{REPOID}",
793792
"kernel",

convert2rhel/unit_tests/repo_test.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,21 @@ def test_get_rhel_repoids_el7(pretend_os, is_els_release, expected, monkeypatch)
8080
assert repos == expected
8181

8282

83-
@pytest.mark.parametrize(("enablerepo", "disablerepos"), (([], ["rhel*"]), (["test-repo"], ["rhel*", "test-repo"])))
84-
def test_get_rhel_repos_to_disable(monkeypatch, enablerepo, disablerepos):
85-
monkeypatch.setattr(repo.tool_opts, "enablerepo", enablerepo)
83+
@pytest.mark.parametrize(
84+
("no_rhsm", "enablerepo", "disablerepos"),
85+
(
86+
(False, [], ["rhel*"]),
87+
(True, ["test-repo"], ["rhel*", "test-repo"]),
88+
(True, [], ["rhel*"]),
89+
(False, ["test-repo"], ["rhel*"]),
90+
),
91+
)
92+
def test_get_rhel_repos_to_disable(monkeypatch, global_tool_opts, no_rhsm, enablerepo, disablerepos):
93+
monkeypatch.setattr(repo, "tool_opts", global_tool_opts)
94+
global_tool_opts.enablerepo = enablerepo
95+
global_tool_opts.no_rhsm = no_rhsm
8696

8797
repos = repo.get_rhel_repos_to_disable()
88-
8998
assert repos == disablerepos
9099

91100

0 commit comments

Comments
 (0)