Provide error message on malformed job list
In project and project-template definitions, the existing voluptuous
schema for the jobs in the job list was vs.Any(str, dict). The contents
of the dict itself need to be validated though, the job being a dict
that looks like:
check:
jobs:
- project-test1:
- required-projects:
org/project2
Is invalid as the contents of the build-openstack-sphinx-docs job dict
should themselves be a string or a dict rather than a list. This updates
the error to be:
Zuul encountered a syntax error while parsing its configuration in the
repo org/project on branch master. The error was:
expected str for dictionary value @ data['check']['jobs'][0]['project-test1']
The error appears in the following project stanza:
project:
name: org/project1
check:
jobs:
- project-test1:
- required-projects:
org/project2
in "org/project/.zuul.yaml@master", line 4, column 3
The error, 'expected str for dictionary value' could probably be
improved at some point, but this is at least an error with a message
which is way better than 'Unknown configuration error'.
Split out the attributes of the job in the JobParser voluptuous schema
that can be used in job lists from the ones that can't. For now it's
only name that can't be used.
Also fix a test fixture that had a trailing : in it.
Change-Id: I217eb5d6befbed51b220d47afa18997a87982389
diff --git a/tests/fixtures/layouts/delayed-repo-init.yaml b/tests/fixtures/layouts/delayed-repo-init.yaml
index e97d37a..c89e2fa 100644
--- a/tests/fixtures/layouts/delayed-repo-init.yaml
+++ b/tests/fixtures/layouts/delayed-repo-init.yaml
@@ -67,7 +67,7 @@
dependencies: project-merge
gate:
jobs:
- - project-merge:
+ - project-merge
- project-test1:
dependencies: project-merge
- project-test2:
diff --git a/tests/unit/test_v3.py b/tests/unit/test_v3.py
index 1c633ba..68ea74f 100755
--- a/tests/unit/test_v3.py
+++ b/tests/unit/test_v3.py
@@ -816,6 +816,60 @@
A.messages[0],
"A should have a syntax error reported")
+ def test_job_list_in_project_template_not_dict_error(self):
+ in_repo_conf = textwrap.dedent(
+ """
+ - job:
+ name: project-test1
+ - project-template:
+ name: some-jobs
+ check:
+ jobs:
+ - project-test1:
+ - required-projects:
+ org/project2
+ """)
+
+ 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('expected str for dictionary value',
+ A.messages[0], "A should have a syntax error reported")
+
+ def test_job_list_in_project_not_dict_error(self):
+ in_repo_conf = textwrap.dedent(
+ """
+ - job:
+ name: project-test1
+ - project:
+ name: org/project1
+ check:
+ jobs:
+ - project-test1:
+ - required-projects:
+ org/project2
+ """)
+
+ 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('expected str for dictionary value',
+ A.messages[0], "A should have a syntax error reported")
+
def test_multi_repo(self):
downstream_repo_conf = textwrap.dedent(
"""