Add action to host results in zuul_json callback
Currently, this information is missing completely, although it's very useful when somebody wants to analyze the Ansible run based on the JSON log. After proposing this patch also for ansible, I've learned that this info is already visible in the original Ansible json callback: https://github.com/ansible/ansible/pull/50853 So, I've just added this missing part to the zuul_json callback. Change-Id: I1ee043fc1be95ec3260d3fe427653ffe8c09b8f7
This commit is contained in:
parent
1779565108
commit
f303dea90b
|
@ -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):
|
||||
|
|
|
@ -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"""
|
||||
|
|
Loading…
Reference in New Issue