config: show error for all unknown projects
At the moment, Zuul only shows an error for the first unknown project that it encounters. However, it's possible that it may encounter more than one so we gather a list of them and warn the user with the entire list instead. Change-Id: I110f63179240178b80b27da53cab2319e36a5600
This commit is contained in:
@@ -1935,9 +1935,34 @@ class TestInRepoConfig(ZuulTestCase):
|
||||
self.assertEqual(A.data['status'], 'NEW')
|
||||
self.assertEqual(A.reported, 1,
|
||||
"A should report failure")
|
||||
self.assertIn('Unknown project does-not-exist', A.messages[0],
|
||||
self.assertIn('Unknown projects: does-not-exist', A.messages[0],
|
||||
"A should have a syntax error reported")
|
||||
|
||||
def test_required_project_not_found_multiple_error(self):
|
||||
in_repo_conf = textwrap.dedent(
|
||||
"""
|
||||
- job:
|
||||
name: project-test1
|
||||
- job:
|
||||
name: test
|
||||
required-projects:
|
||||
- does-not-exist
|
||||
- also-does-not-exist
|
||||
""")
|
||||
|
||||
file_dict = {'.zuul.yaml': in_repo_conf}
|
||||
A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
|
||||
files=file_dict)
|
||||
A.addApproval('Code-Review', 2)
|
||||
self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
|
||||
self.waitUntilSettled()
|
||||
|
||||
self.assertEqual(A.data['status'], 'NEW')
|
||||
self.assertEqual(A.reported, 1,
|
||||
"A should report failure")
|
||||
self.assertIn('Unknown projects: does-not-exist, also-does-not-exist',
|
||||
A.messages[0], "A should have a syntax error reported")
|
||||
|
||||
def test_template_not_found_error(self):
|
||||
in_repo_conf = textwrap.dedent(
|
||||
"""
|
||||
|
||||
@@ -822,6 +822,7 @@ class JobParser(object):
|
||||
if 'required-projects' in conf:
|
||||
new_projects = {}
|
||||
projects = as_list(conf.get('required-projects', []))
|
||||
unknown_projects = []
|
||||
for project in projects:
|
||||
if isinstance(project, dict):
|
||||
project_name = project['name']
|
||||
@@ -835,11 +836,20 @@ class JobParser(object):
|
||||
(trusted, project) = self.pcontext.tenant.getProject(
|
||||
project_name)
|
||||
if project is None:
|
||||
raise Exception("Unknown project %s" % (project_name,))
|
||||
unknown_projects.append(project_name)
|
||||
continue
|
||||
job_project = model.JobProject(project.canonical_name,
|
||||
project_override_branch,
|
||||
project_override_checkout)
|
||||
new_projects[project.canonical_name] = job_project
|
||||
|
||||
# NOTE(mnaser): We accumulate all unknown projects and throw an
|
||||
# exception only once to capture all of them in the
|
||||
# error message.
|
||||
if unknown_projects:
|
||||
names = ", ".join(unknown_projects)
|
||||
raise Exception("Unknown projects: %s" % (names,))
|
||||
|
||||
job.required_projects = new_projects
|
||||
|
||||
if 'dependencies' in conf:
|
||||
|
||||
Reference in New Issue
Block a user