Skip to content

Commit

Permalink
salt/state.py: support retry: True as per docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Doherty committed Nov 8, 2024
1 parent 0dc964f commit 0beec24
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
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

0 comments on commit 0beec24

Please sign in to comment.