Skip to content

Add force option to win_pkg #68205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 3006.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog/68102.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Added the ability to pass for to pkg.install on Windows to force run the
installer
33 changes: 21 additions & 12 deletions salt/modules/win_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,13 @@ def install(name=None, refresh=False, pkgs=None, **kwargs):

.. versionadded:: 2016.11.0

force (bool):
If ``True``, the installation will run whether the package is
already installed or not. If ``False``, the installation will not
run if the correct version of the package is already installed.

.. versionadded:: 3006.15

Returns:
dict: Return a dict containing the new package names and versions. If
the package is already installed, an empty dict is returned.
Expand Down Expand Up @@ -1603,12 +1610,13 @@ def install(name=None, refresh=False, pkgs=None, **kwargs):
# If the version was not passed, version_num will be None
if not version_num:
if pkg_name in old:
log.debug(
"pkg.install: '%s' version '%s' is already installed",
pkg_name,
old[pkg_name][0],
)
continue
if not kwargs.get("force", False):
log.debug(
"pkg.install: '%s' version '%s' is already installed",
pkg_name,
old[pkg_name][0],
)
continue
# Get the most recent version number available from winrepo.p
# May also return `latest` or an empty string
version_num = _get_latest_pkg_version(pkginfo)
Expand All @@ -1621,12 +1629,13 @@ def install(name=None, refresh=False, pkgs=None, **kwargs):
# Check if the version is already installed
if version_num in old.get(pkg_name, []):
# Desired version number already installed
log.debug(
"pkg.install: '%s' version '%s' is already installed",
pkg_name,
version_num,
)
continue
if not kwargs.get("force", False):
log.debug(
"pkg.install: '%s' version '%s' is already installed",
pkg_name,
version_num,
)
continue
# If version number not installed, is the version available?
elif version_num != "latest" and version_num not in pkginfo:
log.error("Version %s not found for package %s", version_num, pkg_name)
Expand Down
23 changes: 23 additions & 0 deletions tests/pytests/unit/modules/test_win_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,29 @@ def test_pkg_install_existing():
assert expected == result


def test_pkg_install_existing_force_true():
"""
test pkg.install when the package is already installed
and force=True
"""
ret_reg = {"Nullsoft Install System": "3.03"}
# The 2nd time it's run, pkg.list_pkgs uses with stringify
se_list_pkgs = {"nsis": ["3.03"]}
with patch.object(win_pkg, "list_pkgs", return_value=se_list_pkgs), patch.object(
win_pkg, "_get_reg_software", return_value=ret_reg
), patch.dict(
win_pkg.__salt__,
{
"cmd.run_all": MagicMock(return_value={"retcode": 0}),
"cp.cache_file": MagicMock(return_value="C:\\fake\\path.exe"),
"cp.is_cached": MagicMock(return_value=True),
},
):
expected = {"nsis": {"install status": "success"}}
result = win_pkg.install(name="nsis", force=True)
assert expected == result


def test_pkg_install_latest():
"""
test pkg.install when the package is already installed
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy