Merge 3006.x into 3007.x

This commit is contained in:
Pedro Algarvio 2024-01-31 13:28:25 +00:00
commit ed2548d52a
No known key found for this signature in database
GPG key ID: BB36BF6584A298FF
9 changed files with 88 additions and 11 deletions

View file

@ -76,10 +76,10 @@ jobs:
- name: Prepare Docs Build
run: |
git clone https://gitlab.com/saltstack/open/docs/builddocs.git .builddocs
git clone https://gitlab.com/saltstack/open/docs/builddocs-fonts.git .builddocs-fonts
sudo mkdir -p /usr/share/fonts/truetype /usr/share/fonts/opentype
sudo cp -rfv .builddocs/builddocs/files/fonts/truetype/*.ttf /usr/share/fonts/truetype/
sudo cp -rfv .builddocs/builddocs/files/fonts/opentype/*.otf /usr/share/fonts/opentype/
sudo cp -rfv .builddocs-fonts/truetype/*.ttf /usr/share/fonts/truetype/
sudo cp -rfv .builddocs-fonts/opentype/*.otf /usr/share/fonts/opentype/
sudo fc-cache -f -v
- name: Build Documentation (${{ matrix.docs-output }})

View file

@ -96,6 +96,7 @@ jobs:
docs:
- added|modified:
- doc/**
- .github/workflows/build-docs.yml
- *doc_requirements
workflows:
- added|modified:

View file

@ -148,6 +148,7 @@ jobs:
docs:
- added|modified:
- doc/**
- .github/workflows/build-docs.yml
- *doc_requirements
workflows:
- added|modified:

View file

@ -138,6 +138,7 @@ jobs:
docs:
- added|modified:
- doc/**
- .github/workflows/build-docs.yml
- *doc_requirements
workflows:
- added|modified:

View file

@ -126,6 +126,7 @@ jobs:
docs:
- added|modified:
- doc/**
- .github/workflows/build-docs.yml
- *doc_requirements
workflows:
- added|modified:

View file

@ -144,6 +144,7 @@ jobs:
docs:
- added|modified:
- doc/**
- .github/workflows/build-docs.yml
- *doc_requirements
workflows:
- added|modified:

View file

@ -0,0 +1 @@
Change module search path priority, so Salt extensions can be overridden by syncable modules and module_dirs. You can switch back to the old logic by setting features.enable_deprecated_module_search_path_priority to true, but it will be removed in Salt 3008.

View file

@ -130,17 +130,18 @@ def _module_dirs(
):
if tag is None:
tag = ext_type
sys_types = os.path.join(base_path or str(SALT_BASE_PATH), int_type or ext_type)
return_types = [sys_types]
if opts.get("extension_modules"):
ext_types = os.path.join(opts["extension_modules"], ext_type)
return_types.insert(0, ext_types)
sys_types = [os.path.join(base_path or str(SALT_BASE_PATH), int_type or ext_type)]
if not sys_types.startswith(SALT_INTERNAL_LOADERS_PATHS):
if opts.get("extension_modules"):
ext_types = [os.path.join(opts["extension_modules"], ext_type)]
else:
ext_types = []
if not sys_types[0].startswith(SALT_INTERNAL_LOADERS_PATHS):
raise RuntimeError(
"{!r} is not considered a salt internal loader path. If this "
"is a new loader being added, please also add it to "
"{}.SALT_INTERNAL_LOADERS_PATHS.".format(sys_types, __name__)
"{}.SALT_INTERNAL_LOADERS_PATHS.".format(sys_types[0], __name__)
)
ext_type_types = []
@ -250,7 +251,17 @@ def _module_dirs(
if os.path.isdir(maybe_dir):
cli_module_dirs.insert(0, maybe_dir)
return cli_module_dirs + ext_type_types + return_types
if opts.get("features", {}).get(
"enable_deprecated_module_search_path_priority", False
):
salt.utils.versions.warn_until(
3008,
"The old module search path priority will be removed in Salt 3008. "
"For more information see https://github.com/saltstack/salt/pull/65938.",
)
return cli_module_dirs + ext_type_types + ext_types + sys_types
else:
return cli_module_dirs + ext_types + ext_type_types + sys_types
def minion_mods(

View file

@ -26,6 +26,66 @@ def venv(tmp_path):
yield _venv
@pytest.fixture
def module_dirs(tmp_path):
module_dir = tmp_path / "module-dir-base"
module_dir.joinpath("modules").mkdir(parents=True)
return [str(module_dir)]
def test_module_dirs_priority(venv, salt_extension, minion_opts, module_dirs):
# Install our extension into the virtualenv
venv.install(str(salt_extension.srcdir))
installed_packages = venv.get_installed_packages()
assert salt_extension.name in installed_packages
code = """
import sys
import json
import salt._logging
import salt.loader
minion_config = json.loads(sys.stdin.read())
salt._logging.set_logging_options_dict(minion_config)
salt._logging.setup_logging()
mod_dirs = salt.loader._module_dirs(minion_config, "modules", "module")
print(json.dumps(mod_dirs))
"""
minion_opts["module_dirs"] = module_dirs
ret = venv.run_code(code, input=json.dumps(minion_opts))
module_dirs_return = json.loads(ret.stdout)
assert len(module_dirs_return) == 5
for i, tail in enumerate(
[
"/module-dir-base/modules",
"/var/cache/salt/minion/extmods/modules",
"/module-dir-base",
"/site-packages/salt_ext_loader_test/modules",
"/site-packages/salt/modules",
]
):
assert module_dirs_return[i].endswith(
tail
), f"{module_dirs_return[i]} does not end with {tail}"
# Test the deprecated mode as well
minion_opts["features"] = {"enable_deprecated_module_search_path_priority": True}
ret = venv.run_code(code, input=json.dumps(minion_opts))
module_dirs_return = json.loads(ret.stdout)
assert len(module_dirs_return) == 5
for i, tail in enumerate(
[
"/module-dir-base/modules",
"/module-dir-base",
"/site-packages/salt_ext_loader_test/modules",
"/var/cache/salt/minion/extmods/modules",
"/site-packages/salt/modules",
]
):
assert module_dirs_return[i].endswith(
tail
), f"{module_dirs_return[i]} does not end with {tail}"
def test_new_entry_points_passing_module(venv, salt_extension, salt_minion_factory):
# Install our extension into the virtualenv
venv.install(str(salt_extension.srcdir))