Merge "Add start and end timestamp to task and play result in zuul_json callback"
This commit is contained in:
commit
ac6a277060
|
@ -12,6 +12,8 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import dateutil
|
||||
import json
|
||||
import os
|
||||
import textwrap
|
||||
|
||||
|
@ -78,3 +80,31 @@ class TestZuulJSON(AnsibleZuulTestCase):
|
|||
text = self._get_json_as_text(build)
|
||||
self.assertIn('rosebud', text)
|
||||
self.assertNotIn('setec', text)
|
||||
|
||||
def test_json_time_log(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)
|
||||
# Assert that 'start' and 'end' are part of the result at all
|
||||
self.assertIn('start', text)
|
||||
self.assertIn('end', text)
|
||||
|
||||
json_result = json.loads(text)
|
||||
# Assert that the start and end timestamps are present at the
|
||||
# right place in the dictionary
|
||||
task = json_result[0]['plays'][0]['tasks'][0]['task']
|
||||
task_start_time = task['duration']['start']
|
||||
task_end_time = task['duration']['end']
|
||||
|
||||
play = json_result[0]['plays'][0]['play']
|
||||
play_start_time = play['duration']['start']
|
||||
play_end_time = play['duration']['end']
|
||||
|
||||
# Assert that the start and end timestamps are valid dates
|
||||
dateutil.parser.parse(task_start_time)
|
||||
dateutil.parser.parse(task_end_time)
|
||||
dateutil.parser.parse(play_start_time)
|
||||
dateutil.parser.parse(play_end_time)
|
||||
|
|
|
@ -23,6 +23,7 @@ from __future__ import (absolute_import, division, print_function)
|
|||
__metaclass__ = type
|
||||
|
||||
import copy
|
||||
import datetime
|
||||
import json
|
||||
import os
|
||||
|
||||
|
@ -37,6 +38,10 @@ except ImportError:
|
|||
from zuul.ansible import logconfig
|
||||
|
||||
|
||||
def current_time():
|
||||
return '%sZ' % datetime.datetime.utcnow().isoformat()
|
||||
|
||||
|
||||
class CallbackModule(CallbackBase):
|
||||
CALLBACK_VERSION = 2.0
|
||||
# aggregate means we can be loaded and not be the stdout plugin
|
||||
|
@ -89,6 +94,9 @@ class CallbackModule(CallbackBase):
|
|||
'play': {
|
||||
'name': play.name,
|
||||
'id': str(play._uuid),
|
||||
'duration': {
|
||||
'start': current_time()
|
||||
}
|
||||
},
|
||||
'tasks': []
|
||||
}
|
||||
|
@ -97,7 +105,10 @@ class CallbackModule(CallbackBase):
|
|||
return {
|
||||
'task': {
|
||||
'name': task.name,
|
||||
'id': str(task._uuid)
|
||||
'id': str(task._uuid),
|
||||
'duration': {
|
||||
'start': current_time()
|
||||
}
|
||||
},
|
||||
'hosts': {}
|
||||
}
|
||||
|
@ -136,6 +147,9 @@ class CallbackModule(CallbackBase):
|
|||
" 'no_log: true' was specified for this result")
|
||||
|
||||
self.results[-1]['tasks'][-1]['hosts'][host.name] = clean_result
|
||||
end_time = current_time()
|
||||
self.results[-1]['tasks'][-1]['task']['duration']['end'] = end_time
|
||||
self.results[-1]['play']['duration']['end'] = end_time
|
||||
|
||||
def v2_playbook_on_stats(self, stats):
|
||||
"""Display info about playbook statistics"""
|
||||
|
|
Loading…
Reference in New Issue