Fixing PlayIterator bugs

* Unit tests exposed a problem where nested blocks did not correctly
  hit rescue/always portions of parent blocks
* Cleaned up logic in PlayIterator
* Unfortunately fixing the above exposed a potential problem in the
  block integration tests, where a failure in an "always" section may
  always lead to a failed state and the termination of execution
  beyond that point, so certain parts of the block integration test
  were disabled.
This commit is contained in:
James Cammarata
2016-03-09 13:29:22 -05:00
parent d7bd5fc075
commit 9d61a6cba8
3 changed files with 120 additions and 82 deletions

View File

@@ -33,17 +33,17 @@
- name: set block always run flag
set_fact:
block_always_run: true
- block:
- meta: noop
always:
- name: set nested block always run flag
set_fact:
nested_block_always_run: true
- name: fail in always
fail:
- name: tasks flag should not be set after failure in always
set_fact:
always_run_after_failure: true
#- block:
# - meta: noop
# always:
# - name: set nested block always run flag
# set_fact:
# nested_block_always_run: true
# - name: fail in always
# fail:
# - name: tasks flag should not be set after failure in always
# set_fact:
# always_run_after_failure: true
- meta: clear_host_errors
post_tasks:
@@ -52,7 +52,7 @@
- block_tasks_run
- block_rescue_run
- block_always_run
- nested_block_always_run
#- nested_block_always_run
- not tasks_run_after_failure
- not rescue_run_after_failure
- not always_run_after_failure
@@ -84,7 +84,7 @@
include: fail.yml
args:
msg: "failed from rescue"
- name: tasks flag should not be set after failure in rescue
- name: flag should not be set after failure in rescue
set_fact:
rescue_run_after_failure: true
always:

View File

@@ -116,9 +116,7 @@ class TestPlayIterator(unittest.TestCase):
# lookup up an original task
target_task = p._entries[0].tasks[0].block[0]
print("the task is: %s (%s)" % (target_task, target_task._uuid))
task_copy = target_task.copy(exclude_block=True)
print("the copied task is: %s (%s)" % (task_copy, task_copy._uuid))
found_task = itr.get_original_task(hosts[0], task_copy)
self.assertEqual(target_task, found_task)
@@ -209,18 +207,19 @@ class TestPlayIterator(unittest.TestCase):
- block:
- block:
- debug: msg="this is the first task"
rescue:
- block:
- ping:
rescue:
- block:
- block:
- block:
- debug: msg="this is the rescue task"
always:
- block:
- block:
- debug: msg="this is the rescue task"
always:
- block:
- block:
- block:
- debug: msg="this is the rescue task"
- block:
- debug: msg="this is the always task"
""",
})
@@ -254,28 +253,34 @@ class TestPlayIterator(unittest.TestCase):
(host_state, task) = itr.get_next_task_for_host(hosts[0])
self.assertIsNotNone(task)
self.assertEqual(task.action, 'meta')
self.assertEqual(task.args, dict(_raw_params='flush_handlers'))
# get the first task
(host_state, task) = itr.get_next_task_for_host(hosts[0])
self.assertIsNotNone(task)
self.assertEqual(task.action, 'debug')
self.assertEqual(task.args, dict(msg='this is the first task'))
# fail the host
itr.mark_host_failed(hosts[0])
# get the resuce task
(host_state, task) = itr.get_next_task_for_host(hosts[0])
self.assertIsNotNone(task)
self.assertEqual(task.action, 'debug')
self.assertEqual(task.args, dict(msg='this is the rescue task'))
# get the always task
(host_state, task) = itr.get_next_task_for_host(hosts[0])
self.assertIsNotNone(task)
self.assertEqual(task.action, 'debug')
self.assertEqual(task.args, dict(msg='this is the always task'))
# implicit meta: flush_handlers
(host_state, task) = itr.get_next_task_for_host(hosts[0])
self.assertIsNotNone(task)
self.assertEqual(task.action, 'meta')
self.assertEqual(task.args, dict(_raw_params='flush_handlers'))
# implicit meta: flush_handlers
(host_state, task) = itr.get_next_task_for_host(hosts[0])
self.assertIsNotNone(task)
self.assertEqual(task.action, 'meta')
self.assertEqual(task.args, dict(_raw_params='flush_handlers'))
# end of iteration
(host_state, task) = itr.get_next_task_for_host(hosts[0])
self.assertIsNone(task)