Squashed commit of the following:

commit 24efa310b58c431b4d888a6315d1285da918f670
Author: James Cammarata <jimi@sngx.net>
Date:   Tue Dec 29 11:23:52 2015 -0500

    Adding an additional test for copy exclusion

    Adds a negative test for the situation when an exclusion doesn't
    exist in the target to be copied.

commit 643ba054877cf042177d65e6e2958178bdd2fe88
Merge: e6ee59f 66a8f7e
Author: James Cammarata <jimi@sngx.net>
Date:   Tue Dec 29 10:59:18 2015 -0500

    Merge branch 'speedup' of https://github.com/chrismeyersfsu/ansible into chrismeyersfsu-speedup

commit 66a8f7e873ca90f7848e47b04d9b62aed23a45df
Author: Chris Meyers <chris.meyers.fsu@gmail.com>
Date:   Mon Dec 28 09:47:00 2015 -0500

    better api and tests added

    * _copy_results = deepcopy for better performance
    * _copy_results_exclude to deepcopy but exclude certain fields. Pop
    fields that do not need to be deep copied. Re-assign popped fields
    after deep copy so we don't modify the original, to be copied, object.
    * _copy_results_exclude unit tests

commit 93490960ff4e75f38a7cc6f6d49f10f949f1a7da
Author: Chris Meyers <chris.meyers.fsu@gmail.com>
Date:   Fri Dec 25 23:17:26 2015 -0600

    remove uneeded deepcopy fields
This commit is contained in:
James Cammarata 2015-12-29 11:40:18 -05:00
parent e6ee59fafe
commit 2d11cfab92
2 changed files with 97 additions and 4 deletions

View file

@ -59,9 +59,20 @@ class CallbackBase:
version = getattr(self, 'CALLBACK_VERSION', '1.0')
self._display.vvvv('Loaded callback %s of type %s, v%s' % (name, ctype, version))
def _copy_result(self, result):
''' helper for callbacks, so they don't all have to include deepcopy '''
return deepcopy(result)
''' helper for callbacks, so they don't all have to include deepcopy '''
_copy_result = deepcopy
def _copy_result_exclude(self, result, exclude):
values = []
for e in exclude:
values.append(getattr(result, e))
setattr(result, e, None)
result_copy = deepcopy(result)
for i,e in enumerate(exclude):
setattr(result, e, values[i])
return result_copy
def _dump_results(self, result, indent=None, sort_keys=True, keep_invocation=False):
if result.get('_ansible_no_log', False):
@ -130,7 +141,7 @@ class CallbackBase:
def _process_items(self, result):
for res in result._result['results']:
newres = self._copy_result(result)
newres = self._copy_result_exclude(result, ['_result'])
res['item'] = self._get_item(res)
newres._result = res
if 'failed' in res and res['failed']: