summaryrefslogtreecommitdiff
path: root/zuul
diff options
context:
space:
mode:
authorMike Heald <mike.heald@hp.com>2014-08-15 12:44:53 +0100
committerMike Heald <mike.heald@hp.com>2014-10-07 16:56:32 +0100
commite84ea64b0257bedd7f56e23c20cee6490668201a (patch)
tree4bfe144492b30b957a5980ee07901422db6ee555 /zuul
parentf2ee0d9495c074befbac94e25d7110ce307b22d5 (diff)
downloadzuul-e84ea64b0257bedd7f56e23c20cee6490668201a.tar.gz
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
Diffstat (limited to 'zuul')
-rw-r--r--zuul/layoutvalidator.py5
-rw-r--r--zuul/trigger/gerrit.py12
2 files changed, 17 insertions, 0 deletions
diff --git a/zuul/layoutvalidator.py b/zuul/layoutvalidator.py
index 7256bc42e..b44590843 100644
--- a/zuul/layoutvalidator.py
+++ b/zuul/layoutvalidator.py
@@ -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'])
+
diff --git a/zuul/trigger/gerrit.py b/zuul/trigger/gerrit.py
index a6eedb10c..4840f5ac9 100644
--- a/zuul/trigger/gerrit.py
+++ b/zuul/trigger/gerrit.py
@@ -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']))
+