Skip to content

Commit

Permalink
Add names and pkgs parameters to zypper.upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
agraul authored and Megan Wilhite committed Oct 6, 2022
1 parent ac3fcb7 commit 183a9ac
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
34 changes: 34 additions & 0 deletions src/saltext/zypper/modules/zypperpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1744,6 +1744,8 @@ def install(


def upgrade(
name=None,
pkgs=None,
refresh=True,
dryrun=False,
dist_upgrade=False,
Expand Down Expand Up @@ -1771,6 +1773,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 @@ -1855,6 +1878,17 @@ def upgrade(
__zypper__(systemd_scope=_systemd_scope(), root=root).noraise.call(
*cmd_update + ["--debug-solver"]
)
else:
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)

Expand Down
23 changes: 17 additions & 6 deletions tests/unit/modules/test_zypperpkg_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,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 @@ -224,14 +225,17 @@ def zypper_search_mock(name, *_args, **_kwargs):


@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 @@ -243,7 +247,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 183a9ac

Please sign in to comment.