mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 02:00:20 +00:00
Fix issue with refresh_db on Windows
When a new package definition file was added to the repo you had to run refresh_db twice to get it to show up in the package databse. This clears the cache before refreshing the database to force changes.
This commit is contained in:
parent
d09b485c16
commit
176ccd63e3
4 changed files with 62 additions and 2 deletions
2
changelog/63848.fixed.md
Normal file
2
changelog/63848.fixed.md
Normal file
|
@ -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
|
|
@ -47,6 +47,7 @@ import time
|
|||
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
|
||||
`<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`)
|
||||
|
@ -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:
|
||||
|
@ -2363,7 +2369,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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
35
tests/pytests/functional/modules/test_win_pkg.py
Normal file
35
tests/pytests/functional/modules/test_win_pkg.py
Normal file
|
@ -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
|
Loading…
Add table
Reference in a new issue