Start validating JJB job-templates
Initial commit to validate some JJB files. This validates for existence of required sections and where possible that no additional ones are available. It will catch some errors that the JJB parser misses, since JJB ignores unknown entries. Change-Id: I51606d7066af7d5761f09655eead48883f7f56dc Co-Authored-By: Andreas Jaeger <aj@suse.com> Signed-off-by: Paul Belanger <pabelanger@redhat.com>
This commit is contained in:
parent
0ed1587691
commit
8ccd1d987e
@ -14,8 +14,49 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import glob
|
||||
import sys
|
||||
import yaml
|
||||
|
||||
import voluptuous as v
|
||||
|
||||
BUILDER = v.Schema({
|
||||
v.Required('name'): v.All(str),
|
||||
v.Required('builders'): v.All(list)
|
||||
}, extra=True)
|
||||
|
||||
JOB = v.Schema({
|
||||
v.Required('builders'): v.All(list),
|
||||
v.Required('name'): v.All(str),
|
||||
'description': v.All(str),
|
||||
'node': v.All(str),
|
||||
'parameters': v.All(list),
|
||||
'publishers': v.All(list),
|
||||
'wrappers': v.All(list)
|
||||
})
|
||||
|
||||
JOB_GROUP = v.Schema({
|
||||
v.Required('name'): v.All(str),
|
||||
v.Required('jobs'): v.All(list)
|
||||
}, extra=True)
|
||||
|
||||
JOB_TEMPLATE = v.Schema({
|
||||
v.Required('builders'): v.All(list),
|
||||
v.Required('name'): v.All(str),
|
||||
'node': v.All(str),
|
||||
'publishers': v.All(list),
|
||||
'wrappers': v.All(list)
|
||||
})
|
||||
|
||||
PROJECT = v.Schema({
|
||||
v.Required('name'): v.All(str),
|
||||
v.Required('jobs'): v.All(list)
|
||||
}, extra=True)
|
||||
|
||||
PUBLISHER = v.Schema({
|
||||
v.Required('name'): v.All(str),
|
||||
v.Required('publishers'): v.All(list)
|
||||
})
|
||||
|
||||
def normalize(s):
|
||||
"Normalize string for comparison."
|
||||
@ -26,6 +67,9 @@ def check_alphabetical():
|
||||
"""Check that the projects are in alphabetical order
|
||||
and that indenting looks correct"""
|
||||
|
||||
print("Checking jenkins/jobs/projects.yaml")
|
||||
print("===================================")
|
||||
|
||||
# Note that the file has different sections and we need to check
|
||||
# entries within these sections only
|
||||
errors = False
|
||||
@ -47,16 +91,73 @@ def check_alphabetical():
|
||||
|
||||
count = count+1
|
||||
|
||||
if errors:
|
||||
print("Found errors in jenkins/jobs/projects.yaml!\n")
|
||||
else:
|
||||
print("No errors found in jenkins/jobs/projects.yaml!\n")
|
||||
|
||||
return errors
|
||||
|
||||
|
||||
def validate_jobs():
|
||||
"""Minimal YAML file validation."""
|
||||
|
||||
count = 0
|
||||
errors = False
|
||||
|
||||
print("Validating YAML files")
|
||||
print("=====================")
|
||||
|
||||
for job_file in glob.glob('jenkins/jobs/*.yaml'):
|
||||
jobs = yaml.load(open(job_file))
|
||||
for item in jobs:
|
||||
if 'builder' in item:
|
||||
schema = BUILDER
|
||||
entry = item['builder']
|
||||
elif 'job' in item:
|
||||
schema = JOB
|
||||
entry = item['job']
|
||||
elif 'job-group' in item:
|
||||
schema = JOB_GROUP
|
||||
entry = item['job-group']
|
||||
elif 'job-template' in item:
|
||||
schema = JOB_TEMPLATE
|
||||
entry = item['job-template']
|
||||
elif 'project' in item:
|
||||
schema = PROJECT
|
||||
entry = item['project']
|
||||
elif 'publisher' in item:
|
||||
schema = PUBLISHER
|
||||
entry = item['publisher']
|
||||
elif 'wrapper' in item:
|
||||
continue
|
||||
elif 'defaults' in item:
|
||||
continue
|
||||
else:
|
||||
print("Unknown entry in file %s" % job_file)
|
||||
print(item)
|
||||
try:
|
||||
schema(entry)
|
||||
except Exception as e:
|
||||
print("Failure in file %s" % job_file)
|
||||
print("Failure parsing item:")
|
||||
print(item)
|
||||
count += 1
|
||||
errors = True
|
||||
|
||||
print ("%d errors found validating YAML files in jenkins/jobs/*.yaml.\n" % count)
|
||||
return errors
|
||||
|
||||
|
||||
def check_all():
|
||||
errors = check_alphabetical()
|
||||
errors = validate_jobs()
|
||||
errors = check_alphabetical() or errors
|
||||
|
||||
if errors:
|
||||
print("Found errors in jenkins/jobs/projects.yaml!")
|
||||
print("Found errors in jenkins/jobs/*.yaml!")
|
||||
else:
|
||||
print("No errors found in jenkins/jobs/projects.yaml!")
|
||||
print("No errors found in jenkins/jobs/*.yaml!")
|
||||
|
||||
return errors
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
Reference in New Issue
Block a user