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

Merged
merged 1 commit into from
Dec 12, 2024

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
tmt/steps/prepare/install.py Outdated Show resolved Hide resolved
@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
@happz happz force-pushed the tbajer-dnf-cache-error branch from 9c21ff0 to a998cbf Compare November 22, 2024 13:36
@happz
Copy link
Collaborator

happz commented Nov 28, 2024

@bajertom please, add a unit test for this new operation. It can be fairly trivial, and it would verify those commands work without crashing. See e.g. https://github.com/teemtee/tmt/blob/main/tests/unit/test_package_managers.py#L420 or other unit tests.

To run new unit tests, the following command should work (with dev environment activated, and let's say you'd call the test test_refresh_metadata):

$ hatch -e dev shell
$ pytest -vv --showlocals tests/unit/test_package_managers.py::test_refresh_metadata

@bajertom
Copy link
Collaborator Author

bajertom commented Dec 3, 2024

I've added unit tests covering the command. Since there was difference between cases in "Metadata C/cache C/created" in different distros but for the same package manager (yum) I've decided to just stick with "Metadata". Is this enough or should I catch a more specific part of the stdout in this case?

Same goes for apt - it depends on whether the system is up to date or not. It's either (debian test)

Hit:1 http://repolink reponame
Hit:2 http://repolink reponame
50 packages can be upgraded. Run 'apt list --upgradable' to see them.

before apt update or (ubuntu test)

Hit:1 http://repolink reponame
Hit:2 http://repolink reponame
All packages are up to date.

if the system is up to date, so I decided to go for packages as a keyword here.

However I am lost with rpm-ostree packager. On my VM I can run rpm-ostree upgrade --check, but the unit test throws this error

DEBUG    tmt:log.py:742 Run command: podman exec ec41e25298a91ed3dd829df46b889f4605f5b33862696297c3146063dd030f5a /bin/bash -c 'rpm-ostree upgrade --check'
INFO     tmt:log.py:742     cmd: rpm-ostree upgrade --check
DEBUG    tmt:log.py:742 environment
DEBUG    tmt:log.py:742 Command event: 2.91e-06 waiting for process to finish
INFO     tmt:log.py:742     err: System has not been booted with systemd as init system (PID 1). Can't operate.
INFO     tmt:log.py:742     err: Failed to connect to bus: Host is down
INFO     tmt:log.py:742     err: System has not been booted with systemd as init system (PID 1). Can't operate.
INFO     tmt:log.py:742     err: Failed to connect to bus: Host is down
INFO     tmt:log.py:742     err: error: Loading sysroot: exit status: 1
DEBUG    tmt:log.py:742 Command event: 0.1897 waiting for process completed
DEBUG    tmt:log.py:742 Command event: 0.19 waiting for stream readers
DEBUG    tmt:log.py:742 Command event: 0.1902 stdout reader done
DEBUG    tmt:log.py:742 Command event: 0.1903 stderr reader done
DEBUG    tmt:log.py:742 Command returned '1' (failure).

@bajertom bajertom force-pushed the tbajer-dnf-cache-error branch from ff0d1c3 to 1b833b0 Compare December 3, 2024 08:34
@happz
Copy link
Collaborator

happz commented Dec 3, 2024

I've added unit tests covering the command. Since there was difference between cases in "Metadata C/cache C/created" in different distros but for the same package manager (yum) I've decided to just stick with "Metadata". Is this enough or should I catch a more specific part of the stdout in this case?

LGTM. It's not perfect, which is true for other test cases in that file, we're fine. Success of the command itself is a good indication things went well.

However I am lost with rpm-ostree packager. On my VM I can run rpm-ostree upgrade --check, but the unit test throws this error

DEBUG    tmt:log.py:742 Run command: podman exec ec41e25298a91ed3dd829df46b889f4605f5b33862696297c3146063dd030f5a /bin/bash -c 'rpm-ostree upgrade --check'
INFO     tmt:log.py:742     cmd: rpm-ostree upgrade --check
DEBUG    tmt:log.py:742 environment
DEBUG    tmt:log.py:742 Command event: 2.91e-06 waiting for process to finish
INFO     tmt:log.py:742     err: System has not been booted with systemd as init system (PID 1). Can't operate.
INFO     tmt:log.py:742     err: Failed to connect to bus: Host is down
INFO     tmt:log.py:742     err: System has not been booted with systemd as init system (PID 1). Can't operate.
INFO     tmt:log.py:742     err: Failed to connect to bus: Host is down
INFO     tmt:log.py:742     err: error: Loading sysroot: exit status: 1
DEBUG    tmt:log.py:742 Command event: 0.1897 waiting for process completed
DEBUG    tmt:log.py:742 Command event: 0.19 waiting for stream readers
DEBUG    tmt:log.py:742 Command event: 0.1902 stdout reader done
DEBUG    tmt:log.py:742 Command event: 0.1903 stderr reader done
DEBUG    tmt:log.py:742 Command returned '1' (failure).

Never seen this one before, and there are other rpm-ostree tests where I'd expect this to appear. No idea so far.

Can you rebase the PR? That should make the patch easier to review and play with.

@happz happz force-pushed the tbajer-dnf-cache-error branch from 1b833b0 to 9ef2fa9 Compare December 11, 2024 11:33
@happz
Copy link
Collaborator

happz commented Dec 11, 2024

@bajertom I tried to play a bit with rpm-ostree, but no luck. @thrix @KwisatzHaderach @BeeGrech any tips, or better approach?

So far I'd propose adding this, basically a no-op with a warning:

diff --git a/tests/unit/test_package_managers.py b/tests/unit/test_package_managers.py
index 0655fcea..b7434ead 100644
--- a/tests/unit/test_package_managers.py
+++ b/tests/unit/test_package_managers.py
@@ -478,6 +478,15 @@ def _parametrize_test_refresh_metadata() -> \
                 r"rpm-ostree upgrade --check", \
                 'Available'
 
+            yield pytest.param(
+                container,
+                package_manager_class,
+                r"rpm-ostree refresh-md --force", \
+                'Available',
+                marks=pytest.mark.skip(reason="refresh-md does not work with how tmt runs ostree container")
+                )
+
+
         elif package_manager_class is tmt.package_managers.apk.Apk:
             yield container, \
                 package_manager_class, \
diff --git a/tmt/package_managers/rpm_ostree.py b/tmt/package_managers/rpm_ostree.py
index 97224202..b37532c3 100644
--- a/tmt/package_managers/rpm_ostree.py
+++ b/tmt/package_managers/rpm_ostree.py
@@ -101,10 +101,20 @@ class RpmOstree(tmt.package_managers.PackageManager):
         return extra_options
 
     def refresh_metadata(self) -> CommandOutput:
-        script = ShellScript(
-            f'{self.command.to_script()} upgrade --check')
-
-        return self.guest.execute(script)
+        self.guest.warn("Metadata refresh is not supported with rpm-ostree.")
+
+        return CommandOutput(stdout=None, stderr=None)
+
+        # The following should work, but it hits some ostree issue:
+        #
+        #   System has not been booted with systemd as init system (PID 1). Can't operate.
+        #   Failed to connect to bus: Host is down
+        #   System has not been booted with systemd as init system (PID 1). Can't operate.
+        #   Failed to connect to bus: Host is down
+        #   error: Loading sysroot: exit status: 1
+        #
+        # script = ShellScript(f'{self.command.to_script()} refresh-md --force')
+        # return self.guest.execute(script)
 
     def install(
             self,

@KwisatzHaderach
Copy link
Collaborator

As I already mentioned in my comment thread above, you can refresh with dnf, but it would look weird

I have no problem with the above approach and don't have a better one apart from ^

@bajertom bajertom force-pushed the tbajer-dnf-cache-error branch 2 times, most recently from e134228 to 104050f Compare December 11, 2024 13:53
@BeeGrech
Copy link
Contributor

LGTM, no other ideas aside from what has been mentioned

@happz
Copy link
Collaborator

happz commented Dec 11, 2024

Thanks for the input. Let's make it a no-op for now, with a warning, and we can get back to it later. I guess the way how tmt runs ostree containers could be improved, enabling the feature eventually.

@psss psss force-pushed the tbajer-dnf-cache-error branch from 104050f to 65ebaad Compare December 12, 2024 07:18
Copy link
Collaborator

@psss psss left a comment

Choose a reason for hiding this comment

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

Thanks for improving this!

@psss psss self-assigned this Dec 12, 2024
@psss
Copy link
Collaborator

psss commented Dec 12, 2024

Failing test is a network glitch, merging.

@psss psss merged commit ebcf9ff into main Dec 12, 2024
19 of 20 checks passed
@psss psss deleted the tbajer-dnf-cache-error branch December 12, 2024 09:23
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
5 participants