Skip to content
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

[3006.x] Fix issue with refresh_db on Windows #66184

Merged
merged 2 commits into from
Mar 11, 2024
Merged
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/63848.fixed.md
Original file line number Diff line number Diff line change
@@ -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
26 changes: 24 additions & 2 deletions salt/modules/win_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
`<cachedir>\files\<saltenv>\<winrepo_source_dir>`
(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 <salt.modules.win_pkg.genrepo>` to parse the
package definition files and generate the repository metadata database
file (`winrepo.p`)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions tests/filename_map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions tests/pytests/functional/modules/test_win_pkg.py
Original file line number Diff line number Diff line change
@@ -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):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def pkg_def_contents(state_tree):
def pkg_def_contents():

Not using the fixture

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be fixed at another time, it's not a real problem.

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
1 change: 0 additions & 1 deletion tools/precommit/docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading