summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Henkel <tobias.henkel@bmw.de>2019-01-28 15:29:24 +0100
committerTobias Henkel <tobias.henkel@bmw.de>2019-02-03 19:06:31 +0100
commitb999b7c8621d43ff60153f92680289a370efda62 (patch)
tree3a82cd8820efbabb1ea6048db61b4e8898f8ccbb
parentb44b6c532ce9a999b135d909ae9f9caf0671784d (diff)
Fix wedged scheduler on force-merge of non-existing template
If there is already a post pipeline defined a force-merge of a change referencing a non-existent project template currently can wedge the scheduler. In this case an exception is raised during reporting which throws the run handler completely out of its loop and the loop starts over from the beginning. However the item to be reported is not consumed in this case so zuul is stuck in an exception loop [1] and can only be recovered by a restart. This can be fixed by catching the exception and continuing the reporting. [1] Traceback: 2019-01-28 07:33:57,304 ERROR zuul.Scheduler: Exception in run handler: Traceback (most recent call last): File "/opt/zuul/lib/python3.6/site-packages/zuul/scheduler.py", line 1033, in run while (pipeline.manager.processQueue() and File "/opt/zuul/lib/python3.6/site-packages/zuul/manager/__init__.py", line 768, in processQueue item, nnfi) File "/opt/zuul/lib/python3.6/site-packages/zuul/manager/__init__.py", line 735, in _processOneItem self.reportItem(item) File "/opt/zuul/lib/python3.6/site-packages/zuul/manager/__init__.py", line 880, in reportItem item.reported = not self._reportItem(item) File "/opt/zuul/lib/python3.6/site-packages/zuul/manager/__init__.py", line 920, in _reportItem if not layout.getProjectPipelineConfig(item): File "/opt/zuul/lib/python3.6/site-packages/zuul/model.py", line 3435, in getProjectPipelineConfig templates = self.getProjectTemplates(template_name) File "/opt/zuul/lib/python3.6/site-packages/zuul/model.py", line 3374, in getProjectTemplates raise TemplateNotFoundError("Project template %s not found" % name) zuul.model.TemplateNotFoundError: Project template foo not found Change-Id: I1a3b59dadbd9337a8ba5b146f09ad093a0123ce8
Notes
Notes (review): Code-Review+2: Monty Taylor <mordred@inaugust.com> Code-Review+2: James E. Blair <corvus@inaugust.com> Workflow+1: James E. Blair <corvus@inaugust.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Tue, 05 Feb 2019 18:49:44 +0000 Reviewed-on: https://review.openstack.org/633514 Project: openstack-infra/zuul Branch: refs/heads/master
-rw-r--r--tests/fixtures/config/force-merge-template/git/common-config/playbooks/test.yaml2
-rw-r--r--tests/fixtures/config/force-merge-template/git/common-config/zuul.yaml35
-rw-r--r--tests/fixtures/config/force-merge-template/git/org_project/README1
-rw-r--r--tests/fixtures/config/force-merge-template/git/org_project/zuul.yaml7
-rw-r--r--tests/fixtures/config/force-merge-template/git/org_project2/README1
-rw-r--r--tests/fixtures/config/force-merge-template/git/org_project2/zuul.yaml4
-rw-r--r--tests/fixtures/config/force-merge-template/main.yaml17
-rw-r--r--tests/unit/test_v3.py44
-rw-r--r--zuul/manager/__init__.py7
9 files changed, 117 insertions, 1 deletions
diff --git a/tests/fixtures/config/force-merge-template/git/common-config/playbooks/test.yaml b/tests/fixtures/config/force-merge-template/git/common-config/playbooks/test.yaml
new file mode 100644
index 0000000..f679dce
--- /dev/null
+++ b/tests/fixtures/config/force-merge-template/git/common-config/playbooks/test.yaml
@@ -0,0 +1,2 @@
1- hosts: all
2 tasks: []
diff --git a/tests/fixtures/config/force-merge-template/git/common-config/zuul.yaml b/tests/fixtures/config/force-merge-template/git/common-config/zuul.yaml
new file mode 100644
index 0000000..27c5e5b
--- /dev/null
+++ b/tests/fixtures/config/force-merge-template/git/common-config/zuul.yaml
@@ -0,0 +1,35 @@
1- pipeline:
2 name: check
3 manager: independent
4 trigger:
5 gerrit:
6 - event: patchset-created
7 success:
8 gerrit:
9 Verified: 1
10 failure:
11 gerrit:
12 Verified: -1
13
14- pipeline:
15 name: post
16 manager: independent
17 trigger:
18 gerrit:
19 - event: ref-updated
20 ref: ^(?!refs/).*$
21 precedence: low
22
23
24- job:
25 name: base
26 parent: null
27
28- job:
29 name: post-job
30 run: playbooks/test.yaml
31
32- job:
33 name: other-job
34 run: playbooks/test.yaml
35
diff --git a/tests/fixtures/config/force-merge-template/git/org_project/README b/tests/fixtures/config/force-merge-template/git/org_project/README
new file mode 100644
index 0000000..9daeafb
--- /dev/null
+++ b/tests/fixtures/config/force-merge-template/git/org_project/README
@@ -0,0 +1 @@
test
diff --git a/tests/fixtures/config/force-merge-template/git/org_project/zuul.yaml b/tests/fixtures/config/force-merge-template/git/org_project/zuul.yaml
new file mode 100644
index 0000000..0d20a6d
--- /dev/null
+++ b/tests/fixtures/config/force-merge-template/git/org_project/zuul.yaml
@@ -0,0 +1,7 @@
1- project:
2 check:
3 jobs:
4 - noop
5 post:
6 jobs:
7 - post-job
diff --git a/tests/fixtures/config/force-merge-template/git/org_project2/README b/tests/fixtures/config/force-merge-template/git/org_project2/README
new file mode 100644
index 0000000..9daeafb
--- /dev/null
+++ b/tests/fixtures/config/force-merge-template/git/org_project2/README
@@ -0,0 +1 @@
test
diff --git a/tests/fixtures/config/force-merge-template/git/org_project2/zuul.yaml b/tests/fixtures/config/force-merge-template/git/org_project2/zuul.yaml
new file mode 100644
index 0000000..350c08c
--- /dev/null
+++ b/tests/fixtures/config/force-merge-template/git/org_project2/zuul.yaml
@@ -0,0 +1,4 @@
1- project:
2 check:
3 jobs:
4 - other-job
diff --git a/tests/fixtures/config/force-merge-template/main.yaml b/tests/fixtures/config/force-merge-template/main.yaml
new file mode 100644
index 0000000..7aed1a3
--- /dev/null
+++ b/tests/fixtures/config/force-merge-template/main.yaml
@@ -0,0 +1,17 @@
1- tenant:
2 name: tenant-one
3 source:
4 gerrit:
5 config-projects:
6 - common-config
7 untrusted-projects:
8 - org/project
9
10- tenant:
11 name: tenant-two
12 source:
13 gerrit:
14 config-projects:
15 - common-config
16 untrusted-projects:
17 - org/project2
diff --git a/tests/unit/test_v3.py b/tests/unit/test_v3.py
index 4ae89fd..bd96fa9 100644
--- a/tests/unit/test_v3.py
+++ b/tests/unit/test_v3.py
@@ -5002,3 +5002,47 @@ class TestProvidesRequires(ZuulDBTestCase):
5002 ]) 5002 ])
5003 self.assertIn('image-user : SKIPPED', B.messages[0]) 5003 self.assertIn('image-user : SKIPPED', B.messages[0])
5004 self.assertIn('not met by build', B.messages[0]) 5004 self.assertIn('not met by build', B.messages[0])
5005
5006
5007class TestForceMergeMissingTemplate(ZuulTestCase):
5008 tenant_config_file = "config/force-merge-template/main.yaml"
5009
5010 def test_force_merge_missing_template(self):
5011 """
5012 Tests that force merging a change using a non-existent project
5013 template triggering a post job doesn't wedge zuul on reporting.
5014 """
5015
5016 # Create change that adds uses a non-existent project template
5017 conf = textwrap.dedent(
5018 """
5019 - project:
5020 templates:
5021 - non-existent
5022 check:
5023 jobs:
5024 - noop
5025 post:
5026 jobs:
5027 - post-job
5028 """)
5029
5030 file_dict = {'zuul.yaml': conf}
5031 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
5032 files=file_dict)
5033
5034 # Now force merge the change
5035 A.setMerged()
5036 self.fake_gerrit.addEvent(A.getChangeMergedEvent())
5037 self.waitUntilSettled()
5038 self.fake_gerrit.addEvent(A.getRefUpdatedEvent())
5039 self.waitUntilSettled()
5040
5041 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
5042 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
5043 self.waitUntilSettled()
5044
5045 self.assertEqual(B.reported, 1)
5046 self.assertHistory([
5047 dict(name='other-job', result='SUCCESS', changes='2,1'),
5048 ])
diff --git a/zuul/manager/__init__.py b/zuul/manager/__init__.py
index 359d73d..22a25bb 100644
--- a/zuul/manager/__init__.py
+++ b/zuul/manager/__init__.py
@@ -912,7 +912,12 @@ class PipelineManager(object):
912 layout = (item.layout or self.pipeline.tenant.layout) 912 layout = (item.layout or self.pipeline.tenant.layout)
913 913
914 project_in_pipeline = True 914 project_in_pipeline = True
915 if not layout.getProjectPipelineConfig(item): 915 ppc = None
916 try:
917 ppc = layout.getProjectPipelineConfig(item)
918 except Exception:
919 self.log.exception("Invalid config for change %s" % item.change)
920 if not ppc:
916 self.log.debug("Project %s not in pipeline %s for change %s" % ( 921 self.log.debug("Project %s not in pipeline %s for change %s" % (
917 item.change.project, self.pipeline, item.change)) 922 item.change.project, self.pipeline, item.change))
918 project_in_pipeline = False 923 project_in_pipeline = False