diff options
author | Mike Heald <mike.heald@hp.com> | 2014-08-15 12:44:53 +0100 |
---|---|---|
committer | Mike Heald <mike.heald@hp.com> | 2014-10-07 16:56:32 +0100 |
commit | e84ea64b0257bedd7f56e23c20cee6490668201a (patch) | |
tree | 4bfe144492b30b957a5980ee07901422db6ee555 | |
parent | f2ee0d9495c074befbac94e25d7110ce307b22d5 (diff) | |
download | zuul-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
-rw-r--r-- | tests/fixtures/layouts/bad_misplaced_ref.yaml | 13 | ||||
-rw-r--r-- | zuul/layoutvalidator.py | 5 | ||||
-rw-r--r-- | zuul/trigger/gerrit.py | 12 |
3 files changed, 30 insertions, 0 deletions
diff --git a/tests/fixtures/layouts/bad_misplaced_ref.yaml b/tests/fixtures/layouts/bad_misplaced_ref.yaml new file mode 100644 index 000000000..f009c397b --- /dev/null +++ b/tests/fixtures/layouts/bad_misplaced_ref.yaml @@ -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 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'])) + |