Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

salt/state.py: support retry: True as per docs #67049

Open
wants to merge 1 commit into
base: 3006.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/67049.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
support retry: True as per docs
7 changes: 5 additions & 2 deletions salt/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2708,10 +2708,13 @@ def verify_retry_data(self, retry_data):
]
else:
validated_retry_data[expected_key] = retry_defaults[expected_key]

elif isinstance(retry_data, bool) and retry_data:
validated_retry_data = retry_defaults
else:
log.warning(
"State is set to retry, but a valid dict for retry "
"configuration was not found. Using retry defaults"
"State is set to retry, but retry: True or a valid dict for "
"retry configuration was not found. Using retry defaults"
)
validated_retry_data = retry_defaults
return validated_retry_data
Expand Down
24 changes: 24 additions & 0 deletions tests/pytests/functional/modules/state/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,30 @@ def test_retry_option(state, state_tree):
assert state_return.full_return["duration"] >= 3


def test_retry_option_is_true(state, state_tree):
"""
test the retry: True on a simple state with defaults
ensure comment is as expected
ensure state duration is greater than configured the passed (interval * attempts)
"""
sls_contents = """
file_test:
file.exists:
- name: /path/to/a/non-existent/file.txt
- retry: True
"""
expected_comment = (
'Attempt 1: Returned a result of "False", with the following '
'comment: "Specified path /path/to/a/non-existent/file.txt does not exist"'
)
with pytest.helpers.temp_file("retry.sls", sls_contents, state_tree):
ret = state.sls("retry")
for state_return in ret:
assert state_return.result is False
assert expected_comment in state_return.comment
assert state_return.full_return["duration"] >= 3


@pytest.mark.skip_initial_gh_actions_failure(skip=_check_skip)
def test_retry_option_success(state, state_tree, tmp_path):
"""
Expand Down
Loading