From d0418f68671a2f83e07c1e214b3deed94404d2a1 Mon Sep 17 00:00:00 2001 From: vzhestkov Date: Thu, 20 Jun 2024 16:10:12 +0200 Subject: [PATCH] Use --cachedir parameter for extension_modules with salt-call --- salt/cli/call.py | 11 ++++++++++- salt/config/__init__.py | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/salt/cli/call.py b/salt/cli/call.py index 932dc61681..be3ded77e6 100644 --- a/salt/cli/call.py +++ b/salt/cli/call.py @@ -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): @@ -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: diff --git a/salt/config/__init__.py b/salt/config/__init__.py index 68f2b0f674..b3cd5d85ae 100644 --- a/salt/config/__init__.py +++ b/salt/config/__init__.py @@ -1,6 +1,7 @@ """ All salt configuration loading and defaults should be in this module """ + import codecs import glob import logging @@ -3841,6 +3842,11 @@ def apply_minion_config( _update_ssl_config(opts) _update_discovery_config(opts) + # Store original `cachedir` value, before overriding, + # to make overriding more accurate. + if "__cachedir" not in opts: + opts["__cachedir"] = opts["cachedir"] + return opts