From 47e4c80a74b82076dbddc519daca494f09cc94a7 Mon Sep 17 00:00:00 2001 From: jeanluc Date: Thu, 30 May 2024 21:41:23 +0200 Subject: [PATCH] Add test for issue #66600 --- .../integration/ssh/test_jinja_mods.py | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tests/pytests/integration/ssh/test_jinja_mods.py b/tests/pytests/integration/ssh/test_jinja_mods.py index aa745c7cdcd..ba00811323d 100644 --- a/tests/pytests/integration/ssh/test_jinja_mods.py +++ b/tests/pytests/integration/ssh/test_jinja_mods.py @@ -28,3 +28,54 @@ def test_echo(salt_ssh_cli, base_env_state_tree_root_dir): ret = salt_ssh_cli.run("state.apply", name) result = StateResult(ret.data) assert result.comment == echo + + +@pytest.fixture +def _exewrap(base_env_state_tree_root_dir, salt_run_cli): + exe = """ +def run(): + return "exe" +""" + + wrapper = """ +def run(): + return "wrapper" +""" + name = "exewrap" + try: + with pytest.helpers.temp_file( + f"{name}.py", exe, base_env_state_tree_root_dir / "_modules" + ): + with pytest.helpers.temp_file( + f"{name}.py", wrapper, base_env_state_tree_root_dir / "_wrapper" + ): + res = salt_run_cli.run("saltutil.sync_all") + assert res.returncode == 0 + assert f"modules.{name}" in res.data["modules"] + assert f"wrapper.{name}" in res.data["wrapper"] + yield name + finally: + res = salt_run_cli.run("saltutil.sync_all") + assert res.returncode == 0 + + +@pytest.fixture +def _jinja_loader_attr_template(base_env_state_tree_root_dir, _exewrap): + contents = f""" +foo: + test.show_notification: + - text: {{{{ salt.{_exewrap}.run() | json }}}} + """ + name = "exewrap_test" + with pytest.helpers.temp_file( + f"{name}.sls", contents, base_env_state_tree_root_dir + ): + yield name + + +def test_wrapper_attribute_access(_jinja_loader_attr_template, salt_ssh_cli): + res = salt_ssh_cli.run("state.apply", _jinja_loader_attr_template) + assert res.returncode == 0 + ret = StateResult(res.data) + assert ret.result is True + assert ret.comment == "wrapper"