Skip to content

Commit

Permalink
Add names and pkgs parameters to zypper.upgrade
Browse files Browse the repository at this point in the history
Fixes saltstack/salt#62030

(cherry picked from commit 19ebb40dc4538c983721a8746a201b7f1300c2f7)
  • Loading branch information
agraul committed Jun 14, 2022
1 parent f7ee5f4 commit 8269868
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog/62030.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix inconsitency regarding name and pkgs parameters between zypperpkg.upgrade() and yumpkg.upgrade()
35 changes: 35 additions & 0 deletions salt/modules/zypperpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,8 @@ def install(


def upgrade(
name=None,
pkgs=None,
refresh=True,
dryrun=False,
dist_upgrade=False,
Expand Down Expand Up @@ -1821,6 +1823,27 @@ def upgrade(
Run a full system upgrade, a zypper upgrade
name
The name of the package to be installed. Note that this parameter is
ignored if ``pkgs`` is passed or if ``dryrun`` is set to True.
CLI Example:
.. code-block:: bash
salt '*' pkg.install name=<package name>
pkgs
A list of packages to install from a software repository. Must be
passed as a python list. Note that this parameter is ignored if
``dryrun`` is set to True.
CLI Examples:
.. code-block:: bash
salt '*' pkg.install pkgs='["foo", "bar"]'
refresh
force a refresh if set to True (default).
If set to False it depends on zypper if a refresh is
Expand Down Expand Up @@ -1899,6 +1922,18 @@ def upgrade(
allowvendorchange, novendorchange
).noraise.call(*cmd_update + ["--debug-solver"])

if not dist_upgrade:
if name or pkgs:
try:
(pkg_params, _) = __salt__["pkg_resource.parse_targets"](
name=name, pkgs=pkgs, sources=None, **kwargs
)
if pkg_params:
cmd_update.extend(pkg_params.keys())

except MinionError as exc:
raise CommandExecutionError(exc)

old = list_pkgs(root=root)
__zypper__(systemd_scope=_systemd_scope(), root=root).allow_vendor_change(
allowvendorchange, novendorchange
Expand Down
23 changes: 17 additions & 6 deletions tests/pytests/unit/modules/test_zypperpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ def configure_loader_modules():
"rpm": None,
"_systemd_scope": MagicMock(return_value=False),
"osrelease_info": [15, 3],
"__salt__": {"pkg_resource.parse_targets": pkg_resource.parse_targets},
},
pkg_resource: {},
pkg_resource: {"__grains__": {"os": "SUSE"}},
}


Expand Down Expand Up @@ -330,14 +331,17 @@ def test_allow_vendor_change(


@pytest.mark.parametrize(
"package,pre_version,post_version,fromrepo_param",
"package,pre_version,post_version,fromrepo_param,name_param,pkgs_param",
[
("vim", "1.1", "1.2", []),
("kernel-default", "1.1", "1.1,1.2", ["dummy", "dummy2"]),
("vim", "1.1", "1.2", [], "", []),
("kernel-default", "1.1", "1.1,1.2", ["dummy", "dummy2"], "", []),
("vim", "1.1", "1.2", [], "vim", []),
],
)
@patch.object(zypper, "refresh_db", MagicMock(return_value=True))
def test_upgrade(package, pre_version, post_version, fromrepo_param):
def test_upgrade(
package, pre_version, post_version, fromrepo_param, name_param, pkgs_param
):
with patch(
"salt.modules.zypperpkg.__zypper__.noraise.call"
) as zypper_mock, patch.object(
Expand All @@ -349,7 +353,14 @@ def test_upgrade(package, pre_version, post_version, fromrepo_param):
for repo in fromrepo_param:
expected_call.extend(["--repo", repo])

result = zypper.upgrade(fromrepo=fromrepo_param)
if pkgs_param:
expected_call.extend(pkgs_param)
elif name_param:
expected_call.append(name_param)

result = zypper.upgrade(
name=name_param, pkgs=pkgs_param, fromrepo=fromrepo_param
)
zypper_mock.assert_any_call(*expected_call)
assert result == {package: {"old": pre_version, "new": post_version}}

Expand Down

0 comments on commit 8269868

Please sign in to comment.