We had cases where zuul used unmerged job descriptions to a trusted parent job (change A) in non related downstream jobs (change B) not having zuul.yaml changes. This happened if the trusted parent job is not defined in the same config repo as the pipeline. E.g. if change A adds a new post playbook an unrelated change B fails with 'post playbook not found'. This is caused by the scheduler using the wrong unmerged job definition of change A but the final workspace contains the correct state without change A. In case of change B there is no dynamic layout and the current active layout should be taken. However it is taken directly from the pipeline object in getLayout (item.queue.pipeline.layout) which doesn't have the correct layout referenced at any time while the layout referenced by the tenant object is correct. Because the pipeline definition is in a different repository than the proposed config repo change, when the dynamic layout is created for the config repo change, the previously cached Pipeline objects are used to build the layout. These objects are the actual live pipelines, and when they are added to the layout, they have their Pipeline.layout attributes set to the dynamic layout. This dynamic layout is then not used further (it is only created for syntax validation), but the pipelines remain altered. We could go ahead and just change that to item.queue.pipeline.layout.tenant.layout but this feels awkward and would leave the possibility of similar bugs that are hard to find and debug. Further pipeline.layout is almost everywhere just used to get the tenant and not the layout. So this attempt to fix this bug goes further and completely rips out the layout from the Pipeline object and replaces it by the tenant. Because the tenant object is never expected to change during the lifetime of the pipeline object, holding the reference to the tenant, rather than the layout, is safe. Change-Id: I1e663f624db5e30a8f51b56134c37cc6e8217029
110 lines
3.8 KiB
Python
110 lines
3.8 KiB
Python
# Copyright 2017 Red Hat, Inc.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
import logging
|
|
import voluptuous as v
|
|
|
|
from zuul.reporter import BaseReporter
|
|
|
|
|
|
class MQTTReporter(BaseReporter):
|
|
"""Publish messages to a topic via mqtt"""
|
|
|
|
name = 'mqtt'
|
|
log = logging.getLogger("zuul.MQTTReporter")
|
|
|
|
def report(self, item):
|
|
self.log.debug("Report change %s, params %s" %
|
|
(item.change, self.config))
|
|
message = {
|
|
'action': self._action,
|
|
'tenant': item.pipeline.tenant.name,
|
|
'zuul_ref': item.current_build_set.ref,
|
|
'pipeline': item.pipeline.name,
|
|
'project': item.change.project.name,
|
|
'branch': getattr(item.change, 'branch', ''),
|
|
'change_url': item.change.url,
|
|
'change': getattr(item.change, 'number', ''),
|
|
'patchset': getattr(item.change, 'patchset', ''),
|
|
'ref': getattr(item.change, 'ref', ''),
|
|
'message': self._formatItemReport(
|
|
item, with_jobs=False),
|
|
'buildset': {
|
|
'uuid': item.current_build_set.uuid,
|
|
'builds': []
|
|
},
|
|
}
|
|
for job in item.getJobs():
|
|
job_informations = {
|
|
'job_name': job.name,
|
|
'voting': job.voting,
|
|
}
|
|
build = item.current_build_set.getBuild(job.name)
|
|
if build:
|
|
# Report build data if available
|
|
(result, url) = item.formatJobResult(job)
|
|
job_informations.update({
|
|
'uuid': build.uuid,
|
|
'start_time': build.start_time,
|
|
'end_time': build.end_time,
|
|
'log_url': url,
|
|
'result': result,
|
|
})
|
|
message['buildset']['builds'].append(job_informations)
|
|
topic = None
|
|
try:
|
|
topic = self.config['topic'].format(
|
|
tenant=item.pipeline.tenant.name,
|
|
pipeline=item.pipeline.name,
|
|
project=item.change.project.name,
|
|
branch=getattr(item.change, 'branch', None),
|
|
change=getattr(item.change, 'number', None),
|
|
patchset=getattr(item.change, 'patchset', None),
|
|
ref=getattr(item.change, 'ref', None))
|
|
except Exception:
|
|
self.log.exception("Error while formatting MQTT topic %s:"
|
|
% self.config['topic'])
|
|
if topic is not None:
|
|
self.connection.publish(
|
|
topic, message, qos=self.config.get('qos', 0))
|
|
|
|
|
|
def topicValue(value):
|
|
if not isinstance(value, str):
|
|
raise v.Invalid("topic is not a string")
|
|
try:
|
|
value.format(
|
|
tenant='test',
|
|
pipeline='test',
|
|
project='test',
|
|
branch='test',
|
|
change='test',
|
|
patchset='test',
|
|
ref='test')
|
|
except KeyError as e:
|
|
raise v.Invalid("topic component %s is invalid" % str(e))
|
|
return value
|
|
|
|
|
|
def qosValue(value):
|
|
if not isinstance(value, int):
|
|
raise v.Invalid("qos is not a integer")
|
|
if value not in (0, 1, 2):
|
|
raise v.Invalid("qos can only be 0, 1 or 2")
|
|
return value
|
|
|
|
|
|
def getSchema():
|
|
return v.Schema({v.Required('topic'): topicValue, 'qos': qosValue})
|