Skip to content

Improved RpmPackage is_installed property logic. #759

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

Merged
merged 8 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions test/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ def test_held_package(host):
assert python.version.startswith("3.11.")


@pytest.mark.destructive
@pytest.mark.testinfra_hosts("docker://rockylinux9")
def test_rpmdb_corrupted(host):
host.check_output("dd if=/dev/zero of=/var/lib/rpm/rpmdb.sqlite bs=1024 count=1")
with pytest.raises(RuntimeError) as excinfo:
host.package("zsh").is_installed
assert (
"Could not check if RPM package 'zsh' is installed. error: sqlite failure:"
) in str(excinfo.value)


@pytest.mark.testinfra_hosts("docker://rockylinux9")
def test_non_default_package_tool(host):
# Make non default pkg tool binary present
Expand Down
10 changes: 9 additions & 1 deletion testinfra/modules/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,15 @@ def version(self):
class RpmPackage(Package):
@property
def is_installed(self):
return self.run_test("rpm -q %s", self.name).rc == 0
result = self.run_test("rpm -q --quiet %s 2>&1", self.name)
if result.succeeded:
return True
elif result.failed and result.stdout == "":
return False
else:
raise RuntimeError(
f"Could not check if RPM package '{self.name}' is installed. {result.stdout}"
)

@property
def version(self):
Expand Down