free strategy - include failed hosts that were notified (#65576)
* free strategy - include failed hosts that were notified so --force-handlers is used * trim line length a bit * Loop over the force handler tests with the strategies linear and free * rename changelog * Use the play iterator instead of TQM for accurate failure representation in blocks * Remove hack in a backwards compatible way for 3rd party plugins
This commit is contained in:
parent
89703b3284
commit
c870457339
4 changed files with 45 additions and 21 deletions
|
@ -0,0 +1,4 @@
|
||||||
|
bugfixes:
|
||||||
|
- free strategy - Include failed hosts when filtering notified hosts for handlers. The strategy base should
|
||||||
|
determine whether or not to run handlers on those hosts depending on whether forcing handlers is enabled
|
||||||
|
(https://github.com/ansible/ansible/issues/65254).
|
|
@ -911,7 +911,10 @@ class StrategyBase:
|
||||||
if notified_hosts is None:
|
if notified_hosts is None:
|
||||||
notified_hosts = handler.notified_hosts[:]
|
notified_hosts = handler.notified_hosts[:]
|
||||||
|
|
||||||
|
# strategy plugins that filter hosts need access to the iterator to identify failed hosts
|
||||||
|
failed_hosts = self._filter_notified_failed_hosts(iterator, notified_hosts)
|
||||||
notified_hosts = self._filter_notified_hosts(notified_hosts)
|
notified_hosts = self._filter_notified_hosts(notified_hosts)
|
||||||
|
notified_hosts += failed_hosts
|
||||||
|
|
||||||
if len(notified_hosts) > 0:
|
if len(notified_hosts) > 0:
|
||||||
saved_name = handler.name
|
saved_name = handler.name
|
||||||
|
@ -991,6 +994,9 @@ class StrategyBase:
|
||||||
display.debug("done running handlers, result is: %s" % result)
|
display.debug("done running handlers, result is: %s" % result)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def _filter_notified_failed_hosts(self, iterator, notified_hosts):
|
||||||
|
return []
|
||||||
|
|
||||||
def _filter_notified_hosts(self, notified_hosts):
|
def _filter_notified_hosts(self, notified_hosts):
|
||||||
'''
|
'''
|
||||||
Filter notified hosts accordingly to strategy
|
Filter notified hosts accordingly to strategy
|
||||||
|
|
|
@ -50,6 +50,11 @@ class StrategyModule(StrategyBase):
|
||||||
# This strategy manages throttling on its own, so we don't want it done in queue_task
|
# This strategy manages throttling on its own, so we don't want it done in queue_task
|
||||||
ALLOW_BASE_THROTTLING = False
|
ALLOW_BASE_THROTTLING = False
|
||||||
|
|
||||||
|
def _filter_notified_failed_hosts(self, iterator, notified_hosts):
|
||||||
|
|
||||||
|
# If --force-handlers is used we may act on hosts that have failed
|
||||||
|
return [host for host in notified_hosts if iterator.is_failed(host)]
|
||||||
|
|
||||||
def _filter_notified_hosts(self, notified_hosts):
|
def _filter_notified_hosts(self, notified_hosts):
|
||||||
'''
|
'''
|
||||||
Filter notified hosts accordingly to strategy
|
Filter notified hosts accordingly to strategy
|
||||||
|
|
|
@ -17,6 +17,11 @@ ansible-playbook test_listening_handlers.yml -i inventory.handlers -v "$@"
|
||||||
[ "$(ansible-playbook test_handlers.yml -i inventory.handlers -v "$@" --tags scenario2 -l A \
|
[ "$(ansible-playbook test_handlers.yml -i inventory.handlers -v "$@" --tags scenario2 -l A \
|
||||||
| grep -E -o 'RUNNING HANDLER \[test_handlers : .*?]')" = "RUNNING HANDLER [test_handlers : test handler]" ]
|
| grep -E -o 'RUNNING HANDLER \[test_handlers : .*?]')" = "RUNNING HANDLER [test_handlers : test handler]" ]
|
||||||
|
|
||||||
|
# Test forcing handlers using the linear and free strategy
|
||||||
|
for strategy in linear free; do
|
||||||
|
|
||||||
|
export ANSIBLE_STRATEGY=$strategy
|
||||||
|
|
||||||
# Not forcing, should only run on successful host
|
# Not forcing, should only run on successful host
|
||||||
[ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags normal \
|
[ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags normal \
|
||||||
| grep -E -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_B" ]
|
| grep -E -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_B" ]
|
||||||
|
@ -45,6 +50,10 @@ ansible-playbook test_listening_handlers.yml -i inventory.handlers -v "$@"
|
||||||
[ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags force_false_in_play --force-handlers \
|
[ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags force_false_in_play --force-handlers \
|
||||||
| grep -E -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_B" ]
|
| grep -E -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_B" ]
|
||||||
|
|
||||||
|
unset ANSIBLE_STRATEGY
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
[ "$(ansible-playbook test_handlers_include.yml -i ../../inventory -v "$@" --tags playbook_include_handlers \
|
[ "$(ansible-playbook test_handlers_include.yml -i ../../inventory -v "$@" --tags playbook_include_handlers \
|
||||||
| grep -E -o 'RUNNING HANDLER \[.*?]')" = "RUNNING HANDLER [test handler]" ]
|
| grep -E -o 'RUNNING HANDLER \[.*?]')" = "RUNNING HANDLER [test handler]" ]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue