diff --git a/changelog/65008.added.md b/changelog/65008.added.md new file mode 100644 index 000000000000..2e8b5adec5e1 --- /dev/null +++ b/changelog/65008.added.md @@ -0,0 +1,3 @@ +Add support for show_jid to salt-run + +Adds support for show_jid master config option to salt-run, so its behaviour matches the salt cli command. diff --git a/salt/runner.py b/salt/runner.py index d3501b8f9190..d606cb485104 100644 --- a/salt/runner.py +++ b/salt/runner.py @@ -288,6 +288,9 @@ def run(self, full_return=False): return async_pub["jid"] # return the jid # otherwise run it in the main process + if self.opts.get("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"}: diff --git a/tests/pytests/functional/cli/test_salt_run_show_jid.py b/tests/pytests/functional/cli/test_salt_run_show_jid.py new file mode 100644 index 000000000000..3fdfe9fb91ae --- /dev/null +++ b/tests/pytests/functional/cli/test_salt_run_show_jid.py @@ -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)