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

Adding retry functionality when parallel is set to True #61631

Merged
merged 139 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
c35dc2b
Making the retry state system feature available when parallel is set …
garethgreenaway Feb 11, 2022
0ce8b7e
swapping out using time.sleep Salt function for Python time.sleep.
garethgreenaway Feb 14, 2022
293190c
Merge branch 'master' into add_rety_to_parallel_state
garethgreenaway Feb 16, 2022
923e816
Merge branch 'master' into add_rety_to_parallel_state
Feb 23, 2022
02eba96
Merge branch 'master' into add_rety_to_parallel_state
garethgreenaway Feb 25, 2022
f4cecb2
Skipping parallel tests on Windows.
garethgreenaway Mar 9, 2022
10c1e61
Merge branch 'master' into add_rety_to_parallel_state
garethgreenaway Mar 10, 2022
4334a9c
Merge branch 'master' into add_rety_to_parallel_state
Mar 16, 2022
9b7d357
Merge branch 'master' into add_rety_to_parallel_state
garethgreenaway Mar 23, 2022
14b0d5e
Merge branch 'master' into add_rety_to_parallel_state
garethgreenaway Mar 23, 2022
30cbe91
Merge branch 'master' into add_rety_to_parallel_state
garethgreenaway Mar 25, 2022
27c55c3
Merge branch 'master' into add_rety_to_parallel_state
garethgreenaway Mar 28, 2022
bb6be1c
Merge branch 'master' into add_rety_to_parallel_state
garethgreenaway Mar 29, 2022
dc6813a
Merge branch 'master' into add_rety_to_parallel_state
Apr 6, 2022
f877605
Merge branch 'master' into add_rety_to_parallel_state
Apr 12, 2022
1a43479
Merge branch 'master' into add_rety_to_parallel_state
garethgreenaway May 17, 2022
561319e
Fixing items, values, and keys functions in the data module. Moving …
garethgreenaway May 4, 2022
8a74bae
adding changleog.
garethgreenaway May 4, 2022
6394a39
fixes saltstack/salt#62044 add ignore_missing to file.comment state
nicholasmhughes May 10, 2022
d94f759
fixes saltstack/salt#61662 fix file.comment reports changes in test mode
nicholasmhughes May 10, 2022
c3158f0
add 61662.fixed changelog
nicholasmhughes May 10, 2022
999bdca
add final test mode run after comment is successful
nicholasmhughes May 10, 2022
f7686f3
fix uncomment_regex
nicholasmhughes May 10, 2022
114b676
fix uncomment_regex
nicholasmhughes May 10, 2022
adef57a
Try not to trigger the GLIBC race condition.
s0undt3ch May 17, 2022
134f5b2
Add missing CLI example to ``network.fqdns``
s0undt3ch May 17, 2022
a3d926a
Sleep between submitting new jobs to thread pool
s0undt3ch May 18, 2022
568122a
Sleep before trying to resolve instead
s0undt3ch May 18, 2022
89af01b
Shorter sleeps
s0undt3ch May 18, 2022
4c64b52
fixes saltstack/salt#61944 fixed backslash literal bytestring
emmadionne1 May 16, 2022
9a6e8ed
When states are running in parallel, ensure that the total run time p…
garethgreenaway Apr 28, 2022
bf12274
removing unrelated change
garethgreenaway Apr 28, 2022
1db81f3
Adding changelog.
garethgreenaway Apr 28, 2022
d79ddc5
Skip parallel test on Windows.
garethgreenaway May 11, 2022
fe02b2f
skip pdbedit unit tests on ubuntu 2204 because md4 is not supported a…
May 13, 2022
4ee94cb
refresh db at the beginning for destructive aptpkg functional tests
May 16, 2022
d8449f9
fix failing test_pkgrepo_managed_absent and actually capture and keep…
May 16, 2022
c711f58
Update tests/unit/modules/test_pdbedit.py
MKLeb May 17, 2022
97b2e3d
Disable hack to force allowing forking on macOS
s0undt3ch Apr 12, 2022
ccb8b46
Use the newer nox platforms file which installs Py3.9
s0undt3ch Mar 31, 2022
17e420e
Support macOS defaulting to spawn as the default multiprocessing method
s0undt3ch Mar 20, 2022
8e15dfb
Remove unused attribute
s0undt3ch Apr 12, 2022
3ecdcdd
Switch to ``salt.utils.platform.spawning_platform()``
s0undt3ch Feb 17, 2022
62533e5
Reconstruct client instances on spawning platforms
s0undt3ch Feb 17, 2022
bee3309
Also skip this test for now on macOS
s0undt3ch Feb 9, 2022
aa2ed58
Reconstruct the ``State`` class on spawned processes.
s0undt3ch Apr 12, 2022
979ef83
Force a reference to ``salt.ext.tornado.iostream.StreamClosedError`` …
s0undt3ch Apr 12, 2022
95ce89d
Skip, for now, problematic tests on spawning platforms
s0undt3ch Feb 24, 2022
5021279
DeltaProxy minions do not work on spawning platforms
s0undt3ch Feb 25, 2022
394a7fc
Avoid a ``NameError`` when failing to initialize the process list
s0undt3ch Mar 20, 2022
729195b
Use Python 3.9 on macOS
s0undt3ch Apr 1, 2022
2c4a954
Drop requirements on Darwin for Py<3.9
s0undt3ch Apr 2, 2022
a7c0e84
Same test run timeout as windows
s0undt3ch Apr 3, 2022
b3b7a05
Don't shell out! Access the database directly and properly escape val…
s0undt3ch Apr 7, 2022
319370e
Fixes for the new macOS Catalina and BigSur CICD images
s0undt3ch Apr 7, 2022
5a2a4f4
Migrate ``integration.modules.test_mac_pkgutil`` to PyTest and functi…
s0undt3ch Apr 8, 2022
5743c05
Add changelog for #57742
s0undt3ch Apr 12, 2022
ef0cab6
Add changelog entry.
s0undt3ch Apr 12, 2022
1d35c36
initial Proxy Module
ITJamie Nov 17, 2020
33de313
inital pass of restconf states
ITJamie Nov 17, 2020
82d9a60
adding codeauthor
ITJamie Nov 17, 2020
72a9af8
adding restconf module
ITJamie Nov 17, 2020
07444e8
doc update
ITJamie Nov 18, 2020
4cae4b9
doc update
ITJamie Nov 18, 2020
d28544f
doc update
ITJamie Nov 23, 2020
9f194e3
add requirements chefk to states module
ITJamie Nov 23, 2020
651bede
doc update
ITJamie Nov 23, 2020
6fbf4e5
doc update
ITJamie Nov 23, 2020
23b4ddb
doc update
ITJamie Nov 23, 2020
118f121
add changelog entry
ITJamie Nov 23, 2020
b5db8e8
Update salt/proxy/restconf.py
ITJamie Nov 24, 2020
39947b9
Update salt/proxy/restconf.py
ITJamie Nov 24, 2020
0dd8748
remove noqa statements
ITJamie Nov 24, 2020
8845a5f
docs update & opts defaults
ITJamie Nov 24, 2020
2b88c7c
docs update
ITJamie Nov 24, 2020
7705f9d
error checks + https transport method
ITJamie Nov 24, 2020
037c13b
docs update
ITJamie Nov 24, 2020
a03380c
docs update
ITJamie Nov 24, 2020
0855724
doing a fix for commit check
ITJamie Nov 24, 2020
a1b411f
adding test and updating modules
ITJamie Nov 25, 2020
bc259e1
removing old code
ITJamie Nov 25, 2020
5c1051e
DRY
ITJamie Nov 25, 2020
40b19d8
docs update
ITJamie Nov 25, 2020
746275e
output updates
ITJamie Nov 25, 2020
ad08c9c
prepping for deepdiff switch
ITJamie Nov 25, 2020
39852e6
states testing
ITJamie Nov 25, 2020
d4d1fbb
more tests
ITJamie Nov 30, 2020
47c471d
changed changelog from fixed to added
ITJamie Nov 30, 2020
ecc4d7f
force pre-commit checks
ITJamie Dec 1, 2020
a0d119b
new style of diff output that is readable
ITJamie Dec 1, 2020
50b6d7e
updating tests and output
ITJamie Dec 1, 2020
2837737
updating output style to make YAML diff more readable
ITJamie Dec 1, 2020
fcb8a64
add test for restconf module
ITJamie Dec 2, 2020
15c4a96
adjusting based on pr review
ITJamie Dec 3, 2020
7587ccf
adjusting based on pr review
ITJamie Dec 3, 2020
c44a659
adjusting true/false verify based on pr review
ITJamie Dec 3, 2020
2013f98
change uri to path and clean args list
ITJamie Dec 3, 2020
3661b60
adjusting uri to path based on pr review
ITJamie Dec 3, 2020
6140cf1
adjusting capabilities path based on pr review
ITJamie Dec 3, 2020
d20d538
Update salt/modules/restconf.py
ITJamie Dec 3, 2020
b015400
adjusting val based on pr review
ITJamie Dec 3, 2020
6de6f19
caps to confirm to RFC 8040
illegalhex Dec 3, 2020
4781af8
WIP: refactor based on feedback
illegalhex Dec 3, 2020
f105876
WIP: changed results to be any kind of falsey val
illegalhex Dec 3, 2020
fdb629a
linting - pre-commit
ITJamie Dec 7, 2020
a0dac12
updating docs
ITJamie Dec 7, 2020
ea63819
Update salt/states/restconf.py
ITJamie Dec 7, 2020
9347222
updating style
ITJamie Dec 7, 2020
4054eee
fixes for lint and nox pass
ITJamie Dec 7, 2020
d777652
fixing
ITJamie Dec 7, 2020
8b00ff5
blacken
ITJamie Nov 20, 2021
d699feb
Update restconf.py
ITJamie Nov 20, 2021
f66a269
add cli examples
ITJamie Nov 22, 2021
71f0a1a
change logging type
ITJamie Nov 22, 2021
64537c5
add pytest skip for ordereddict issue with legacy python
ITJamie Feb 11, 2022
b1dbbfa
add sys library for pytest mark skipif check
ITJamie Feb 11, 2022
c2aa92c
pre-commit fixes
ITJamie Feb 11, 2022
0f0cbca
Update salt/proxy/restconf.py
ITJamie Feb 23, 2022
c475315
Update salt/states/restconf.py
ITJamie Feb 23, 2022
090d2b5
Update tests/pytests/unit/modules/test_restconf.py
ITJamie Feb 23, 2022
ab3e55b
Update tests/pytests/unit/states/test_restconf.py
ITJamie Feb 23, 2022
4bcdee8
Update tests/pytests/unit/proxy/test_restconf.py
ITJamie Feb 23, 2022
db256a9
pre-commit fix
ITJamie Feb 23, 2022
617ae9b
update logging
ITJamie Feb 24, 2022
92c7ff4
Update restconf.py
ITJamie Mar 26, 2022
e848b9f
some rest apis dont follow the standard correctly (cisco) and need an…
ITJamie Mar 28, 2022
048bfd5
fixes saltstack/salt#61946 sync_after_install immutabledict error
nicholasmhughes May 12, 2022
0265f75
add configurable sync sleep for create
nicholasmhughes May 19, 2022
a914796
add testing around the particular sync command called
nicholasmhughes May 19, 2022
371b815
Adds the ability to get file version information on Windows
twangboy May 11, 2022
f57d174
Update states.chef for version 16.x and 17.x Chef Infra Client output
ericham Mar 31, 2022
ae7a651
Support previous Chef version plus version 16.x and 17.x output.
ericham Apr 5, 2022
50f3237
Remove legacy chef unit test
waynew Apr 5, 2022
f8ef608
Add unit tests for chef state
waynew Apr 5, 2022
47ac21a
Update salt-bootstrap to 2022.03.15 release
krionbsd Mar 15, 2022
d8e99dc
Merge branch 'master' into add_rety_to_parallel_state
garethgreenaway May 24, 2022
a99e3f0
Update state.py
garethgreenaway May 24, 2022
5f79ebb
Running pre-commit manually.
garethgreenaway May 24, 2022
813710c
swap out salt.utils.platform.is_windows for salt.utils.platform.spawn…
garethgreenaway May 25, 2022
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/61630.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Making the retry state system feature available when parallel is set to True.
67 changes: 66 additions & 1 deletion salt/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2030,12 +2030,77 @@ def _call_parallel_target(cls, instance, init_kwargs, name, cdata, low):
}

utc_finish_time = datetime.datetime.utcnow()
timezone_delta = datetime.datetime.utcnow() - datetime.datetime.now()
local_finish_time = utc_finish_time - timezone_delta
local_start_time = utc_start_time - timezone_delta
ret["start_time"] = local_start_time.time().isoformat()
delta = utc_finish_time - utc_start_time
# duration in milliseconds.microseconds
duration = (delta.seconds * 1000000 + delta.microseconds) / 1000.0
ret["duration"] = duration
ret["__parallel__"] = True

if "retry" in low:
retries = 1
low["retry"] = instance.verify_retry_data(low["retry"])
if not sys.modules[instance.states[cdata["full"]].__module__].__opts__[
"test"
]:
while low["retry"]["attempts"] >= retries:

if low["retry"]["until"] == ret["result"]:
break

interval = low["retry"]["interval"]
if low["retry"]["splay"] != 0:
interval = interval + random.randint(0, low["retry"]["splay"])
log.info(
"State result does not match retry until value, "
"state will be re-run in %s seconds",
interval,
)
time.sleep(interval)
retry_ret = instance.states[cdata["full"]](
*cdata["args"], **cdata["kwargs"]
)

utc_start_time = datetime.datetime.utcnow()
utc_finish_time = datetime.datetime.utcnow()
delta = utc_finish_time - utc_start_time
duration = (delta.seconds * 1000000 + delta.microseconds) / 1000.0
retry_ret["duration"] = duration

orig_ret = ret
ret = retry_ret
if not ret["comment"]:
_comment = ""
else:
_comment = (
'Attempt {}: Returned a result of "{}", '
'with the following comment: "{}"'.format(
retries, ret["result"], ret["comment"]
)
)

ret["comment"] = "\n".join([orig_ret["comment"], _comment])
ret["duration"] = (
ret["duration"] + orig_ret["duration"] + (interval * 1000)
)
if retries == 1:
ret["start_time"] = orig_ret["start_time"]
retries = retries + 1

else:
ret["comment"] = " ".join(
[
"" if not ret["comment"] else str(ret["comment"]),
"The state would be retried every {interval} seconds "
"(with a splay of up to {splay} seconds) a maximum of "
"{attempts} times or until a result of {until} "
"is returned".format(**low["retry"]),
]
)

troot = os.path.join(instance.opts["cachedir"], instance.jid)
tfile = os.path.join(troot, salt.utils.hashutils.sha1_digest(tag))
if not os.path.isdir(troot):
Expand Down Expand Up @@ -2283,7 +2348,7 @@ def call(self, low, chunks=None, running=None, retries=1):
local_finish_time.time().isoformat(),
duration,
)
if "retry" in low:
if "retry" in low and "parallel" not in low:
low["retry"] = self.verify_retry_data(low["retry"])
if not sys.modules[self.states[cdata["full"]].__module__].__opts__["test"]:
if low["retry"]["until"] != ret["result"]:
Expand Down
92 changes: 91 additions & 1 deletion tests/pytests/functional/modules/state/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ def test_retry_option_success(state, state_tree, tmp_path):
testfile
)
duration = 4
if salt.utils.platform.is_windows():
if salt.utils.platform.spawning_platform():
duration = 16

with pytest.helpers.temp_file("retry.sls", sls_contents, state_tree):
Expand All @@ -702,6 +702,44 @@ def test_retry_option_success(state, state_tree, tmp_path):
assert "Attempt 2" not in state_return.comment


@pytest.mark.skip_on_windows(
reason="Skipped until parallel states can be fixed on Windows"
)
def test_retry_option_success_parallel(state, state_tree, tmp_path):
"""
test a state with the retry option that should return True immediately (i.e. no retries)
"""
testfile = tmp_path / "testfile"
testfile.touch()
sls_contents = """
file_test:
file.exists:
- name: {}
- parallel: True
- retry:
until: True
attempts: 5
interval: 2
splay: 0
""".format(
testfile
)
duration = 4
if salt.utils.platform.spawning_platform():
duration = 30

with pytest.helpers.temp_file("retry.sls", sls_contents, state_tree):
ret = state.sls(
"retry", __pub_jid="1"
) # Because these run in parallel we need a fake JID

for state_return in ret:
assert state_return.result is True
assert state_return.full_return["duration"] < duration
# It should not take 2 attempts
assert "Attempt 2" not in state_return.comment


@pytest.mark.slow_test
def test_retry_option_eventual_success(state, state_tree, tmp_path):
"""
Expand Down Expand Up @@ -747,6 +785,58 @@ def create_testfile(testfile1, testfile2):
assert "Attempt 5" not in state_return.comment


@pytest.mark.skip_on_windows(
reason="Skipped until parallel states can be fixed on Windows"
)
@pytest.mark.slow_test
def test_retry_option_eventual_success_parallel(state, state_tree, tmp_path):
"""
test a state with the retry option that should return True, eventually
"""
testfile1 = tmp_path / "testfile-1"
testfile2 = tmp_path / "testfile-2"

def create_testfile(testfile1, testfile2):
while True:
if testfile1.exists():
break
time.sleep(2)
testfile2.touch()

thread = threading.Thread(target=create_testfile, args=(testfile1, testfile2))
sls_contents = """
file_test_a:
file.managed:
- name: {}
- content: 'a'

file_test:
file.exists:
- name: {}
- retry:
until: True
attempts: 5
interval: 2
splay: 0
- parallel: True
- require:
- file_test_a
""".format(
testfile1, testfile2
)
with pytest.helpers.temp_file("retry.sls", sls_contents, state_tree):
thread.start()
ret = state.sls(
"retry", __pub_jid="1"
) # Because these run in parallel we need a fake JID
for state_return in ret:
log.debug("=== state_return %s ===", state_return)
assert state_return.result is True
assert state_return.full_return["duration"] > 4
# It should not take 5 attempts
assert "Attempt 5" not in state_return.comment


@pytest.mark.slow_test
def test_state_non_base_environment(state, state_tree_prod, tmp_path):
"""
Expand Down