summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2019-03-15 20:21:34 +0000
committerGerrit Code Review <review@openstack.org>2019-03-15 20:21:35 +0000
commit9b6c7e60b511f1591dc802cda8c090677083cbd6 (patch)
tree76e41db278336a8a7304643471d7d6331636e8ae
parenta095e41e917a34dcc27c0752d7e28b003eb8b333 (diff)
parent81adf8c6e65e1525bf86316fbf213b83cfb5cf6d (diff)
Merge "Raise an error if pipeline is defined twice"
-rw-r--r--tests/fixtures/layouts/broken-double-gate.yaml47
-rw-r--r--tests/unit/test_model.py10
-rw-r--r--tests/unit/test_v3.py11
-rw-r--r--zuul/configloader.py1
-rw-r--r--zuul/model.py6
5 files changed, 67 insertions, 8 deletions
diff --git a/tests/fixtures/layouts/broken-double-gate.yaml b/tests/fixtures/layouts/broken-double-gate.yaml
new file mode 100644
index 0000000..c504820
--- /dev/null
+++ b/tests/fixtures/layouts/broken-double-gate.yaml
@@ -0,0 +1,47 @@
1- pipeline:
2 name: gate
3 manager: dependent
4 trigger:
5 gerrit:
6 - event: comment-added
7 approval:
8 - Approved: 1
9 success:
10 gerrit:
11 Verified: 2
12 submit: true
13 failure:
14 gerrit:
15 Verified: -2
16 start:
17 gerrit:
18 Verified: 0
19
20- pipeline:
21 name: gate
22 manager: dependent
23 trigger:
24 gerrit:
25 - event: comment-added
26 approval:
27 - Approved: 1
28 success:
29 gerrit:
30 Verified: 2
31 submit: true
32 failure:
33 gerrit:
34 Verified: -2
35 start:
36 gerrit:
37 Verified: 0
38
39- job:
40 name: base
41 parent: null
42
43- project:
44 name: org/project
45 gate:
46 jobs:
47 - base
diff --git a/tests/unit/test_model.py b/tests/unit/test_model.py
index 1726259..e4f3d2f 100644
--- a/tests/unit/test_model.py
+++ b/tests/unit/test_model.py
@@ -154,10 +154,7 @@ class TestJob(BaseTestCase):
154 job.applyVariant(bad_final, self.layout) 154 job.applyVariant(bad_final, self.layout)
155 155
156 def test_job_inheritance_job_tree(self): 156 def test_job_inheritance_job_tree(self):
157 pipeline = model.Pipeline('gate', self.tenant) 157 queue = model.ChangeQueue(self.pipeline)
158 pipeline.source_context = self.context
159 self.layout.addPipeline(pipeline)
160 queue = model.ChangeQueue(pipeline)
161 158
162 base = self.pcontext.job_parser.fromYaml({ 159 base = self.pcontext.job_parser.fromYaml({
163 '_source_context': self.context, 160 '_source_context': self.context,
@@ -229,10 +226,7 @@ class TestJob(BaseTestCase):
229 self.assertEqual(job.timeout, 70) 226 self.assertEqual(job.timeout, 70)
230 227
231 def test_inheritance_keeps_matchers(self): 228 def test_inheritance_keeps_matchers(self):
232 pipeline = model.Pipeline('gate', self.tenant) 229 queue = model.ChangeQueue(self.pipeline)
233 pipeline.source_context = self.context
234 self.layout.addPipeline(pipeline)
235 queue = model.ChangeQueue(pipeline)
236 230
237 base = self.pcontext.job_parser.fromYaml({ 231 base = self.pcontext.job_parser.fromYaml({
238 '_source_context': self.context, 232 '_source_context': self.context,
diff --git a/tests/unit/test_v3.py b/tests/unit/test_v3.py
index 075f776..4b769d1 100644
--- a/tests/unit/test_v3.py
+++ b/tests/unit/test_v3.py
@@ -2586,6 +2586,17 @@ class TestBrokenConfig(ZuulTestCase):
2586 "Zuul encountered a syntax error", 2586 "Zuul encountered a syntax error",
2587 str(tenant.layout.loading_errors[0].error)) 2587 str(tenant.layout.loading_errors[0].error))
2588 2588
2589 @simple_layout('layouts/broken-double-gate.yaml')
2590 def test_broken_config_on_startup_double_gate(self):
2591 # Verify that duplicated pipeline definitions raise config errors
2592 tenant = self.sched.abide.tenants.get('tenant-one')
2593 self.assertEquals(
2594 len(tenant.layout.loading_errors), 1,
2595 "An error should have been stored")
2596 self.assertIn(
2597 "Zuul encountered a syntax error",
2598 str(tenant.layout.loading_errors[0].error))
2599
2589 def test_dynamic_ignore(self): 2600 def test_dynamic_ignore(self):
2590 # Verify dynamic config behaviors inside a tenant broken config 2601 # Verify dynamic config behaviors inside a tenant broken config
2591 tenant = self.sched.abide.tenants.get('tenant-one') 2602 tenant = self.sched.abide.tenants.get('tenant-one')
diff --git a/zuul/configloader.py b/zuul/configloader.py
index 41d3d26..d0ba714 100644
--- a/zuul/configloader.py
+++ b/zuul/configloader.py
@@ -1129,6 +1129,7 @@ class PipelineParser(object):
1129 self.schema(conf) 1129 self.schema(conf)
1130 pipeline = model.Pipeline(conf['name'], self.pcontext.tenant) 1130 pipeline = model.Pipeline(conf['name'], self.pcontext.tenant)
1131 pipeline.source_context = conf['_source_context'] 1131 pipeline.source_context = conf['_source_context']
1132 pipeline.start_mark = conf['_start_mark']
1132 pipeline.description = conf.get('description') 1133 pipeline.description = conf.get('description')
1133 1134
1134 precedence = model.PRECEDENCE_MAP[conf.get('precedence')] 1135 precedence = model.PRECEDENCE_MAP[conf.get('precedence')]
diff --git a/zuul/model.py b/zuul/model.py
index 028a597..6e0c1bb 100644
--- a/zuul/model.py
+++ b/zuul/model.py
@@ -247,6 +247,7 @@ class Pipeline(object):
247 # reach the currently active layout for that tenant. 247 # reach the currently active layout for that tenant.
248 self.tenant = tenant 248 self.tenant = tenant
249 self.source_context = None 249 self.source_context = None
250 self.start_mark = None
250 self.description = None 251 self.description = None
251 self.failure_message = None 252 self.failure_message = None
252 self.merge_failure_message = None 253 self.merge_failure_message = None
@@ -3561,6 +3562,11 @@ class Layout(object):
3561 "may not be added to %s" % ( 3562 "may not be added to %s" % (
3562 pipeline.tenant, 3563 pipeline.tenant,
3563 self.tenant)) 3564 self.tenant))
3565
3566 if pipeline.name in self.pipelines:
3567 raise Exception(
3568 "Pipeline %s is already defined" % pipeline.name)
3569
3564 self.pipelines[pipeline.name] = pipeline 3570 self.pipelines[pipeline.name] = pipeline
3565 3571
3566 def addProjectTemplate(self, project_template): 3572 def addProjectTemplate(self, project_template):