better handling of parsed

updated tests to match new result output

(cherry picked from commit 5e98be2e62)
This commit is contained in:
Brian Coca 2017-03-20 10:08:13 -04:00
parent 4f8a2d3806
commit 4e6cdf8989
2 changed files with 3 additions and 2 deletions

View file

@ -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)

View file

@ -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)