mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 17:50:20 +00:00
parent
6c62792c73
commit
512f61d573
4 changed files with 94 additions and 0 deletions
1
changelog/61100.fixed.md
Normal file
1
changelog/61100.fixed.md
Normal file
|
@ -0,0 +1 @@
|
|||
Fixed state.test does not work with salt-ssh
|
|
@ -1317,3 +1317,18 @@ def single(fun, name, test=None, **kwargs):
|
|||
|
||||
# If for some reason the json load fails, return the stdout
|
||||
return stdout
|
||||
|
||||
|
||||
def test(*args, **kwargs):
|
||||
"""
|
||||
.. versionadded:: 3001
|
||||
|
||||
Alias for `state.apply` with the kwarg `test` forced to `True`.
|
||||
|
||||
This is a nicety to avoid the need to type out `test=True` and the possibility of
|
||||
a typo causing changes you do not intend.
|
||||
"""
|
||||
kwargs["test"] = True
|
||||
ret = apply_(*args, **kwargs)
|
||||
|
||||
return ret
|
||||
|
|
|
@ -25,3 +25,71 @@ def _reap_stray_processes():
|
|||
with reap_stray_processes():
|
||||
# Run test
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def state_tree(base_env_state_tree_root_dir):
|
||||
top_file = """
|
||||
{%- from "map.jinja" import abc with context %}
|
||||
base:
|
||||
'localhost':
|
||||
- basic
|
||||
'127.0.0.1':
|
||||
- basic
|
||||
"""
|
||||
map_file = """
|
||||
{%- set abc = "def" %}
|
||||
"""
|
||||
state_file = """
|
||||
{%- from "map.jinja" import abc with context %}
|
||||
Ok with {{ abc }}:
|
||||
test.succeed_with_changes
|
||||
"""
|
||||
top_tempfile = pytest.helpers.temp_file(
|
||||
"top.sls", top_file, base_env_state_tree_root_dir
|
||||
)
|
||||
map_tempfile = pytest.helpers.temp_file(
|
||||
"map.jinja", map_file, base_env_state_tree_root_dir
|
||||
)
|
||||
state_tempfile = pytest.helpers.temp_file(
|
||||
"test.sls", state_file, base_env_state_tree_root_dir
|
||||
)
|
||||
with top_tempfile, map_tempfile, state_tempfile:
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def state_tree_dir(base_env_state_tree_root_dir):
|
||||
"""
|
||||
State tree with files to test salt-ssh
|
||||
when the map.jinja file is in another directory
|
||||
"""
|
||||
top_file = """
|
||||
{%- from "test/map.jinja" import abc with context %}
|
||||
base:
|
||||
'localhost':
|
||||
- test
|
||||
'127.0.0.1':
|
||||
- test
|
||||
"""
|
||||
map_file = """
|
||||
{%- set abc = "def" %}
|
||||
"""
|
||||
state_file = """
|
||||
{%- from "test/map.jinja" import abc with context %}
|
||||
|
||||
Ok with {{ abc }}:
|
||||
test.succeed_without_changes
|
||||
"""
|
||||
top_tempfile = pytest.helpers.temp_file(
|
||||
"top.sls", top_file, base_env_state_tree_root_dir
|
||||
)
|
||||
map_tempfile = pytest.helpers.temp_file(
|
||||
"test/map.jinja", map_file, base_env_state_tree_root_dir
|
||||
)
|
||||
state_tempfile = pytest.helpers.temp_file(
|
||||
"test.sls", state_file, base_env_state_tree_root_dir
|
||||
)
|
||||
|
||||
with top_tempfile, map_tempfile, state_tempfile:
|
||||
yield
|
||||
|
|
|
@ -101,3 +101,13 @@ def test_state_high(salt_ssh_cli):
|
|||
"""
|
||||
ret = salt_ssh_cli.run("state.high", '{"echo blah": {"cmd": ["run"]}}')
|
||||
assert ret.data["cmd_|-echo blah_|-echo blah_|-run"]["changes"]["stdout"] == "blah"
|
||||
|
||||
|
||||
def test_state_test(salt_ssh_cli, state_tree):
|
||||
ret = salt_ssh_cli.run("state.test", "test")
|
||||
assert ret.returncode == 0
|
||||
assert ret.data
|
||||
assert (
|
||||
ret.data["test_|-Ok with def_|-Ok with def_|-succeed_with_changes"]["result"]
|
||||
is None
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue