summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornitzmahone <mdavis@ansible.com>2016-05-05 15:26:40 -0700
committernitzmahone <mdavis@ansible.com>2016-05-05 15:30:58 -0700
commit761cdc794ec18d0afa75a24508560fe45bf2bebb (patch)
tree3498f311d78c9a3704be2646da1fefd632d6ea2a
parentda1e62a6d96423f829b2d5d46c8f94cb3b7d8fe1 (diff)
downloadansible-761cdc794ec18d0afa75a24508560fe45bf2bebb.tar.gz
add jimi-c's unit test for squashed skip results, tweaked is_skipped() logic to pass
-rw-r--r--lib/ansible/executor/task_result.py11
-rw-r--r--test/units/executor/test_task_result.py9
2 files changed, 17 insertions, 3 deletions
diff --git a/lib/ansible/executor/task_result.py b/lib/ansible/executor/task_result.py
index db73f1ccb9..457a094b73 100644
--- a/lib/ansible/executor/task_result.py
+++ b/lib/ansible/executor/task_result.py
@@ -40,11 +40,16 @@ class TaskResult:
return self._check_key('changed')
def is_skipped(self):
+ # loop results
if 'results' in self._result and self._task.loop:
results = self._result['results']
- return results and all(isinstance(res, dict) and res.get('skipped', False) for res in results)
- else:
- return self._result.get('skipped', False)
+ # Loop tasks are only considered skipped if all items were skipped.
+ # some squashed results (eg, yum) are not dicts and can't be skipped individually
+ if results and all(isinstance(res, dict) and res.get('skipped', False) for res in results):
+ return True
+
+ # regular tasks and squashed non-dict results
+ return self._result.get('skipped', False)
def is_failed(self):
if 'failed_when_result' in self._result or \
diff --git a/test/units/executor/test_task_result.py b/test/units/executor/test_task_result.py
index a0af67edbd..c83d7b4489 100644
--- a/test/units/executor/test_task_result.py
+++ b/test/units/executor/test_task_result.py
@@ -85,6 +85,15 @@ class TestTaskResult(unittest.TestCase):
tr = TaskResult(mock_host, mock_task, dict(results=[dict(skipped=True), dict(skipped=True), dict(skipped=True)]))
self.assertTrue(tr.is_skipped())
+ # test with multiple squashed results (list of strings)
+ # first with the main result having skipped=False
+ mock_task.loop = 'foo'
+ tr = TaskResult(mock_host, mock_task, dict(results=["a", "b", "c"], skipped=False))
+ self.assertFalse(tr.is_skipped())
+ # then with the main result having skipped=True
+ tr = TaskResult(mock_host, mock_task, dict(results=["a", "b", "c"], skipped=True))
+ self.assertTrue(tr.is_skipped())
+
def test_task_result_is_unreachable(self):
mock_host = MagicMock()
mock_task = MagicMock()