mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 09:40:20 +00:00
Add test for checking pkg.installed/removed with only normalisation
This commit is contained in:
parent
806ebae86e
commit
708238e3a4
1 changed files with 287 additions and 1 deletions
|
@ -3,6 +3,8 @@ import logging
|
|||
import pytest
|
||||
|
||||
import salt.modules.beacons as beaconmod
|
||||
import salt.modules.pkg_resource as pkg_resource
|
||||
import salt.modules.yumpkg as yumpkg
|
||||
import salt.states.beacon as beaconstate
|
||||
import salt.states.pkg as pkg
|
||||
import salt.utils.state as state_utils
|
||||
|
@ -18,7 +20,7 @@ def configure_loader_modules():
|
|||
pkg: {
|
||||
"__env__": "base",
|
||||
"__salt__": {},
|
||||
"__grains__": {"os": "CentOS"},
|
||||
"__grains__": {"os": "CentOS", "os_family": "RedHat"},
|
||||
"__opts__": {"test": False, "cachedir": ""},
|
||||
"__instance_id__": "",
|
||||
"__low__": {},
|
||||
|
@ -26,6 +28,15 @@ def configure_loader_modules():
|
|||
},
|
||||
beaconstate: {"__salt__": {}, "__opts__": {}},
|
||||
beaconmod: {"__salt__": {}, "__opts__": {}},
|
||||
pkg_resource: {
|
||||
"__salt__": {},
|
||||
"__grains__": {"os": "CentOS", "os_family": "RedHat"},
|
||||
},
|
||||
yumpkg: {
|
||||
"__salt__": {},
|
||||
"__grains__": {"osarch": "x86_64", "osmajorrelease": 7},
|
||||
"__opts__": {},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
@ -727,3 +738,278 @@ def test_held_unheld(package_manager):
|
|||
hold_mock.assert_not_called()
|
||||
unhold_mock.assert_any_call(name="held-test", pkgs=["baz"])
|
||||
unhold_mock.assert_any_call(name="held-test", pkgs=["bar"])
|
||||
|
||||
|
||||
def test_installed_with_single_normalize():
|
||||
"""
|
||||
Test pkg.installed with preventing multiple package name normalisation
|
||||
"""
|
||||
|
||||
list_no_weird_installed = {
|
||||
"pkga": "1.0.1",
|
||||
"pkgb": "1.0.2",
|
||||
"pkgc": "1.0.3",
|
||||
}
|
||||
list_no_weird_installed_ver_list = {
|
||||
"pkga": ["1.0.1"],
|
||||
"pkgb": ["1.0.2"],
|
||||
"pkgc": ["1.0.3"],
|
||||
}
|
||||
list_with_weird_installed = {
|
||||
"pkga": "1.0.1",
|
||||
"pkgb": "1.0.2",
|
||||
"pkgc": "1.0.3",
|
||||
"weird-name-1.2.3-1234.5.6.test7tst.x86_64": "20220214-2.1",
|
||||
}
|
||||
list_with_weird_installed_ver_list = {
|
||||
"pkga": ["1.0.1"],
|
||||
"pkgb": ["1.0.2"],
|
||||
"pkgc": ["1.0.3"],
|
||||
"weird-name-1.2.3-1234.5.6.test7tst.x86_64": ["20220214-2.1"],
|
||||
}
|
||||
list_pkgs = MagicMock(
|
||||
side_effect=[
|
||||
# For the package with version specified
|
||||
list_no_weird_installed_ver_list,
|
||||
{},
|
||||
list_no_weird_installed,
|
||||
list_no_weird_installed_ver_list,
|
||||
list_with_weird_installed,
|
||||
list_with_weird_installed,
|
||||
list_with_weird_installed_ver_list,
|
||||
# For the package with no version specified
|
||||
list_no_weird_installed_ver_list,
|
||||
{},
|
||||
list_no_weird_installed,
|
||||
list_no_weird_installed_ver_list,
|
||||
list_with_weird_installed,
|
||||
list_with_weird_installed,
|
||||
list_with_weird_installed_ver_list,
|
||||
]
|
||||
)
|
||||
|
||||
salt_dict = {
|
||||
"pkg.install": yumpkg.install,
|
||||
"pkg.list_pkgs": list_pkgs,
|
||||
"pkg.normalize_name": yumpkg.normalize_name,
|
||||
"pkg_resource.version_clean": pkg_resource.version_clean,
|
||||
"pkg_resource.parse_targets": pkg_resource.parse_targets,
|
||||
}
|
||||
|
||||
with patch("salt.modules.yumpkg.list_pkgs", list_pkgs), patch(
|
||||
"salt.modules.yumpkg.version_cmp", MagicMock(return_value=0)
|
||||
), patch(
|
||||
"salt.modules.yumpkg._call_yum", MagicMock(return_value={"retcode": 0})
|
||||
) as call_yum_mock, patch.dict(
|
||||
pkg.__salt__, salt_dict
|
||||
), patch.dict(
|
||||
pkg_resource.__salt__, salt_dict
|
||||
), patch.dict(
|
||||
yumpkg.__salt__, salt_dict
|
||||
), patch.dict(
|
||||
yumpkg.__grains__, {"os": "CentOS", "osarch": "x86_64", "osmajorrelease": 7}
|
||||
):
|
||||
|
||||
expected = {
|
||||
"weird-name-1.2.3-1234.5.6.test7tst.x86_64": {
|
||||
"old": "",
|
||||
"new": "20220214-2.1",
|
||||
}
|
||||
}
|
||||
ret = pkg.installed(
|
||||
"test_install",
|
||||
pkgs=[{"weird-name-1.2.3-1234.5.6.test7tst.x86_64.noarch": "20220214-2.1"}],
|
||||
)
|
||||
call_yum_mock.assert_called_once()
|
||||
assert (
|
||||
"weird-name-1.2.3-1234.5.6.test7tst.x86_64-20220214-2.1"
|
||||
in call_yum_mock.mock_calls[0].args[0]
|
||||
)
|
||||
assert ret["result"]
|
||||
assert ret["changes"] == expected
|
||||
|
||||
call_yum_mock.reset_mock()
|
||||
|
||||
ret = pkg.installed(
|
||||
"test_install",
|
||||
pkgs=["weird-name-1.2.3-1234.5.6.test7tst.x86_64.noarch"],
|
||||
)
|
||||
call_yum_mock.assert_called_once()
|
||||
assert (
|
||||
"weird-name-1.2.3-1234.5.6.test7tst.x86_64"
|
||||
in call_yum_mock.mock_calls[0].args[0]
|
||||
)
|
||||
assert ret["result"]
|
||||
assert ret["changes"] == expected
|
||||
|
||||
|
||||
def test_removed_with_single_normalize():
|
||||
"""
|
||||
Test pkg.removed with preventing multiple package name normalisation
|
||||
"""
|
||||
|
||||
list_no_weird_installed = {
|
||||
"pkga": "1.0.1",
|
||||
"pkgb": "1.0.2",
|
||||
"pkgc": "1.0.3",
|
||||
}
|
||||
list_no_weird_installed_ver_list = {
|
||||
"pkga": ["1.0.1"],
|
||||
"pkgb": ["1.0.2"],
|
||||
"pkgc": ["1.0.3"],
|
||||
}
|
||||
list_with_weird_installed = {
|
||||
"pkga": "1.0.1",
|
||||
"pkgb": "1.0.2",
|
||||
"pkgc": "1.0.3",
|
||||
"weird-name-1.2.3-1234.5.6.test7tst.x86_64": "20220214-2.1",
|
||||
}
|
||||
list_with_weird_installed_ver_list = {
|
||||
"pkga": ["1.0.1"],
|
||||
"pkgb": ["1.0.2"],
|
||||
"pkgc": ["1.0.3"],
|
||||
"weird-name-1.2.3-1234.5.6.test7tst.x86_64": ["20220214-2.1"],
|
||||
}
|
||||
list_pkgs = MagicMock(
|
||||
side_effect=[
|
||||
# For the package with version specified
|
||||
list_with_weird_installed_ver_list,
|
||||
list_with_weird_installed,
|
||||
list_no_weird_installed,
|
||||
list_no_weird_installed_ver_list,
|
||||
# For the package with no version specified
|
||||
list_with_weird_installed_ver_list,
|
||||
list_with_weird_installed,
|
||||
list_no_weird_installed,
|
||||
list_no_weird_installed_ver_list,
|
||||
]
|
||||
)
|
||||
|
||||
salt_dict = {
|
||||
"pkg.remove": yumpkg.remove,
|
||||
"pkg.list_pkgs": list_pkgs,
|
||||
"pkg.normalize_name": yumpkg.normalize_name,
|
||||
"pkg_resource.parse_targets": pkg_resource.parse_targets,
|
||||
"pkg_resource.version_clean": pkg_resource.version_clean,
|
||||
}
|
||||
|
||||
with patch("salt.modules.yumpkg.list_pkgs", list_pkgs), patch(
|
||||
"salt.modules.yumpkg.version_cmp", MagicMock(return_value=0)
|
||||
), patch(
|
||||
"salt.modules.yumpkg._call_yum", MagicMock(return_value={"retcode": 0})
|
||||
) as call_yum_mock, patch.dict(
|
||||
pkg.__salt__, salt_dict
|
||||
), patch.dict(
|
||||
pkg_resource.__salt__, salt_dict
|
||||
), patch.dict(
|
||||
yumpkg.__salt__, salt_dict
|
||||
):
|
||||
|
||||
expected = {
|
||||
"weird-name-1.2.3-1234.5.6.test7tst.x86_64": {
|
||||
"old": "20220214-2.1",
|
||||
"new": "",
|
||||
}
|
||||
}
|
||||
ret = pkg.removed(
|
||||
"test_remove",
|
||||
pkgs=[{"weird-name-1.2.3-1234.5.6.test7tst.x86_64.noarch": "20220214-2.1"}],
|
||||
)
|
||||
call_yum_mock.assert_called_once()
|
||||
assert (
|
||||
"weird-name-1.2.3-1234.5.6.test7tst.x86_64-20220214-2.1"
|
||||
in call_yum_mock.mock_calls[0].args[0]
|
||||
)
|
||||
assert ret["result"]
|
||||
assert ret["changes"] == expected
|
||||
|
||||
call_yum_mock.reset_mock()
|
||||
|
||||
ret = pkg.removed(
|
||||
"test_remove",
|
||||
pkgs=["weird-name-1.2.3-1234.5.6.test7tst.x86_64.noarch"],
|
||||
)
|
||||
call_yum_mock.assert_called_once()
|
||||
assert (
|
||||
"weird-name-1.2.3-1234.5.6.test7tst.x86_64"
|
||||
in call_yum_mock.mock_calls[0].args[0]
|
||||
)
|
||||
assert ret["result"]
|
||||
assert ret["changes"] == expected
|
||||
|
||||
|
||||
def test_installed_with_single_normalize_32bit():
|
||||
"""
|
||||
Test pkg.installed of 32bit package with preventing multiple package name normalisation
|
||||
"""
|
||||
|
||||
list_no_weird_installed = {
|
||||
"pkga": "1.0.1",
|
||||
"pkgb": "1.0.2",
|
||||
"pkgc": "1.0.3",
|
||||
}
|
||||
list_no_weird_installed_ver_list = {
|
||||
"pkga": ["1.0.1"],
|
||||
"pkgb": ["1.0.2"],
|
||||
"pkgc": ["1.0.3"],
|
||||
}
|
||||
list_with_weird_installed = {
|
||||
"pkga": "1.0.1",
|
||||
"pkgb": "1.0.2",
|
||||
"pkgc": "1.0.3",
|
||||
"xz-devel.i686": "1.2.3",
|
||||
}
|
||||
list_with_weird_installed_ver_list = {
|
||||
"pkga": ["1.0.1"],
|
||||
"pkgb": ["1.0.2"],
|
||||
"pkgc": ["1.0.3"],
|
||||
"xz-devel.i686": ["1.2.3"],
|
||||
}
|
||||
list_pkgs = MagicMock(
|
||||
side_effect=[
|
||||
list_no_weird_installed_ver_list,
|
||||
{},
|
||||
list_no_weird_installed,
|
||||
list_no_weird_installed_ver_list,
|
||||
list_with_weird_installed,
|
||||
list_with_weird_installed,
|
||||
list_with_weird_installed_ver_list,
|
||||
]
|
||||
)
|
||||
|
||||
salt_dict = {
|
||||
"pkg.install": yumpkg.install,
|
||||
"pkg.list_pkgs": list_pkgs,
|
||||
"pkg.normalize_name": yumpkg.normalize_name,
|
||||
"pkg_resource.version_clean": pkg_resource.version_clean,
|
||||
"pkg_resource.parse_targets": pkg_resource.parse_targets,
|
||||
}
|
||||
|
||||
with patch("salt.modules.yumpkg.list_pkgs", list_pkgs), patch(
|
||||
"salt.modules.yumpkg.version_cmp", MagicMock(return_value=0)
|
||||
), patch(
|
||||
"salt.modules.yumpkg._call_yum", MagicMock(return_value={"retcode": 0})
|
||||
) as call_yum_mock, patch.dict(
|
||||
pkg.__salt__, salt_dict
|
||||
), patch.dict(
|
||||
pkg_resource.__salt__, salt_dict
|
||||
), patch.dict(
|
||||
yumpkg.__salt__, salt_dict
|
||||
), patch.dict(
|
||||
yumpkg.__grains__, {"os": "CentOS", "osarch": "x86_64", "osmajorrelease": 7}
|
||||
):
|
||||
|
||||
expected = {
|
||||
"xz-devel.i686": {
|
||||
"old": "",
|
||||
"new": "1.2.3",
|
||||
}
|
||||
}
|
||||
ret = pkg.installed(
|
||||
"test_install",
|
||||
pkgs=["xz-devel.i686"],
|
||||
)
|
||||
call_yum_mock.assert_called_once()
|
||||
assert "xz-devel.i686" in call_yum_mock.mock_calls[0].args[0]
|
||||
assert ret["result"]
|
||||
assert ret["changes"] == expected
|
||||
|
|
Loading…
Add table
Reference in a new issue