From 98ecf8d45cf7dbc7d534d04226bb4beae5e448fd Mon Sep 17 00:00:00 2001 From: nicholasmhughes Date: Mon, 24 Apr 2023 14:53:22 -0400 Subject: [PATCH] fixes saltstack/salt#64150 cmd.run doesn't output changes in test mode --- changelog/64150.fixed.md | 1 + salt/states/cmd.py | 1 + tests/pytests/unit/states/test_cmd.py | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 changelog/64150.fixed.md diff --git a/changelog/64150.fixed.md b/changelog/64150.fixed.md new file mode 100644 index 00000000000..a767e10bf8d --- /dev/null +++ b/changelog/64150.fixed.md @@ -0,0 +1 @@ +Fix cmd.run doesn't output changes in test mode diff --git a/salt/states/cmd.py b/salt/states/cmd.py index 2df04807ce3..5a859c8092c 100644 --- a/salt/states/cmd.py +++ b/salt/states/cmd.py @@ -849,6 +849,7 @@ def run( if __opts__["test"] and not test_name: ret["result"] = None ret["comment"] = 'Command "{}" would have been executed'.format(name) + ret["changes"] = {"cmd": name} return _reinterpreted_state(ret) if stateful else ret if cwd and not os.path.isdir(cwd): diff --git a/tests/pytests/unit/states/test_cmd.py b/tests/pytests/unit/states/test_cmd.py index 682ee621e7d..4a839c2f91a 100644 --- a/tests/pytests/unit/states/test_cmd.py +++ b/tests/pytests/unit/states/test_cmd.py @@ -77,7 +77,9 @@ def test_run(): with patch.dict(cmd.__opts__, {"test": True}): comt = 'Command "cmd.script" would have been executed' - ret.update({"comment": comt, "result": None, "changes": {}}) + ret.update( + {"comment": comt, "result": None, "changes": {"cmd": "cmd.script"}} + ) assert cmd.run(name) == ret