summaryrefslogtreecommitdiff
path: root/lib/ansible/plugins/strategy
diff options
context:
space:
mode:
authorPilou <pierre-louis.bonicoli@libregerbil.fr>2020-01-24 14:18:08 +0000
committerJames Cammarata <jimi@sngx.net>2020-01-24 08:18:08 -0600
commitbbbdc1c25c1b26554a38ae4c1cd7261b900378af (patch)
tree49f62b5a5ac48b5986381b56aed008b0ed8958f5 /lib/ansible/plugins/strategy
parent7bbf4ad7d65320d82214a82045457c1a1ab9647d (diff)
downloadansible-bbbdc1c25c1b26554a38ae4c1cd7261b900378af.tar.gz
throttle: fix linear based strategies (#65422)
* throttle tests: fix detection of parallel execution The test wasn't able to detect if too many workers were running. On my laptop: - without this change, the 'throttle' target takes ~20 seconds - with this change, the 'throttle' target takes ~70 seconds - 1 second isn't long enough to encounter the issue * Fix throttle test when strategy is 'free' based 'free' strategy allows multiple tasks to be executed in parallel: use one 'throttledir' per task. Use 'linear' strategy with a dedicated play for cleanup/setup tasks * throttle: reset worker idx before queuing a new task * TestStrategyBase: define task.throttle otherwise '1' will be used instead of the default value due to the following expression being equal to '1': int(templar.template(task_mock.throttle)) Co-authored-by: James Cammarata <jimi@sngx.net>
Diffstat (limited to 'lib/ansible/plugins/strategy')
-rw-r--r--lib/ansible/plugins/strategy/__init__.py30
1 files changed, 17 insertions, 13 deletions
diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py
index 1750e3da9b..dc83744a12 100644
--- a/lib/ansible/plugins/strategy/__init__.py
+++ b/lib/ansible/plugins/strategy/__init__.py
@@ -325,9 +325,26 @@ class StrategyBase:
# and then queue the new task
try:
+ # Determine the "rewind point" of the worker list. This means we start
+ # iterating over the list of workers until the end of the list is found.
+ # Normally, that is simply the length of the workers list (as determined
+ # by the forks or serial setting), however a task/block/play may "throttle"
+ # that limit down.
+ rewind_point = len(self._workers)
+ if throttle > 0 and self.ALLOW_BASE_THROTTLING:
+ if task.run_once:
+ display.debug("Ignoring 'throttle' as 'run_once' is also set for '%s'" % task.get_name())
+ else:
+ if throttle <= rewind_point:
+ display.debug("task: %s, throttle: %d" % (task.get_name(), throttle))
+ rewind_point = throttle
+
queued = False
starting_worker = self._cur_worker
while True:
+ if self._cur_worker >= rewind_point:
+ self._cur_worker = 0
+
worker_prc = self._workers[self._cur_worker]
if worker_prc is None or not worker_prc.is_alive():
self._queued_task_cache[(host.name, task._uuid)] = {
@@ -346,19 +363,6 @@ class StrategyBase:
self._cur_worker += 1
- # Determine the "rewind point" of the worker list. This means we start
- # iterating over the list of workers until the end of the list is found.
- # Normally, that is simply the length of the workers list (as determined
- # by the forks or serial setting), however a task/block/play may "throttle"
- # that limit down.
- rewind_point = len(self._workers)
- if throttle > 0 and self.ALLOW_BASE_THROTTLING:
- if task.run_once:
- display.debug("Ignoring 'throttle' as 'run_once' is also set for '%s'" % task.get_name())
- else:
- if throttle <= rewind_point:
- display.debug("task: %s, throttle: %d" % (task.get_name(), throttle))
- rewind_point = throttle
if self._cur_worker >= rewind_point:
self._cur_worker = 0