Fix "Set failed, unreachable, skipped statuses in json plugin"

This change was ineffective because it was modifying the wrong data.
Correct that and add a test.

Change-Id: I26cfba0ff9a3eca05314e12f3f1d66b934c505b6
This commit is contained in:
James E. Blair
2019-09-04 13:13:41 -07:00
parent 90b1add80a
commit cfe6a7b985
3 changed files with 14 additions and 2 deletions

View File

@@ -1,3 +1,8 @@
- hosts: all
tasks:
- shell: echo "Standard output test {{ zuul.executor.src_root }}"
- shell: echo "This should be skipped"
when: false
- fail:
msg: "This should fail"
ignore_errors: true

View File

@@ -4911,6 +4911,7 @@ class TestJobOutput(AnsibleZuulTestCase):
A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
self.waitUntilSettled()
self.assertHistory([
dict(name='job-output', result='SUCCESS', changes='1,1'),
], ordered=False)
@@ -4921,6 +4922,10 @@ class TestJobOutput(AnsibleZuulTestCase):
self.assertEqual(token,
j[0]['plays'][0]['tasks'][0]
['hosts']['localhost']['stdout'])
self.assertTrue(j[0]['plays'][0]['tasks'][1]
['hosts']['localhost']['skipped'])
self.assertTrue(j[0]['plays'][0]['tasks'][2]
['hosts']['localhost']['failed'])
self.log.info(self._get_file(self.history[0],
'work/logs/job-output.txt'))

View File

@@ -158,11 +158,13 @@ class CallbackModule(CallbackBase):
def v2_runner_on_failed(self, result, **kwargs):
self.v2_runner_on_ok(result, **kwargs)
result._host.setdefault('failed', True)
self.results[-1]['tasks'][-1]['hosts'][result._host.name].\
setdefault('failed', True)
def v2_runner_on_skipped(self, result, **kwargs):
self.v2_runner_on_ok(result, **kwargs)
result._host.setdefault('skipped', True)
self.results[-1]['tasks'][-1]['hosts'][result._host.name].\
setdefault('skipped', True)
def v2_playbook_on_stats(self, stats):
"""Display info about playbook statistics"""