Skip to content

Commit

Permalink
Call check_custom_repos_are_valid before any other checks
Browse files Browse the repository at this point in the history
This change intends to call the `check_custom_repos_are_valid` function
as the first thing before any other checks. The reason for that is we
can guarantee that we will work with the most recent cache for
`yum`/`dnf`.

Jira reference (If any): https://issues.redhat.com/browse/OAMG-6294
Bugzilla reference (If any):
  • Loading branch information
r0x0d committed Mar 28, 2022
1 parent 2c96035 commit 52141e1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
10 changes: 2 additions & 8 deletions convert2rhel/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@

def perform_pre_checks():
"""Early checks after system facts should be added here."""
check_custom_repos_are_valid()
check_efi()
check_tainted_kmods()
check_readonly_mounts()
check_rhel_compatible_kernel_is_used()
check_custom_repos_are_valid()


def perform_pre_ponr_checks():
Expand Down Expand Up @@ -159,11 +159,6 @@ def check_custom_repos_are_valid():
logger.info("Skipping the check of repositories due to the use of RHSM for the conversion.")
return

# Without clearing the metadata cache, the `yum makecache` command may return 0 (everything's ok) even when
# the baseurl of a repository is not accessible. That would happen when the repository baseurl is changed but yum
# still uses the previous baseurl stored in its cache.
call_yum_cmd(command="clean", args=["metadata"], print_output=False)

output, ret_code = call_yum_cmd(
command="makecache", args=["-v", "--setopt=*.skip_if_unavailable=False"], print_output=False
)
Expand All @@ -172,9 +167,8 @@ def check_custom_repos_are_valid():
"Unable to access the repositories passed through the --enablerepo option. "
"For more details, see YUM/DNF output:\n{0}".format(output)
)
else:
logger.debug("Output of the previous yum command:\n{0}".format(output))

logger.debug("Output of the previous yum command:\n{0}".format(output))
logger.info("The repositories passed through the --enablerepo option are all accessible.")


Expand Down
4 changes: 4 additions & 0 deletions convert2rhel/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,16 @@ def main():
loggerinst.task("Prepare: Show Red Hat software EULA")
show_eula()

loggerinst.task("Prepare: Clean yum cache metadata")
pkghandler.clean_yum_metadata()

# gather system information
loggerinst.task("Prepare: Gather system information")
systeminfo.system_info.resolve_system_info()
breadcrumbs.breadcrumbs.collect_early_data()

# check the system prior the conversion (possible inhibit)
loggerinst.task("Prepare: Perform basic system checks")
checks.perform_pre_checks()

# backup system release file before starting conversion process
Expand Down
15 changes: 15 additions & 0 deletions convert2rhel/pkghandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,3 +968,18 @@ def get_pkg_names_from_rpm_paths(rpm_paths):
for rpm_path in rpm_paths:
pkg_names.append(utils.get_package_name_from_rpm(rpm_path))
return pkg_names
def clean_yum_metadata():
"""Remove cached metadata from yum.
This is to make sure that Convert2RHEL works with up-to-date data from repositories before, for instance, querying
whether the system has the latest package versions installed, or before checking whether enabled repositories have
accessible URLs.
"""
output, ret_code = call_yum_cmd(command="clean", args=["metadata"], print_output=False)
loggerinst.debug("Output of yum clean metadata:\n%s" % output)

if ret_code != 0:
loggerinst.warning("Failed to clean yum metadata:\n%s" % output)
return

loggerinst.info("Cached yum metadata cleaned successfully.")
9 changes: 9 additions & 0 deletions convert2rhel/unit_tests/pkghandler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1685,3 +1685,12 @@ def test_filter_installed_pkgs(packages, expected, is_rpm_installed, monkeypatch
def test_get_pkg_names_from_rpm_paths(rpm_paths, expected, monkeypatch):
monkeypatch.setattr(utils, "get_package_name_from_rpm", lambda x: x)
assert pkghandler.get_pkg_names_from_rpm_paths(rpm_paths) == expected


@pytest.mark.parametrize(
("ret_code", "expected"), ((0, "Cached yum metadata cleaned successfully."), (1, "Failed to clean yum metadata"))
)
def test_clean_yum_metadata(ret_code, expected, monkeypatch, caplog):
monkeypatch.setattr(pkghandler, "call_yum_cmd", value=mock.Mock(return_value=("Test", ret_code)))
pkghandler.clean_yum_metadata()
assert expected in caplog.records[-1].message

0 comments on commit 52141e1

Please sign in to comment.