mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #62019 from meaksh/master-fix-issue-targeting-duplicated-package-names
Make Salt to return an error on "pkg" modules and states when targeting duplicated package names
This commit is contained in:
commit
c678a1bb85
3 changed files with 25 additions and 1 deletions
1
changelog/62019.fixed
Normal file
1
changelog/62019.fixed
Normal file
|
@ -0,0 +1 @@
|
|||
Make Salt to return an error on "pkg" modules and states when targeting duplicated package names
|
|
@ -27,11 +27,22 @@ def _repack_pkgs(pkgs, normalize=True):
|
|||
_normalize_name = __salt__["pkg.normalize_name"]
|
||||
else:
|
||||
_normalize_name = lambda pkgname: pkgname
|
||||
return {
|
||||
|
||||
repacked_pkgs = {
|
||||
_normalize_name(str(x)): str(y) if y is not None else y
|
||||
for x, y in salt.utils.data.repack_dictlist(pkgs).items()
|
||||
}
|
||||
|
||||
# Check if there were collisions in names
|
||||
if len(pkgs) != len(repacked_pkgs):
|
||||
raise SaltInvocationError(
|
||||
"You are passing a list of packages that contains duplicated packages names: {}. This cannot be processed. In case you are targeting different versions of the same package, please target them individually".format(
|
||||
pkgs
|
||||
)
|
||||
)
|
||||
|
||||
return repacked_pkgs
|
||||
|
||||
|
||||
def pack_sources(sources, normalize=True):
|
||||
"""
|
||||
|
|
|
@ -8,6 +8,7 @@ import yaml
|
|||
import salt.modules.pkg_resource as pkg_resource
|
||||
import salt.utils.data
|
||||
import salt.utils.yaml
|
||||
from salt.exceptions import SaltInvocationError
|
||||
from tests.support.mock import MagicMock, patch
|
||||
|
||||
|
||||
|
@ -224,6 +225,17 @@ def test_format_pkg_list_with_attr():
|
|||
assert sorted(pkgs) == sorted(expected_pkg_list)
|
||||
|
||||
|
||||
def test_repack_pkgs():
|
||||
"""
|
||||
Test to check that repack function is raising error in case of
|
||||
package name collisions
|
||||
"""
|
||||
assert pkg_resource._repack_pkgs([{"A": "a"}])
|
||||
assert pkg_resource._repack_pkgs([{"A": "a"}, {"B": "b"}])
|
||||
with pytest.raises(SaltInvocationError):
|
||||
assert pkg_resource._repack_pkgs([{"A": "a"}, {"A": "c"}])
|
||||
|
||||
|
||||
def test_stringify():
|
||||
"""
|
||||
Test to takes a dict of package name/version information
|
||||
|
|
Loading…
Add table
Reference in a new issue