diff --git a/changelog/63848.fixed.md b/changelog/63848.fixed.md new file mode 100644 index 000000000000..d297d7a3467a --- /dev/null +++ b/changelog/63848.fixed.md @@ -0,0 +1,2 @@ +Fixes an issue in pkg.refresh_db on Windows where new package definition +files were not being picked up on the first run diff --git a/salt/modules/win_pkg.py b/salt/modules/win_pkg.py index aff40b3d54d2..c15f11f449de 100644 --- a/salt/modules/win_pkg.py +++ b/salt/modules/win_pkg.py @@ -47,6 +47,7 @@ import urllib.parse from functools import cmp_to_key +import salt.fileserver import salt.payload import salt.syspaths import salt.utils.args @@ -915,7 +916,7 @@ def refresh_db(**kwargs): - Fetch the package definition files (.sls) from `winrepo_source_dir` (default `salt://win/repo-ng`) and cache them in `\files\\` - (default: ``C:\salt\var\cache\salt\minion\files\base\win\repo-ng``) + (default: ``C:\ProgramData\Salt Project\Salt\var\cache\salt\minion\files\base\win\repo-ng``) - Call :py:func:`pkg.genrepo ` to parse the package definition files and generate the repository metadata database file (`winrepo.p`) @@ -1020,6 +1021,11 @@ def refresh_db(**kwargs): "Failed to clear one or more winrepo cache files", info={"failed": failed} ) + # Clear the cache so that newly copied package definitions will be picked up + fileserver = salt.fileserver.Fileserver(__opts__) + load = {"saltenv": saltenv, "fsbackend": None} + fileserver.clear_file_list_cache(load=load) + # Cache repo-ng locally log.info("Fetching *.sls files from %s", repo_details.winrepo_source_dir) try: @@ -2359,7 +2365,23 @@ def _get_name_map(saltenv="base"): def get_package_info(name, saltenv="base"): """ - Return package info. Returns empty map if package not available. + Get information about the package as found in the winrepo database + + Args: + + name (str): The name of the package + + saltenv (str): The salt environment to use. Default is "base" + + Returns: + dict: A dictionary of package info, empty if package not available + + CLI Example: + + .. code-block:: bash + + salt '*' pkg.get_package_info chrome + """ return _get_package_info(name=name, saltenv=saltenv) diff --git a/tests/filename_map.yml b/tests/filename_map.yml index ded66d324101..d4a2143d3be0 100644 --- a/tests/filename_map.yml +++ b/tests/filename_map.yml @@ -17,6 +17,7 @@ salt/_logging/(impl|handlers).py: salt/modules/(apkpkg|aptpkg|ebuildpkg|dpkg_lowpkg|freebsdpkg|mac_brew_pkg|mac_ports_pkg|openbsdpkg|opkg|pacmanpkg|pkgin|pkgng|pkg_resource|rpm_lowpkg|solarisipspkg|solarispkg|win_pkg|xbpspkg|yumpkg|zypperpkg)\.py: - pytests.unit.states.test_pkg - pytests.functional.modules.test_pkg + - pytests.functional.modules.test_win_pkg - pytests.functional.states.test_pkg - pytests.functional.states.pkgrepo.test_centos - pytests.functional.states.pkgrepo.test_debian diff --git a/tests/pytests/functional/modules/test_win_pkg.py b/tests/pytests/functional/modules/test_win_pkg.py new file mode 100644 index 000000000000..b68895ef6253 --- /dev/null +++ b/tests/pytests/functional/modules/test_win_pkg.py @@ -0,0 +1,35 @@ +import pytest + +pytestmark = [ + pytest.mark.windows_whitelisted, + pytest.mark.skip_unless_on_windows, + pytest.mark.slow_test, +] + + +@pytest.fixture(scope="module") +def pkg_def_contents(state_tree): + return r""" + my-software: + '1.0.1': + full_name: 'My Software' + installer: 'C:\files\mysoftware.msi' + install_flags: '/qn /norestart' + uninstaller: 'C:\files\mysoftware.msi' + uninstall_flags: '/qn /norestart' + msiexec: True + reboot: False + """ + + +@pytest.fixture(scope="module") +def pkg(modules): + yield modules.pkg + + +def test_refresh_db(pkg, pkg_def_contents, state_tree, minion_opts): + assert len(pkg.get_package_info("my-software")) == 0 + repo_dir = state_tree / "win" / "repo-ng" + with pytest.helpers.temp_file("my-software.sls", pkg_def_contents, repo_dir): + pkg.refresh_db() + assert len(pkg.get_package_info("my-software")) == 1 diff --git a/tools/precommit/docstrings.py b/tools/precommit/docstrings.py index b26f8b1a954c..665b171fd64e 100644 --- a/tools/precommit/docstrings.py +++ b/tools/precommit/docstrings.py @@ -751,7 +751,6 @@ "delete_advanced_configs", "get_vm", ], - "salt/modules/win_pkg.py": ["get_package_info"], "salt/modules/win_timezone.py": ["zone_compare"], "salt/modules/zk_concurrency.py": [ "lock",