"Fossies" - the Fresh Open Source Software Archive

Member "salt-3002.2/tests/pytests/integration/states/test_idem.py" (18 Nov 2020, 2002 Bytes) of package /linux/misc/salt-3002.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "test_idem.py": 3002.1_vs_3002.2.

    1 """
    2 Tests for the idem state
    3 """
    4 import tempfile
    5 from contextlib import contextmanager
    6 
    7 import pytest
    8 import salt.state
    9 import salt.utils.idem as idem
   10 import salt.utils.path
   11 import tests.support.sminion
   12 
   13 pytestmark = pytest.mark.skipif(not idem.HAS_POP[0], reason=idem.HAS_POP[1])
   14 
   15 
   16 @contextmanager
   17 def test_state(salt_call_cli):
   18     with tempfile.NamedTemporaryFile(suffix=".sls", delete=True, mode="w+") as fh:
   19         sls_succeed_without_changes = """
   20         state_name:
   21           test.succeed_without_changes:
   22             - name: idem_test
   23             - foo: bar
   24         """
   25         fh.write(sls_succeed_without_changes)
   26         fh.flush()
   27         ret = salt_call_cli.run(
   28             "--local", "state.single", "idem.state", sls=fh.name, name="idem_test"
   29         )
   30 
   31     state_id = "idem_|-idem_test_|-idem_test_|-state"
   32     parent = ret.json[state_id]
   33     assert parent["result"] is True, parent["comment"]
   34     sub_state_ret = parent["sub_state_run"][0]
   35     assert sub_state_ret["result"] is True
   36     assert sub_state_ret["name"] == "idem_test"
   37     assert "Success!" in sub_state_ret["comment"]
   38 
   39     # Format the idem state through the state outputter
   40     minion_opts = tests.support.sminion.build_minion_opts()
   41     state_obj = salt.state.State(minion_opts)
   42 
   43     chunk_ret = state_obj.call_chunk(
   44         {"state": "state", "name": "name", "fun": "fun", "__id__": "__id__"},
   45         ret.json,
   46         {},
   47     )
   48     # Verify that the sub_state_run looks like a normal salt state
   49     assert "start_time" in chunk_ret[state_id]
   50     float(chunk_ret[state_id]["duration"])
   51 
   52 
   53 def test_bad_state(salt_call_cli):
   54     bad_sls = "non-existant-file.sls"
   55 
   56     ret = salt_call_cli.run(
   57         "--local", "state.single", "idem.state", sls=bad_sls, name="idem_bad_test"
   58     )
   59     parent = ret.json["idem_|-idem_bad_test_|-idem_bad_test_|-state"]
   60 
   61     assert parent["result"] is False
   62     assert "SLS ref {} did not resolve to a file".format(bad_sls) == parent["comment"]
   63     assert not parent["sub_state_run"]