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

Pass metadata, module_executors and executor_opts to ssh #642

Draft
wants to merge 1 commit into
base: openSUSE/release/3006.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions salt/client/ssh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,7 @@ def __init__(
self.argv = argv

self.fun, self.args, self.kwargs = self.__arg_comps()
self.call_args = self.__get_call_args()
self.id = id_
self.set_path = kwargs.get("set_path", "")

Expand Down Expand Up @@ -1148,6 +1149,21 @@ def __arg_comps(self):
kws = parsed[1]
return fun, args, kws

def __get_call_args(self):
"""
Put extra arguments to the salt-call for the remote client.
"""
call_args = []
args_list = (
("module_executors", "--module-executors"),
("executor_opts", "--executor-opts"),
("metadata", "--set-metadata"),
)
for src, dst in args_list:
if src in self.opts:
call_args.append(f"{dst}={self.opts[src]}")
return call_args if call_args else None

def _escape_arg(self, arg):
"""
Properly escape argument to protect special characters from shell
Expand Down Expand Up @@ -1509,6 +1525,7 @@ def _cmd_str(self):
OPTIONS.tty = {tty}
OPTIONS.cmd_umask = {cmd_umask}
OPTIONS.code_checksum = {code_checksum}
CALL_ARGS = {call_args}
ARGS = {arguments}\n'''.format(
config=self.minion_config,
delimeter=RSTR,
Expand All @@ -1521,6 +1538,7 @@ def _cmd_str(self):
tty=self.tty,
cmd_umask=self.cmd_umask,
code_checksum=thin_code_digest,
call_args=self.call_args,
arguments=self.argv,
)
py_code = SSH_PY_SHIM.replace("#%%OPTS", arg_str)
Expand Down
5 changes: 4 additions & 1 deletion salt/client/ssh/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ def sanitize_kwargs(self, kwargs):
("ssh_run_pre_flight", bool),
("no_host_keys", bool),
("saltfile", str),
("module_executors", list),
("executor_opts", dict),
("metadata", dict),
]
sane_kwargs = {}
for name, kind in roster_vals:
Expand All @@ -92,7 +95,7 @@ def sanitize_kwargs(self, kwargs):
except ValueError:
log.warning("Unable to cast kwarg %s", name)
continue
if kind is bool or kind is int:
if kind in (bool, int, dict):
sane_kwargs[name] = val
elif kind is str:
if val.find("ProxyCommand") != -1:
Expand Down
8 changes: 7 additions & 1 deletion salt/client/ssh/ssh_py_shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class OptionsContainer:


OPTIONS = OptionsContainer()
CALL_ARGS = None
ARGS = None
# The below line is where OPTIONS can be redefined with internal options
# (rather than cli arguments) when the shim is bundled by
Expand Down Expand Up @@ -284,13 +285,13 @@ def main(argv): # pylint: disable=W0613
# VIRTUAL_ENV environment variable is defined by venv-salt-minion wrapper
# it's used to check if the shim is running under this wrapper
venv_salt_call = None
cache_dir = os.path.join(OPTIONS.saltdir, "running_data", "var", "cache")
if virt_env and "venv-salt-minion" in virt_env:
venv_salt_call = os.path.join(virt_env, "bin", "salt-call")
if not os.path.exists(venv_salt_call):
venv_salt_call = None
elif not os.path.exists(OPTIONS.saltdir):
os.makedirs(OPTIONS.saltdir)
cache_dir = os.path.join(OPTIONS.saltdir, "running_data", "var", "cache")
os.makedirs(os.path.join(cache_dir, "salt"))
os.symlink(
"salt", os.path.relpath(os.path.join(cache_dir, "venv-salt-minion"))
Expand Down Expand Up @@ -401,6 +402,8 @@ def main(argv): # pylint: disable=W0613
"quiet",
"-c",
OPTIONS.saltdir,
"--cachedir",
cache_dir,
]

try:
Expand All @@ -409,6 +412,9 @@ def main(argv): # pylint: disable=W0613
except (IndexError, TypeError):
pass

if CALL_ARGS and isinstance(CALL_ARGS, list):
salt_argv.extend(CALL_ARGS)

salt_argv.append("--")
salt_argv.extend(argv_prepared)

Expand Down
7 changes: 7 additions & 0 deletions salt/utils/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3201,6 +3201,7 @@ def setup_config(self):
class SaltSSHOptionParser(
OptionParser,
ConfigDirMixIn,
ExecutorsMixIn,
MergeConfigMixIn,
LogLevelMixIn,
TargetOptionsMixIn,
Expand Down Expand Up @@ -3369,6 +3370,12 @@ def _mixin_setup(self):
dest="ssh_run_pre_flight",
help="Run the defined ssh_pre_flight script in the roster",
)
self.add_option(
"--metadata",
default="",
metavar="METADATA",
help="Pass metadata into Salt, used to search jobs.",
)

ssh_group = optparse.OptionGroup(
self, "SSH Options", "Parameters for the SSH client."
Expand Down