salt/tests/pytests/integration/utils/test_templates.py
Megan Wilhite fc7d0a9296
Merge freeze into master (#62438)
* fixes saltstack/salt#62372 unable to use random shuffle and sample functions as Jinja filters

* move random_shuffle and random_sample logic to utils

* static seed in tests seems to have shifted

* static seed in tests require hash module

* Change Tiamat to onedir in release notes

* Reinstate known issues

* Update release notes with onedir package support policy

* need to check the version of Netmiko python library and then import the exceptions from different locations depending on the result.

* Adding changelog.

* swap out if...else for double try...except.

* Remove extra fix we don't need anymore

* [Docs] include onedir system python note

* Update all platforms to use pycparser 2.21 or greater for Py 3.9 or higher, fixes fips fault with openssl v3.x

* Remove the PyObjC dependency

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>

* Add "<tiamat> python" subcommand to allow execution or arbitrary scripts via bundled Python runtime

* Document usage of bundled Python runtime for Client API

* Use explicit locals for custom script execution, handle exception in similar fashion as Python

* Remove old __file__ replacement

* Apply suggestions from code review

Co-authored-by: Pedro Algarvio <pedro@algarvio.me>

Co-authored-by: nicholasmhughes <nicholasmhughes@gmail.com>
Co-authored-by: Alyssa Rock <alyssa.rock@gmail.com>
Co-authored-by: Gareth J. Greenaway <gareth@saltstack.com>
Co-authored-by: Twangboy <leesh@vmware.com>
Co-authored-by: David Murphy < dmurphy@saltstack.com>
Co-authored-by: Pedro Algarvio <palgarvio@vmware.com>
Co-authored-by: Lukas Raska <lukas@raska.me>
Co-authored-by: Pedro Algarvio <pedro@algarvio.me>
2022-08-08 11:27:10 -06:00

74 lines
2.1 KiB
Python

"""
Tests for the templates utils
"""
import os
import pytest
def test_issue_60083(
salt_call_cli,
tmp_path,
base_env_state_tree_root_dir,
):
"""
Validate that we can serialize pillars to json in states.
Issue #60083
"""
target_path = tmp_path / "issue-60083-target.txt"
assert not os.path.exists(str(target_path))
sls_name = "issue-60083"
sls_contents = """
{{ pillar["target-path"] }}:
file.managed:
- contents: |
{{ pillar|json }}
"""
sls_tempfile = pytest.helpers.temp_file(
"{}.sls".format(sls_name), sls_contents, base_env_state_tree_root_dir
)
with sls_tempfile: # , issue_50221_ext_pillar_tempfile:
ret = salt_call_cli.run(
"state.apply", sls_name, pillar={"target-path": str(target_path)}
)
assert ret.stdout.find("Jinja error") == -1
assert ret.data
keys = list(ret.data.keys())
assert len(keys) == 1
key = keys[0]
assert ret.data[key]["changes"]["diff"] == "New file"
def test_issue_62372(
salt_call_cli,
tmp_path,
base_env_state_tree_root_dir,
):
"""
Validate that we can use the random_* filters
Issue #62372
"""
target_path = tmp_path / "issue-62372-target.txt"
assert not os.path.exists(str(target_path))
sls_name = "issue-62372"
sls_contents = """
{% set my_list = ["one", "two", "three", "four"] -%}
{{ pillar["target-path"] }}:
file.managed:
- contents: |
{{ my_list | random_sample(2, seed="static") }}
{{ my_list | random_shuffle(seed="static") }}
"""
sls_tempfile = pytest.helpers.temp_file(
"{}.sls".format(sls_name), sls_contents, base_env_state_tree_root_dir
)
with sls_tempfile:
ret = salt_call_cli.run(
"state.apply", sls_name, pillar={"target-path": str(target_path)}
)
assert ret.stdout.find("Jinja error") == -1
assert ret.data
keys = list(ret.data.keys())
assert len(keys) == 1
key = keys[0]
assert ret.data[key]["changes"]["diff"] == "New file"