Merge "Add action to host results in zuul_json callback"

This commit is contained in:
Zuul 2019-01-18 09:43:54 +00:00 committed by Gerrit Code Review
commit d171a0c00e
2 changed files with 18 additions and 0 deletions

View File

@ -81,6 +81,22 @@ class TestZuulJSON(AnsibleZuulTestCase):
self.assertIn('rosebud', text)
self.assertNotIn('setec', text)
def test_json_task_action(self):
job = self._run_job('no-log')
with self.jobLog(job):
build = self.history[-1]
self.assertEqual(build.result, 'SUCCESS')
text = self._get_json_as_text(build)
json_result = json.loads(text)
tasks = json_result[0]['plays'][0]['tasks']
expected_actions = [
'debug', 'debug', 'debug', 'copy', 'find', 'stat', 'debug'
]
for i, expected in enumerate(expected_actions):
host_result = tasks[i]['hosts']['controller']
self.assertEquals(expected, host_result['action'])
def test_json_role_log(self):
job = self._run_job('json-role')
with self.jobLog(job):

View File

@ -132,6 +132,7 @@ class CallbackModule(CallbackBase):
def v2_runner_on_ok(self, result, **kwargs):
host = result._host
action = result._task.action
if result._result.get('_ansible_no_log', False) or result._task.no_log:
self.results[-1]['tasks'][-1]['hosts'][host.name] = dict(
censored="the output has been hidden due to the fact that"
@ -155,6 +156,7 @@ class CallbackModule(CallbackBase):
end_time = current_time()
self.results[-1]['tasks'][-1]['task']['duration']['end'] = end_time
self.results[-1]['play']['duration']['end'] = end_time
self.results[-1]['tasks'][-1]['hosts'][host.name]['action'] = action
def v2_playbook_on_stats(self, stats):
"""Display info about playbook statistics"""