Skip to content

Commit 48c2d1e

Browse files
Tom Dohertydwoz
authored andcommitted
salt/state.py: support retry: True as per docs
1 parent 21df2a1 commit 48c2d1e

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

changelog/67049.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
support retry: True as per docs

salt/state.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2731,10 +2731,13 @@ def verify_retry_data(self, retry_data):
27312731
]
27322732
else:
27332733
validated_retry_data[expected_key] = retry_defaults[expected_key]
2734+
2735+
elif isinstance(retry_data, bool) and retry_data:
2736+
validated_retry_data = retry_defaults
27342737
else:
27352738
log.warning(
2736-
"State is set to retry, but a valid dict for retry "
2737-
"configuration was not found. Using retry defaults"
2739+
"State is set to retry, but retry: True or a valid dict for "
2740+
"retry configuration was not found. Using retry defaults"
27382741
)
27392742
validated_retry_data = retry_defaults
27402743
return validated_retry_data

tests/pytests/functional/modules/state/test_state.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,30 @@ def test_retry_option(state, state_tree):
711711
assert state_return.full_return["duration"] >= 3
712712

713713

714+
def test_retry_option_is_true(state, state_tree):
715+
"""
716+
test the retry: True on a simple state with defaults
717+
ensure comment is as expected
718+
ensure state duration is greater than configured the passed (interval * attempts)
719+
"""
720+
sls_contents = """
721+
file_test:
722+
file.exists:
723+
- name: /path/to/a/non-existent/file.txt
724+
- retry: True
725+
"""
726+
expected_comment = (
727+
'Attempt 1: Returned a result of "False", with the following '
728+
'comment: "Specified path /path/to/a/non-existent/file.txt does not exist"'
729+
)
730+
with pytest.helpers.temp_file("retry.sls", sls_contents, state_tree):
731+
ret = state.sls("retry")
732+
for state_return in ret:
733+
assert state_return.result is False
734+
assert expected_comment in state_return.comment
735+
assert state_return.full_return["duration"] >= 3
736+
737+
714738
@pytest.mark.skip_initial_gh_actions_failure(skip=_check_skip)
715739
def test_retry_option_success(state, state_tree, tmp_path):
716740
"""

0 commit comments

Comments
 (0)