From 4e6cdf898980966705319658db5449dab1f35209 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Mon, 20 Mar 2017 10:08:13 -0400 Subject: [PATCH] better handling of parsed updated tests to match new result output (cherry picked from commit 5e98be2e62b7efe08a0aeb64d86630e0607d622e) --- lib/ansible/plugins/action/__init__.py | 4 ++-- test/units/plugins/action/test_action.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py index cf93eec276..fb62257c73 100644 --- a/lib/ansible/plugins/action/__init__.py +++ b/lib/ansible/plugins/action/__init__.py @@ -742,7 +742,6 @@ class ActionBase(with_metaclass(ABCMeta, object)): # remove internal keys self._remove_internal_keys(data) - data['_ansible_parsed'] = True # cleanup tmp? if (self._play_context.become and self._play_context.become_user != 'root') and not persist_files and delete_remote_tmp or tmpdir_delete: @@ -767,7 +766,7 @@ class ActionBase(with_metaclass(ABCMeta, object)): def _remove_internal_keys(self, data): for key in list(data.keys()): - if key.startswith('_ansible_') or key in C.INTERNAL_RESULT_KEYS: + if key.startswith('_ansible_') and key != '_ansible_parsed' or key in C.INTERNAL_RESULT_KEYS: display.warning("Removed unexpected internal key in module return: %s = %s" % (key, data[key])) del data[key] @@ -824,6 +823,7 @@ class ActionBase(with_metaclass(ABCMeta, object)): if 'ansible_facts' in data and isinstance(data['ansible_facts'], dict): self._clean_returned_data(data['ansible_facts']) data['ansible_facts'] = wrap_var(data['ansible_facts']) + data['_ansible_parsed'] = True except ValueError: # not valid json, lets try to capture error data = dict(failed=True, _ansible_parsed=False) diff --git a/test/units/plugins/action/test_action.py b/test/units/plugins/action/test_action.py index 3b0faa0b43..910d1192f4 100644 --- a/test/units/plugins/action/test_action.py +++ b/test/units/plugins/action/test_action.py @@ -591,6 +591,7 @@ class TestActionBaseParseReturnedData(unittest.TestCase): 'stdout_lines': stdout.splitlines(), 'stderr': err} res = action_base._parse_returned_data(returned_data) + del res['_ansible_parsed'] # we always have _ansible_parsed self.assertEqual(len(res), 0) self.assertFalse(res)