Browse Source

Merge "Raise an error if pipeline is defined twice"

tags/3.7.0
Zuul 2 months ago
parent
commit
9b6c7e60b5

+ 47
- 0
tests/fixtures/layouts/broken-double-gate.yaml View File

@@ -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

+ 2
- 8
tests/unit/test_model.py View File

@@ -154,10 +154,7 @@ class TestJob(BaseTestCase):
154 154
             job.applyVariant(bad_final, self.layout)
155 155
 
156 156
     def test_job_inheritance_job_tree(self):
157
-        pipeline = model.Pipeline('gate', self.tenant)
158
-        pipeline.source_context = self.context
159
-        self.layout.addPipeline(pipeline)
160
-        queue = model.ChangeQueue(pipeline)
157
+        queue = model.ChangeQueue(self.pipeline)
161 158
 
162 159
         base = self.pcontext.job_parser.fromYaml({
163 160
             '_source_context': self.context,
@@ -229,10 +226,7 @@ class TestJob(BaseTestCase):
229 226
         self.assertEqual(job.timeout, 70)
230 227
 
231 228
     def test_inheritance_keeps_matchers(self):
232
-        pipeline = model.Pipeline('gate', self.tenant)
233
-        pipeline.source_context = self.context
234
-        self.layout.addPipeline(pipeline)
235
-        queue = model.ChangeQueue(pipeline)
229
+        queue = model.ChangeQueue(self.pipeline)
236 230
 
237 231
         base = self.pcontext.job_parser.fromYaml({
238 232
             '_source_context': self.context,

+ 11
- 0
tests/unit/test_v3.py View File

@@ -2586,6 +2586,17 @@ class TestBrokenConfig(ZuulTestCase):
2586 2586
             "Zuul encountered a syntax error",
2587 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 2600
     def test_dynamic_ignore(self):
2590 2601
         # Verify dynamic config behaviors inside a tenant broken config
2591 2602
         tenant = self.sched.abide.tenants.get('tenant-one')

+ 1
- 0
zuul/configloader.py View File

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

+ 6
- 0
zuul/model.py View File

@@ -247,6 +247,7 @@ class Pipeline(object):
247 247
         # reach the currently active layout for that tenant.
248 248
         self.tenant = tenant
249 249
         self.source_context = None
250
+        self.start_mark = None
250 251
         self.description = None
251 252
         self.failure_message = None
252 253
         self.merge_failure_message = None
@@ -3561,6 +3562,11 @@ class Layout(object):
3561 3562
                             "may not be added to %s" % (
3562 3563
                                 pipeline.tenant,
3563 3564
                                 self.tenant))
3565
+
3566
+        if pipeline.name in self.pipelines:
3567
+            raise Exception(
3568
+                "Pipeline %s is already defined" % pipeline.name)
3569
+
3564 3570
         self.pipelines[pipeline.name] = pipeline
3565 3571
 
3566 3572
     def addProjectTemplate(self, project_template):

Loading…
Cancel
Save