Merge "Raise an error if pipeline is defined twice"

This commit is contained in:
Zuul 2019-03-15 20:21:34 +00:00 committed by Gerrit Code Review
commit 9b6c7e60b5
5 changed files with 67 additions and 8 deletions

View File

@ -0,0 +1,47 @@
- pipeline:
name: gate
manager: dependent
trigger:
gerrit:
- event: comment-added
approval:
- Approved: 1
success:
gerrit:
Verified: 2
submit: true
failure:
gerrit:
Verified: -2
start:
gerrit:
Verified: 0
- pipeline:
name: gate
manager: dependent
trigger:
gerrit:
- event: comment-added
approval:
- Approved: 1
success:
gerrit:
Verified: 2
submit: true
failure:
gerrit:
Verified: -2
start:
gerrit:
Verified: 0
- job:
name: base
parent: null
- project:
name: org/project
gate:
jobs:
- base

View File

@ -154,10 +154,7 @@ class TestJob(BaseTestCase):
job.applyVariant(bad_final, self.layout)
def test_job_inheritance_job_tree(self):
pipeline = model.Pipeline('gate', self.tenant)
pipeline.source_context = self.context
self.layout.addPipeline(pipeline)
queue = model.ChangeQueue(pipeline)
queue = model.ChangeQueue(self.pipeline)
base = self.pcontext.job_parser.fromYaml({
'_source_context': self.context,
@ -229,10 +226,7 @@ class TestJob(BaseTestCase):
self.assertEqual(job.timeout, 70)
def test_inheritance_keeps_matchers(self):
pipeline = model.Pipeline('gate', self.tenant)
pipeline.source_context = self.context
self.layout.addPipeline(pipeline)
queue = model.ChangeQueue(pipeline)
queue = model.ChangeQueue(self.pipeline)
base = self.pcontext.job_parser.fromYaml({
'_source_context': self.context,

View File

@ -2586,6 +2586,17 @@ class TestBrokenConfig(ZuulTestCase):
"Zuul encountered a syntax error",
str(tenant.layout.loading_errors[0].error))
@simple_layout('layouts/broken-double-gate.yaml')
def test_broken_config_on_startup_double_gate(self):
# Verify that duplicated pipeline definitions raise config errors
tenant = self.sched.abide.tenants.get('tenant-one')
self.assertEquals(
len(tenant.layout.loading_errors), 1,
"An error should have been stored")
self.assertIn(
"Zuul encountered a syntax error",
str(tenant.layout.loading_errors[0].error))
def test_dynamic_ignore(self):
# Verify dynamic config behaviors inside a tenant broken config
tenant = self.sched.abide.tenants.get('tenant-one')

View File

@ -1129,6 +1129,7 @@ class PipelineParser(object):
self.schema(conf)
pipeline = model.Pipeline(conf['name'], self.pcontext.tenant)
pipeline.source_context = conf['_source_context']
pipeline.start_mark = conf['_start_mark']
pipeline.description = conf.get('description')
precedence = model.PRECEDENCE_MAP[conf.get('precedence')]

View File

@ -247,6 +247,7 @@ class Pipeline(object):
# reach the currently active layout for that tenant.
self.tenant = tenant
self.source_context = None
self.start_mark = None
self.description = None
self.failure_message = None
self.merge_failure_message = None
@ -3561,6 +3562,11 @@ class Layout(object):
"may not be added to %s" % (
pipeline.tenant,
self.tenant))
if pipeline.name in self.pipelines:
raise Exception(
"Pipeline %s is already defined" % pipeline.name)
self.pipelines[pipeline.name] = pipeline
def addProjectTemplate(self, project_template):