mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add support for show_jid to salt-run
Adds support for show_jid to the salt-run cli command to match the behaviour of the salt cli command.
This commit is contained in:
parent
b213670518
commit
22b44a8275
3 changed files with 48 additions and 2 deletions
|
@ -30,8 +30,9 @@ class SaltRun(salt.utils.parsers.SaltRunOptionParser):
|
|||
try:
|
||||
if check_user(self.config["user"]):
|
||||
pr = salt.utils.profile.activate_profile(profiling_enabled)
|
||||
show_jid = self.config.get("show_jid", False)
|
||||
try:
|
||||
ret = runner.run(full_return=True)
|
||||
ret = runner.run(full_return=True, show_jid=show_jid)
|
||||
# In older versions ret['data']['retcode'] was used
|
||||
# for signaling the return code. This has been
|
||||
# changed for the orchestrate runner, but external
|
||||
|
|
|
@ -207,7 +207,7 @@ class Runner(RunnerClient):
|
|||
print(docs[fun])
|
||||
|
||||
# TODO: move to mixin whenever we want a salt-wheel cli
|
||||
def run(self, full_return=False):
|
||||
def run(self, full_return=False, show_jid=False):
|
||||
"""
|
||||
Execute the runner sequence
|
||||
"""
|
||||
|
@ -288,6 +288,9 @@ class Runner(RunnerClient):
|
|||
return async_pub["jid"] # return the jid
|
||||
|
||||
# otherwise run it in the main process
|
||||
if show_jid:
|
||||
print(f"jid: {self.jid}")
|
||||
|
||||
if self.opts.get("eauth"):
|
||||
ret = self.cmd_sync(low)
|
||||
if isinstance(ret, dict) and set(ret) == {"data", "outputter"}:
|
||||
|
|
42
tests/pytests/functional/cli/test_salt_run_show_jid.py
Normal file
42
tests/pytests/functional/cli/test_salt_run_show_jid.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
"""
|
||||
Tests for salt-run with show_jid
|
||||
"""
|
||||
|
||||
import logging
|
||||
import re
|
||||
|
||||
import pytest
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def salt_master(salt_factories):
|
||||
"""
|
||||
Salt master with `show_jid: True`
|
||||
"""
|
||||
config_defaults = {
|
||||
"show_jid": True,
|
||||
}
|
||||
salt_master = salt_factories.salt_master_daemon(
|
||||
"salt-run-show-jid-master", defaults=config_defaults
|
||||
)
|
||||
with salt_master.started():
|
||||
yield salt_master
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def salt_run_cli(salt_master):
|
||||
"""
|
||||
The ``salt-run`` CLI as a fixture against the running master
|
||||
"""
|
||||
assert salt_master.is_running()
|
||||
return salt_master.salt_run_cli(timeout=30)
|
||||
|
||||
|
||||
def test_salt_run_show_jid(salt_run_cli):
|
||||
"""
|
||||
Test that jid is output
|
||||
"""
|
||||
ret = salt_run_cli.run("test.stdout_print")
|
||||
assert re.match(r"jid: \d+", ret.stdout)
|
Loading…
Add table
Reference in a new issue