From 29812c3dcdfc7cb6b54480e796187ec57a27c18d Mon Sep 17 00:00:00 2001 From: Dheeraj Gupta Date: Thu, 3 Nov 2022 10:38:45 +0530 Subject: [PATCH] Make legacy and modern syntax detection work for module.wait PR#61772 added the ability to detect modern or legacy syntax for module.run to allow both styles to co-exist. Those changes did not fully address module.wait semantics which led to all module.wait syntaxes to be treated as legacy. Using modern syntax led to state failure in such cases. This commit adds additional keys that may be generated when module.wait is used to the list of kwargs ignored by detection algorithm. It also adds functional tests for module.wait test cases. Fixes #62988 --- changelog/62988.fixed | 1 + salt/states/module.py | 6 +- .../pytests/functional/states/test_module.py | 61 ++++++++++++++++++- 3 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 changelog/62988.fixed diff --git a/changelog/62988.fixed b/changelog/62988.fixed new file mode 100644 index 000000000000..b525e2f38ac8 --- /dev/null +++ b/changelog/62988.fixed @@ -0,0 +1 @@ +Fixed bug where module.wait states were detected as running legacy module.run syntax diff --git a/salt/states/module.py b/salt/states/module.py index a9801ea82bf1..5ad87b053d27 100644 --- a/salt/states/module.py +++ b/salt/states/module.py @@ -376,8 +376,10 @@ def run(**kwargs): legacy_run = False keys = list(kwargs) - if "name" in keys: - keys.remove("name") + ignored_kwargs = ["name", "__reqs__", "sfun"] + for item in ignored_kwargs: + if item in keys: + keys.remove(item) # The rest of the keys should be function names for new-style syntax for name in keys: diff --git a/tests/pytests/functional/states/test_module.py b/tests/pytests/functional/states/test_module.py index d4caca2bc3a1..bf2410ab529d 100644 --- a/tests/pytests/functional/states/test_module.py +++ b/tests/pytests/functional/states/test_module.py @@ -82,7 +82,66 @@ def test_issue_58763_b(tmp_path, modules, state_tree, caplog): mods="issue-58763", ) assert len(ret.raw) == 1 - print(ret) for k in ret.raw: assert ret.raw[k]["result"] is True assert "Detected legacy module.run syntax: test.ping" in caplog.messages + + +@pytest.mark.slow_test +def test_issue_62988_a(tmp_path, modules, state_tree, caplog): + + venv_dir = tmp_path / "issue-2028-pip-installed" + + sls_contents = dedent( + """ + test_foo: + test.succeed_with_changes + + run_new: + module.wait: + - test.random_hash: + - size: 10 + - hash_type: md5 + - watch: + - test: test_foo + """ + ) + with pytest.helpers.temp_file("issue-62988.sls", sls_contents, state_tree): + with caplog.at_level(logging.DEBUG): + ret = modules.state.sls( + mods="issue-62988", + ) + assert len(ret.raw) == 2 + for k in ret.raw: + assert ret.raw[k]["result"] is True + assert "Using new style module.run syntax: run_new" in caplog.messages + + +@pytest.mark.slow_test +def test_issue_62988_b(tmp_path, modules, state_tree, caplog): + + venv_dir = tmp_path / "issue-2028-pip-installed" + + sls_contents = dedent( + """ + test_foo: + test.succeed_with_changes: + - watch_in: + - module: run_new + + run_new: + module.wait: + - test.random_hash: + - size: 10 + - hash_type: md5 + """ + ) + with pytest.helpers.temp_file("issue-62988.sls", sls_contents, state_tree): + with caplog.at_level(logging.DEBUG): + ret = modules.state.sls( + mods="issue-62988", + ) + assert len(ret.raw) == 2 + for k in ret.raw: + assert ret.raw[k]["result"] is True + assert "Using new style module.run syntax: run_new" in caplog.messages