Log execution phase and include information

We pass the execution phase and the index of the phase now, so emit it
into the play banners in the log. This will allow us to post-process the
logs and put in smart things like "collapse pre tasks".

Also include information about include statements.

Also rename zuul_execution_phase_count to zuul_execution_phase_index -
mainly just because it's an index not a count. My shed is red.

Change-Id: I975ed9547bbcdbb70d5a25c9be398888bdcdb07a
changes/44/483044/4
Monty Taylor 5 years ago
parent b09cb00b85
commit 393ee76e59
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
  1. 25
      zuul/ansible/callback/zuul_stream.py
  2. 14
      zuul/executor/server.py

@ -150,14 +150,29 @@ class CallbackModule(default.CallbackModule):
def v2_playbook_on_start(self, playbook):
self._playbook_name = os.path.splitext(playbook._file_name)[0]
def v2_playbook_on_include(self, included_file):
for host in included_file._hosts:
self._log("{host} | included: {filename}".format(
host=host.name,
filename=included_file._filename))
def v2_playbook_on_play_start(self, play):
self._play = play
# Get the hostvars from just one host - the vars we're looking for will
# be identical on all of them
hostvars = self._play._variable_manager._hostvars
a_host = hostvars.keys()[0]
self.phase = hostvars[a_host]['zuul_execution_phase']
if self.phase != 'run':
self.phase = '{phase}-{index}'.format(
phase=self.phase,
index=hostvars[a_host]['zuul_execution_phase_index'])
# the name of a play defaults to the hosts string
name = play.get_name().strip()
if not name:
msg = u"PLAY"
else:
msg = u"PLAY [{playbook} : {name}]".format(
playbook=self._playbook_name, name=name)
msg = u"PLAY [{phase} : {playbook} : {name}]".format(
phase=self.phase,
playbook=self._playbook_name, name=name)
self._log(msg)
# Log an extra blank line to get space after each play

@ -883,10 +883,10 @@ class AnsibleJob(object):
result = None
pre_failed = False
for count, playbook in enumerate(self.jobdir.pre_playbooks):
for index, playbook in enumerate(self.jobdir.pre_playbooks):
# TODOv3(pabelanger): Implement pre-run timeout setting.
pre_status, pre_code = self.runAnsiblePlaybook(
playbook, args['timeout'], phase='pre', count=count)
playbook, args['timeout'], phase='pre', index=index)
if pre_status != self.RESULT_NORMAL or pre_code != 0:
# These should really never fail, so return None and have
# zuul try again
@ -912,10 +912,10 @@ class AnsibleJob(object):
else:
result = 'FAILURE'
for count, playbook in enumerate(self.jobdir.post_playbooks):
for index, playbook in enumerate(self.jobdir.post_playbooks):
# TODOv3(pabelanger): Implement post-run timeout setting.
post_status, post_code = self.runAnsiblePlaybook(
playbook, args['timeout'], success, phase='post', count=count)
playbook, args['timeout'], success, phase='post', index=index)
if post_status != self.RESULT_NORMAL or post_code != 0:
# If we encountered a pre-failure, that takes
# precedence over the post result.
@ -1373,7 +1373,7 @@ class AnsibleJob(object):
return (self.RESULT_NORMAL, ret)
def runAnsiblePlaybook(self, playbook, timeout, success=None,
phase=None, count=None):
phase=None, index=None):
env_copy = os.environ.copy()
env_copy['LOGNAME'] = 'zuul'
@ -1390,8 +1390,8 @@ class AnsibleJob(object):
if phase:
cmd.extend(['-e', 'zuul_execution_phase=%s' % phase])
if count is not None:
cmd.extend(['-e', 'zuul_execution_phase_count=%s' % count])
if index is not None:
cmd.extend(['-e', 'zuul_execution_phase_index=%s' % index])
result, code = self.runAnsible(
cmd=cmd, timeout=timeout, trusted=playbook.trusted)

Loading…
Cancel
Save