From f303dea90b4c3789a41be6b9e186b0cb11aa3c99 Mon Sep 17 00:00:00 2001 From: Felix Schmidt Date: Mon, 14 Jan 2019 09:23:09 +0100 Subject: [PATCH] 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 --- tests/remote/test_remote_zuul_json.py | 16 ++++++++++++++++ zuul/ansible/callback/zuul_json.py | 2 ++ 2 files changed, 18 insertions(+) diff --git a/tests/remote/test_remote_zuul_json.py b/tests/remote/test_remote_zuul_json.py index 11c03e207a..36c6b6bb61 100644 --- a/tests/remote/test_remote_zuul_json.py +++ b/tests/remote/test_remote_zuul_json.py @@ -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): diff --git a/zuul/ansible/callback/zuul_json.py b/zuul/ansible/callback/zuul_json.py index bbd2c24868..e52e2e24d1 100644 --- a/zuul/ansible/callback/zuul_json.py +++ b/zuul/ansible/callback/zuul_json.py @@ -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"""