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

[3006.x] rpm doenst need to check digest and signing when listing packages #65172

Merged
merged 1 commit into from
Sep 12, 2023
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
1 change: 1 addition & 0 deletions changelog/65152.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
speed up yumpkg list_pkgs by not requiring digest or signature verification on lookup.
2 changes: 2 additions & 0 deletions salt/modules/yumpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,8 @@ def list_pkgs(versions_as_list=False, **kwargs):
cmd = [
"rpm",
"-qa",
"--nodigest",
"--nosignature",
"--queryformat",
salt.utils.pkg.rpm.QUERYFORMAT.replace("%{REPOID}", "(none)") + "\n",
]
Expand Down
41 changes: 41 additions & 0 deletions tests/pytests/functional/modules/test_yumpkg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import pytest

import salt.modules.cmdmod
import salt.modules.pkg_resource
import salt.modules.yumpkg
import salt.utils.pkg.rpm


@pytest.fixture
def configure_loader_modules(minion_opts):
return {
salt.modules.yumpkg: {
"__salt__": {
"cmd.run": salt.modules.cmdmod.run,
"pkg_resource.add_pkg": salt.modules.pkg_resource.add_pkg,
"pkg_resource.format_pkg_list": salt.modules.pkg_resource.format_pkg_list,
},
"__grains__": {"osarch": salt.utils.pkg.rpm.get_osarch()},
},
}


@pytest.mark.slow_test
def test_yum_list_pkgs(grains):
"""
compare the output of rpm -qa vs the return of yumpkg.list_pkgs,
make sure that any changes to ympkg.list_pkgs still returns.
"""

if grains["os_family"] != "RedHat":
pytest.skip("Skip if not RedHat")
cmd = [
"rpm",
"-qa",
"--queryformat",
"%{NAME}\n",
]
known_pkgs = salt.modules.cmdmod.run(cmd, python_shell=False)
listed_pkgs = salt.modules.yumpkg.list_pkgs()
for line in known_pkgs.splitlines():
assert any(line in d for d in listed_pkgs)
15 changes: 14 additions & 1 deletion tests/pytests/unit/modules/test_yumpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ def _add_data(data, key, value):
"openssh_|-(none)_|-6.6.1p1_|-33.el7_3_|-x86_64_|-(none)_|-1487838485",
"virt-what_|-(none)_|-1.13_|-8.el7_|-x86_64_|-(none)_|-1487838486",
]
cmd_mod = MagicMock(return_value=os.linesep.join(rpm_out))
with patch.dict(yumpkg.__grains__, {"osarch": "x86_64"}), patch.dict(
yumpkg.__salt__,
{"cmd.run": MagicMock(return_value=os.linesep.join(rpm_out))},
{"cmd.run": cmd_mod},
), patch.dict(yumpkg.__salt__, {"pkg_resource.add_pkg": _add_data}), patch.dict(
yumpkg.__salt__,
{"pkg_resource.format_pkg_list": pkg_resource.format_pkg_list},
Expand All @@ -147,6 +148,18 @@ def _add_data(data, key, value):
}.items():
assert pkgs.get(pkg_name) is not None
assert pkgs[pkg_name] == [pkg_version]
cmd_mod.assert_called_once_with(
[
"rpm",
"-qa",
"--nodigest",
"--nosignature",
"--queryformat",
"%{NAME}_|-%{EPOCH}_|-%{VERSION}_|-%{RELEASE}_|-%{ARCH}_|-(none)_|-%{INSTALLTIME}\n",
],
output_loglevel="trace",
python_shell=False,
)


def test_list_pkgs_no_context():
Expand Down
Loading