From 9b962c5dcb77dc3e7687f75030ea41de30a54746 Mon Sep 17 00:00:00 2001 From: David Moreau Simard Date: Sun, 4 Feb 2018 10:12:27 -0500 Subject: [PATCH] Fix unit tests and handle versions of Ansible returning non-bool ignore_errors This is a squashed commit in order to make all tests pass. - Fix fake task result unit test returning a skipped tuple It's meant to be a boolean, not a tuple. Stray comma made it a tuple. - Handler older versions of Ansible returning a non-bool ignore_errors Older versions of Ansible could sometimes return a non-boolean value for ignore_errors. Work around the issue in the callback plugin. Change-Id: If82ec57d8218c704dcd80de39bafb36e611be52c --- ara/plugins/callbacks/log_ara.py | 9 ++++++++- ara/tests/unit/common.py | 5 +++-- ara/tests/unit/fakes.py | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ara/plugins/callbacks/log_ara.py b/ara/plugins/callbacks/log_ara.py index 2038ca8b..91ea5e85 100644 --- a/ara/plugins/callbacks/log_ara.py +++ b/ara/plugins/callbacks/log_ara.py @@ -158,6 +158,13 @@ class CallbackModule(CallbackBase): else: results = jsonutils.loads(self._dump_results(result._result)) + # Ignore errors can be "yes" instead of a proper boolean in <2.3 + # for some reason + ignore_errors = kwargs.get('ignore_errors', False) + if LooseVersion(ansible_version) < LooseVersion('2.3.0'): + if not isinstance(ignore_errors, bool): + ignore_errors = True if ignore_errors == "yes" else False + self.taskresult = models.TaskResult( task=self.task, host=host, @@ -169,7 +176,7 @@ class CallbackModule(CallbackBase): failed=result._result.get('failed', False), skipped=result._result.get('skipped', False), unreachable=result._result.get('unreachable', False), - ignore_errors=kwargs.get('ignore_errors', False), + ignore_errors=ignore_errors, ) db.session.add(self.taskresult) diff --git a/ara/tests/unit/common.py b/ara/tests/unit/common.py index c3e9c690..13a66780 100644 --- a/ara/tests/unit/common.py +++ b/ara/tests/unit/common.py @@ -139,6 +139,7 @@ def ansible_run(complete=True, failed=False, gather_facts=True, host=host, status='ok', changed=True, + skipped=skipped, result=msg).model data = fakes.Data(playbook=playbook).model @@ -151,7 +152,7 @@ def ansible_run(complete=True, failed=False, gather_facts=True, host=host, status='skipped', changed=False, - skipped=True, + skipped=skipped, result=msg).model task_results.append(record_result) @@ -176,7 +177,7 @@ def ansible_run(complete=True, failed=False, gather_facts=True, host=host, status='skipped', changed=False, - skipped=True, + skipped=skipped, result=msg).model task_results.append(failed_result) diff --git a/ara/tests/unit/fakes.py b/ara/tests/unit/fakes.py index ca276a41..01ca91f7 100644 --- a/ara/tests/unit/fakes.py +++ b/ara/tests/unit/fakes.py @@ -212,7 +212,7 @@ class TaskResult(object): self.ignore_errors = ignore_errors self.changed = changed self.failed = failed - self.skipped = skipped, + self.skipped = skipped self.unreachable = unreachable self.result = result