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

[master] Add support for show_jid to salt-run #65008

Merged
merged 4 commits into from
Oct 17, 2023
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
3 changes: 3 additions & 0 deletions changelog/65008.added.md
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions salt/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}:
Expand Down
42 changes: 42 additions & 0 deletions tests/pytests/functional/cli/test_salt_run_show_jid.py
Original file line number Diff line number Diff line change
@@ -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)