mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
rpm doenst need to check digest and signing when listing packages
This commit is contained in:
parent
d337303731
commit
2475f4fd14
4 changed files with 58 additions and 1 deletions
1
changelog/65152.fixed.md
Normal file
1
changelog/65152.fixed.md
Normal file
|
@ -0,0 +1 @@
|
|||
speed up yumpkg list_pkgs by not requiring digest or signature verification on lookup.
|
|
@ -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",
|
||||
]
|
||||
|
|
41
tests/pytests/functional/modules/test_yumpkg.py
Normal file
41
tests/pytests/functional/modules/test_yumpkg.py
Normal file
|
@ -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)
|
|
@ -118,9 +118,10 @@ def test_list_pkgs():
|
|||
"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},
|
||||
|
@ -147,6 +148,18 @@ def test_list_pkgs():
|
|||
}.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():
|
||||
|
|
Loading…
Add table
Reference in a new issue