Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh metadata cache after failed package installation #3348

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

bajertom
Copy link
Collaborator

@bajertom bajertom commented Nov 8, 2024

Fixes #3277

When testing I found out that there is different behavior in dnf5 compared to dnf4, where a mere dnf makecache would be enough, but dnf5 needs the --refresh option as well (or dnf clean metadata or dnf clean expire-cache), see https://bugzilla.redhat.com/show_bug.cgi?id=2324177

Not sure about the Exception being too generic. Should I create a new one, something like InstallationError? And notify the user through logger as to why metadata --refresh is happening?

Pull Request Checklist

  • implement the feature

tmt/steps/prepare/install.py Outdated Show resolved Hide resolved
tmt/steps/prepare/install.py Outdated Show resolved Hide resolved
tmt/steps/prepare/install.py Outdated Show resolved Hide resolved
@bajertom bajertom force-pushed the tbajer-dnf-cache-error branch 2 times, most recently from c736cd9 to 793ac8a Compare November 14, 2024 16:46
@bajertom bajertom requested a review from happz November 19, 2024 10:12
@happz happz added area | package managers Changes related to implementations of package managers plugin | install The prepare plugin for installing packages labels Nov 19, 2024
@happz happz modified the milestones: 1.40, 1.39 Nov 19, 2024
except Exception:
# Refresh cache in case of recent but not updated change do repodata
self.guest.package_manager.refresh_metadata()
self._install()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether should capture the first exception as well - this way, the original one is lost, with all its data. How about something like this?

try:
    self._install()

except Exception as exc1:
    # We do not have any special handling for exceptions raised by the following code.
    # Wrapping them with try/except gives us a chance to attach the original exception
    # to whatever the code may raise, and therefore preserve the information attached
    # to the original exception.
    try:
        # Refresh cache in case of recent but not updated change do repodata
        self.guest.package_manager.refresh_metadata()
        self._install()

    except Exception as exc2:
        raise exc2 from ex1

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, that seems like an unnecessary loss of data - better to catch them both. I used your code, if that's alright:)

@bajertom
Copy link
Collaborator Author

/packit test

@bajertom bajertom requested a review from happz November 19, 2024 15:14
@psss psss modified the milestones: 1.39, 1.40 Nov 21, 2024
@happz happz added the ci | full test Pull request is ready for the full test execution label Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area | package managers Changes related to implementations of package managers ci | full test Pull request is ready for the full test execution plugin | install The prepare plugin for installing packages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tmt should handle error due to outdated dnf cache
4 participants