Skip to content
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
1 change: 1 addition & 0 deletions changelog/66742.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use `--cachedir` parameter for setting `extension_modules` with salt-call.
11 changes: 10 additions & 1 deletion salt/cli/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import salt.cli.caller
import salt.defaults.exitcodes
import salt.utils.parsers
from salt.config import _expand_glob_path
from salt.config import _expand_glob_path, prepend_root_dir


class SaltCall(salt.utils.parsers.SaltCallOptionParser):
Expand Down Expand Up @@ -37,6 +37,15 @@ def run(self):
if self.options.master:
self.config["master"] = self.options.master

if self.options.cachedir and self.config.get(
"extension_modules"
) == os.path.join(self.config.get("__cachedir"), "extmods"):
# Override `extension_modules`, but only in case if it was autogenerated
cache_dir = os.path.abspath(self.options.cachedir)
self.config["cachedir"] = cache_dir
self.config["extension_modules"] = os.path.join(cache_dir, "extmods")
prepend_root_dir(self.config, ["cachedir", "extension_modules"])

caller = salt.cli.caller.Caller.factory(self.config)

if self.options.doc:
Expand Down
5 changes: 5 additions & 0 deletions salt/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3899,6 +3899,11 @@ def apply_minion_config(
f"Please specify one of {','.join(salt.crypt.VALID_SIGNING_ALGORITHMS)}."
)

# Store original `cachedir` value, before overriding,
# to make overriding more accurate.
if "__cachedir" not in opts:
opts["__cachedir"] = opts["cachedir"]

return opts


Expand Down
32 changes: 32 additions & 0 deletions tests/pytests/unit/cli/test_salt_call.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os

from salt.cli.call import SaltCall
from tests.support.mock import MagicMock, patch


def test_passing_cachedir_to_extension_modules(temp_salt_minion):
"""
Test passing `cachedir` CLI parameter to `extension_modules` opts
"""
test_cache_dir = os.path.join(temp_salt_minion.config["root_dir"], "new_cache_tmp")
with patch(
"sys.argv",
[
"salt-call",
"--local",
"--config-dir",
temp_salt_minion.config["root_dir"],
"--cachedir",
test_cache_dir,
"test.true",
],
), patch("salt.utils.verify.verify_files", MagicMock()), patch(
"salt._logging.impl.setup_logfile_handler", MagicMock()
):
salt_call = SaltCall()
with patch("salt.cli.caller.Caller.factory", MagicMock()) as caller_mock:
salt_call.run()
assert salt_call.config["cachedir"] == test_cache_dir
assert salt_call.config["extension_modules"] == os.path.join(
test_cache_dir, "extmods"
)