Enforce ref only for gerrit events that supply a ref

Invalid layout could be used and cause zuul to crash. If a ref
was specified for an event that did not supply a ref,
(e.g. patchset-created) then zuul would crash trying to match
the regex supplied in layout.yaml to event.ref, which would be
None. This results in all jobs failing, so this patch
makes sure that only the ref-updated gerrit event can have
a ref pattern specified.

Change-Id: I297e38f3749166ce54a946f6cbcf708744f20fa1
This commit is contained in:
Mike Heald 2014-08-15 12:44:53 +01:00
parent f2ee0d9495
commit e84ea64b02
3 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,13 @@
pipelines:
- name: 'check'
manager: IndependentPipelineManager
trigger:
gerrit:
- event: patchset-created
ref: /some/ref/path
projects:
- name: org/project
merge-mode: cherry-pick
check:
- project-check

View File

@ -18,6 +18,7 @@
import voluptuous as v
import string
from zuul.trigger import gerrit
# Several forms accept either a single item or a list, this makes
# specifying that in the schema easy (and explicit).
@ -262,3 +263,7 @@ class LayoutValidator(object):
if 'project-templates' in data:
self.checkDuplicateNames(
data['project-templates'], ['project-templates'])
for pipeline in data['pipelines']:
if 'gerrit' in pipeline['trigger']:
gerrit.validate_trigger(pipeline['trigger'])

View File

@ -16,6 +16,7 @@ import logging
import threading
import time
import urllib2
import voluptuous
from zuul.lib import gerrit
from zuul.model import TriggerEvent, Change
@ -383,3 +384,14 @@ class Gerrit(object):
if sha:
url += ';a=commitdiff;h=' + sha
return url
def validate_trigger(trigger_data):
"""Validates the layout's trigger data."""
events_with_ref = ('ref-updated', )
for event in trigger_data['gerrit']:
if event['event'] not in events_with_ref and event.get('ref', False):
raise voluptuous.Invalid(
"The event %s does not include ref information, Zuul cannot "
"use ref filter 'ref: %s'" % (event['event'], event['ref']))