diff options
author | Zuul <zuul@review.opendev.org> | 2022-07-01 13:09:45 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2022-07-01 13:09:45 +0000 |
commit | 43f23a96dbb0f61f736d5178e610d768237dfb38 (patch) | |
tree | 71634d61b1b9ea26ae4098adfd6be9195c7a9c0b | |
parent | 29a1313801493d542b91cf7351feb618b5a05253 (diff) | |
parent | 026de6587b14c2f6fa19c1208f5615566fcba02b (diff) | |
download | zuul-43f23a96dbb0f61f736d5178e610d768237dfb38.tar.gz |
Merge "Validate dependent job names"
-rw-r--r-- | releasenotes/notes/dependency-validation-000f63204da83b4a.yaml | 12 | ||||
-rw-r--r-- | tests/unit/test_v3.py | 32 | ||||
-rw-r--r-- | zuul/model.py | 2 |
3 files changed, 46 insertions, 0 deletions
diff --git a/releasenotes/notes/dependency-validation-000f63204da83b4a.yaml b/releasenotes/notes/dependency-validation-000f63204da83b4a.yaml new file mode 100644 index 000000000..0f88a06fa --- /dev/null +++ b/releasenotes/notes/dependency-validation-000f63204da83b4a.yaml @@ -0,0 +1,12 @@ +--- +fixes: + - | + Zuul now treats job dependencies that reference undefined jobs as + a configuration error. Previously a job which depended on another + job which did not exist would pass initial syntax validation and + only cause a failure in freezing the job graph when Zuul attempted + to run the job. Now incorrect or missing job dependencies are + detected during configuration. This means that new config errors + may be prevented from merging. It also means that existing + erroneous job or project configurations will be regarded as + configuration errors at startup. diff --git a/tests/unit/test_v3.py b/tests/unit/test_v3.py index a461c9589..ac10eda47 100644 --- a/tests/unit/test_v3.py +++ b/tests/unit/test_v3.py @@ -1479,6 +1479,38 @@ class TestInRepoConfig(ZuulTestCase): "A should have failed the check pipeline") self.assertHistory([]) + def test_dynamic_nonexistent_job_dependency(self): + # Tests that a reference to a nonexistent job dependency is an + # error. + in_repo_conf = textwrap.dedent( + """ + - job: + name: project-test1 + run: playbooks/project-test1.yaml + + - project: + name: org/project + check: + jobs: + - project-test1: + dependencies: + - name: non-existent-job + soft: true + """) + + file_dict = {'.zuul.yaml': in_repo_conf} + A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A', + files=file_dict) + self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) + self.waitUntilSettled() + self.assertEqual(A.reported, 1, + "A should report failure") + self.assertEqual(A.patchsets[0]['approvals'][0]['value'], "-1") + self.assertIn('Job non-existent-job not defined', A.messages[0], + "A should have failed the check pipeline") + self.assertNotIn('freezing', A.messages[0]) + self.assertHistory([]) + def test_dynamic_config_new_patchset(self): self.executor_server.hold_jobs_in_build = True diff --git a/zuul/model.py b/zuul/model.py index ea66503d5..aa814ce6c 100644 --- a/zuul/model.py +++ b/zuul/model.py @@ -2708,6 +2708,8 @@ class Job(ConfigObject): job=self.name, maxnodes=layout.tenant.max_nodes_per_job)) + for dependency in self.dependencies: + layout.getJob(dependency.name) for pb in self.pre_run + self.run + self.post_run + self.cleanup_run: pb.validateReferences(layout) |