Skip to content

Commit

Permalink
Merge pull request saltstack#58953 from erwindon/fixterse
Browse files Browse the repository at this point in the history
fix formatting for terse output mode
  • Loading branch information
garethgreenaway authored Nov 14, 2022
2 parents 1e1811e + b246cd2 commit 1736155
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/58953.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed formatting for terse output mode
2 changes: 1 addition & 1 deletion salt/output/highstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ def _format_terse(tcolor, comps, ret, colors, tabular):
)
fmt_string += " {0} Name: {1} - Function: {2}.{3} - Result: {4}"
if __opts__.get("state_output_profile") and "start_time" in ret:
fmt_string += " Started: - {6[start_time]!s} Duration: {6[duration]!s} ms"
fmt_string += " - Started: {6[start_time]!s} - Duration: {6[duration]!s} ms"
fmt_string += "{5}"

msg = fmt_string.format(
Expand Down
87 changes: 87 additions & 0 deletions tests/pytests/unit/output/test_highstate_terse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import logging
import re

import pytest

import salt.config
import salt.output.highstate as highstate

log = logging.getLogger(__name__)


@pytest.fixture
def configure_loader_modules():
minion_opts = salt.config.DEFAULT_MINION_OPTS.copy()
overrides = {
"extension_modules": "",
"optimization_order": [0, 1, 2],
"color": False,
"state_output_pct": True,
"state_output": "terse",
}
minion_opts.update(overrides)
return {highstate: {"__opts__": minion_opts}}


def test_terse_output():
nested_data = {
"outputter": "highstate",
"state_output": "terse",
"data": {
"local_master": {
"salt_|-nested_|-state.orchestrate_|-runner": {
"comment": "Runner function 'state.orchestrate' executed.",
"name": "state.orchestrate",
"__orchestration__": True,
"start_time": "09:22:53.158742",
"result": True,
"duration": 980.694,
"__run_num__": 0,
"__jid__": "20180326092253538853",
"__sls__": "orch.test.nested",
"changes": {
"return": {
"outputter": "highstate",
"data": {
"local_master": {
"test_|-always-passes-with-changes_|-oinaosf_|-succeed_with_changes": {
"comment": "Success!",
"name": "oinaosf",
"start_time": "09:22:54.128415",
"result": True,
"duration": 0.437,
"__run_num__": 0,
"__sls__": "orch.test.changes",
"changes": {
"testing": {
"new": (
"Something pretended to change"
),
"old": "Unchanged",
}
},
"__id__": "always-passes-with-changes",
}
}
},
"retcode": 0,
}
},
"__id__": "nested",
}
}
},
"retcode": 0,
}

ret = highstate.output(nested_data)
# test whether we have at least the normal output
assert "Succeeded: 1 (changed=1)" in ret
# test whether the TERSE output is correct
assert (
re.search(
"Name: state[.]orchestrate - Function: salt[.]runner - Result: Changed - Started: [0-2][0-9]:[0-5][0-9]:[0-5][0-9]([.][0-9][0-9]*)? - Duration: [1-9][0-9]*([.][0-9][0-9]*)? ms",
ret,
)
is not None
)

0 comments on commit 1736155

Please sign in to comment.