Don't ignore inexistent jobs in config
Currently, when a project pipeline invokes a job which otherwise doesn't exist, zuul simply runs nothing. As this is not the desired behavior add a check during configuration time. This also uncovers some bugs in the tests which are also fixed. Change-Id: I37da435fdf3281f98ca097d79d504c170c13bf3a Story: 2000893
This commit is contained in:
parent
539c5f54b2
commit
f02cf516fe
@ -25,7 +25,7 @@
|
||||
- job:
|
||||
name: project1-test1
|
||||
- job:
|
||||
name: project2-test1
|
||||
name: project2-test2
|
||||
|
||||
- project:
|
||||
name: org/project1
|
||||
|
@ -5362,6 +5362,9 @@ class TestSemaphoreInRepo(ZuulTestCase):
|
||||
|
||||
in_repo_conf = textwrap.dedent(
|
||||
"""
|
||||
- job:
|
||||
name: project-test1
|
||||
|
||||
- job:
|
||||
name: project-test2
|
||||
semaphore: test-semaphore
|
||||
|
@ -89,6 +89,9 @@ class TestInRepoConfig(ZuulTestCase):
|
||||
def test_dynamic_config(self):
|
||||
in_repo_conf = textwrap.dedent(
|
||||
"""
|
||||
- job:
|
||||
name: project-test1
|
||||
|
||||
- job:
|
||||
name: project-test2
|
||||
|
||||
@ -135,6 +138,77 @@ class TestInRepoConfig(ZuulTestCase):
|
||||
dict(name='project-test2', result='SUCCESS', changes='1,1'),
|
||||
dict(name='project-test2', result='SUCCESS', changes='2,1')])
|
||||
|
||||
def test_dynamic_config_non_existing_job(self):
|
||||
"""Test that requesting a non existent job fails"""
|
||||
in_repo_conf = textwrap.dedent(
|
||||
"""
|
||||
- job:
|
||||
name: project-test1
|
||||
|
||||
- project:
|
||||
name: org/project
|
||||
check:
|
||||
jobs:
|
||||
- non-existent-job
|
||||
""")
|
||||
|
||||
in_repo_playbook = textwrap.dedent(
|
||||
"""
|
||||
- hosts: all
|
||||
tasks: []
|
||||
""")
|
||||
|
||||
file_dict = {'.zuul.yaml': in_repo_conf,
|
||||
'playbooks/project-test2.yaml': in_repo_playbook}
|
||||
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.assertHistory([])
|
||||
|
||||
def test_dynamic_config_non_existing_job_in_template(self):
|
||||
"""Test that requesting a non existent job fails"""
|
||||
in_repo_conf = textwrap.dedent(
|
||||
"""
|
||||
- job:
|
||||
name: project-test1
|
||||
|
||||
- project-template:
|
||||
name: test-template
|
||||
check:
|
||||
jobs:
|
||||
- non-existent-job
|
||||
|
||||
- project:
|
||||
name: org/project
|
||||
templates:
|
||||
- test-template
|
||||
""")
|
||||
|
||||
in_repo_playbook = textwrap.dedent(
|
||||
"""
|
||||
- hosts: all
|
||||
tasks: []
|
||||
""")
|
||||
|
||||
file_dict = {'.zuul.yaml': in_repo_conf,
|
||||
'playbooks/project-test2.yaml': in_repo_playbook}
|
||||
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.assertHistory([])
|
||||
|
||||
def test_dynamic_config_new_patchset(self):
|
||||
self.executor_server.hold_jobs_in_build = True
|
||||
|
||||
@ -143,6 +217,9 @@ class TestInRepoConfig(ZuulTestCase):
|
||||
|
||||
in_repo_conf = textwrap.dedent(
|
||||
"""
|
||||
- job:
|
||||
name: project-test1
|
||||
|
||||
- job:
|
||||
name: project-test2
|
||||
|
||||
@ -220,6 +297,9 @@ class TestInRepoConfig(ZuulTestCase):
|
||||
|
||||
in_repo_conf = textwrap.dedent(
|
||||
"""
|
||||
- job:
|
||||
name: project-test1
|
||||
|
||||
- job:
|
||||
name: project-test2
|
||||
|
||||
@ -259,6 +339,9 @@ class TestInRepoConfig(ZuulTestCase):
|
||||
def test_in_repo_branch(self):
|
||||
in_repo_conf = textwrap.dedent(
|
||||
"""
|
||||
- job:
|
||||
name: project-test1
|
||||
|
||||
- job:
|
||||
name: project-test2
|
||||
|
||||
@ -321,6 +404,9 @@ class TestInRepoConfig(ZuulTestCase):
|
||||
|
||||
in_repo_conf = textwrap.dedent(
|
||||
"""
|
||||
- job:
|
||||
name: project-test1
|
||||
|
||||
- job:
|
||||
name: project-test2
|
||||
|
||||
|
@ -644,6 +644,12 @@ class ProjectTemplateParser(object):
|
||||
raise Exception("Job must be a string or dictionary")
|
||||
attrs['_source_context'] = source_context
|
||||
attrs['_start_mark'] = start_mark
|
||||
|
||||
# validate that the job is existing
|
||||
with configuration_exceptions('project or project-template',
|
||||
attrs):
|
||||
layout.getJob(attrs['name'])
|
||||
|
||||
job_list.addJob(JobParser.fromYaml(tenant, layout, attrs,
|
||||
project_pipeline=True))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user