Skip to content

Commit

Permalink
Make legacy and modern syntax detection work for module.wait
Browse files Browse the repository at this point in the history
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
  • Loading branch information
redbaron4 authored and Megan Wilhite committed Nov 7, 2022
1 parent 0f6b9ef commit 29812c3
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog/62988.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed bug where module.wait states were detected as running legacy module.run syntax
6 changes: 4 additions & 2 deletions salt/states/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
61 changes: 60 additions & 1 deletion tests/pytests/functional/states/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 29812c3

Please sign in to comment.