-
-
Notifications
You must be signed in to change notification settings - Fork 355
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
Improved RpmPackage is_installed property logic. #759
Improved RpmPackage is_installed property logic. #759
Conversation
@CarstenGrohmann , @philpep since you are the most active collaborators/maintainers, would you mind checking this quick PR? Thanks! |
lgtm, I'd just use f-strings, as testinfra requires Python>=3.9. |
LGTM, also. Please add a small test case. |
testinfra/modules/package.py
Outdated
if result.succeeded: | ||
return True | ||
|
||
if "not installed" in result.stdout or not result.stdout.startswith(self.name): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can be pickier here and make the stdout
match a regex, just to make sure there is actually a package with its version, etc. @philpep What do you think?
@narmaku: I suggest to simplify the test as a corrupt database is not necessary:
|
testinfra/modules/package.py
Outdated
result = self.run("rpm -q --quiet %s 2>&1", self.name) | ||
if result.succeeded: | ||
return True | ||
elif result.failed and result.stdout == '': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: If return code is 1
but there is no output/error, it means the package is not installed
(for that we used --quiet
option).
testinfra/modules/package.py
Outdated
elif result.failed and result.stdout == '': | ||
return False | ||
else: | ||
raise RuntimeError(f"Could not check if RPM package '{self.name}' is installed. {result.stdout}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: If return code is 1
and there is stdout
, that means there was an unexpected error, so we throw a RuntimeError
here. (as we use --quiet
there should not be any output when failing).
This new logic verifies if there is a "not installed" string in the stdout when "rpm -q %s" command returns 1. As seen in bug pytest-dev#758, if rpm command failed because of other reasons (such as database corruption), the old implementation was returning True, making the end-user think that the package was installed, however it was never queried.
Also improved package check logic to be locales agnostic.
ff45060
to
94cb4d5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I modified the test with a corrupted rpmdb and switched back to use run_test().
Merged, thanks! |
This new logic verifies if there is a "not installed" string in the stdout when "rpm -q %s" command returns 1.
As seen in bug #758, if rpm command failed because of other reasons (such as database corruption), the old implementation was returning True, making the end-user think that the package was installed, however it was never queried.