"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tests/pytests/integration/states/test_idem.py" between
salt-3002.1.tar.gz and salt-3002.2.tar.gz

About: SaltStack is a systems management software for data center automation, cloud orchestration, server provisioning, configuration management and more. Community version.

test_idem.py  (salt-3002.1):test_idem.py  (salt-3002.2)
""" """
Tests for the idem state Tests for the idem state
""" """
import tempfile import tempfile
from contextlib import contextmanager from contextlib import contextmanager
import pytest import pytest
import salt.state
import salt.utils.idem as idem import salt.utils.idem as idem
import salt.utils.path import salt.utils.path
import tests.support.sminion
pytestmark = pytest.mark.skipif(not idem.HAS_POP[0], reason=idem.HAS_POP[1]) pytestmark = pytest.mark.skipif(not idem.HAS_POP[0], reason=idem.HAS_POP[1])
@pytest.mark.skipif(not salt.utils.path.which("idem"), reason="idem is not insta lled")
@contextmanager @contextmanager
def test_state(salt_call_cli): def test_state(salt_call_cli):
with tempfile.NamedTemporaryFile(suffix=".sls", delete=True, mode="w+") as f h: with tempfile.NamedTemporaryFile(suffix=".sls", delete=True, mode="w+") as f h:
sls_succeed_without_changes = """ sls_succeed_without_changes = """
state_name: state_name:
test.succeed_without_changes: test.succeed_without_changes:
- name: idem_test - name: idem_test
- foo: bar - foo: bar
""" """
fh.write(sls_succeed_without_changes) fh.write(sls_succeed_without_changes)
fh.flush() fh.flush()
ret = salt_call_cli.run( ret = salt_call_cli.run(
"--local", "state.single", "idem.state", sls=fh.name, name="idem_tes t" "--local", "state.single", "idem.state", sls=fh.name, name="idem_tes t"
) )
parent = ret.json["idem_|-idem_test_|-idem_test_|-state"] state_id = "idem_|-idem_test_|-idem_test_|-state"
parent = ret.json[state_id]
assert parent["result"] is True, parent["comment"] assert parent["result"] is True, parent["comment"]
sub_state_ret = parent["sub_state_run"][0] sub_state_ret = parent["sub_state_run"][0]
assert sub_state_ret["result"] is True assert sub_state_ret["result"] is True
assert sub_state_ret["name"] == "idem_test" assert sub_state_ret["name"] == "idem_test"
assert "Success!" in sub_state_ret["comment"] assert "Success!" in sub_state_ret["comment"]
# Format the idem state through the state outputter
minion_opts = tests.support.sminion.build_minion_opts()
state_obj = salt.state.State(minion_opts)
chunk_ret = state_obj.call_chunk(
{"state": "state", "name": "name", "fun": "fun", "__id__": "__id__"},
ret.json,
{},
)
# Verify that the sub_state_run looks like a normal salt state
assert "start_time" in chunk_ret[state_id]
float(chunk_ret[state_id]["duration"])
def test_bad_state(salt_call_cli): def test_bad_state(salt_call_cli):
bad_sls = "non-existant-file.sls" bad_sls = "non-existant-file.sls"
ret = salt_call_cli.run( ret = salt_call_cli.run(
"--local", "state.single", "idem.state", sls=bad_sls, name="idem_bad_tes t" "--local", "state.single", "idem.state", sls=bad_sls, name="idem_bad_tes t"
) )
parent = ret.json["idem_|-idem_bad_test_|-idem_bad_test_|-state"] parent = ret.json["idem_|-idem_bad_test_|-idem_bad_test_|-state"]
assert parent["result"] is False assert parent["result"] is False
assert "SLS ref {} did not resolve to a file".format(bad_sls) == parent["com ment"] assert "SLS ref {} did not resolve to a file".format(bad_sls) == parent["com ment"]
 End of changes. 5 change blocks. 
2 lines changed or deleted 17 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)