diff --git a/config/zuul/layout.yaml b/config/zuul/layout.yaml index 5064b7cc..e9153294 100644 --- a/config/zuul/layout.yaml +++ b/config/zuul/layout.yaml @@ -145,10 +145,11 @@ projects: - dib-storm_1.0.1-u14-aio - dib-ambari_2.2-c7 - dib-ambari_2.2-u14 - + - name: openstack/sahara-ci-config check: - sahara-ci-syntax-check + - sahara-ci-layout - name: openstack/heat noop: diff --git a/host-scripts/check_layout.py b/host-scripts/check_layout.py new file mode 100644 index 00000000..756db656 --- /dev/null +++ b/host-scripts/check_layout.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python + +import os +import re +import sys + +import yaml + +layout = yaml.load(open(sys.argv[1])) + + +def grep(source, pattern): + found = False + p = re.compile(pattern) + for line in source: + if p.match(line): + found = True + break + return found + + +def get_pipelines(): + pipelines = [] + for pipeline in layout['pipelines']: + pipelines.append(pipeline['name']) + return pipelines + + +def check_jobs(): + errors = False + + pipelines = get_pipelines() + + job_list_file = sys.argv[2] + if not os.path.isfile(job_list_file): + print("Job list file %s does not exist, not checking jobs section" + % job_list_file) + return False + + with open(job_list_file, 'r') as f: + job_list = [line.rstrip() for line in f] + + for project in layout['projects']: + for pipeline in pipelines: + jobs = project.get(pipeline, []) + for job in jobs: + found = grep(job_list, job) + if not found: + print ("Regex %s has no matches in job list" % job) + errors = True + + return errors + +if __name__ == "__main__": + sys.exit(check_jobs()) diff --git a/host-scripts/check_layout.sh b/host-scripts/check_layout.sh new file mode 100755 index 00000000..6d542a1d --- /dev/null +++ b/host-scripts/check_layout.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +mkdir out +jenkins-jobs test -o out/ $WORKSPACE/jenkins_job_builder/ + + +find out/ -printf "%f\n" > job-list.txt + +python $WORKSPACE/host-scripts/check_layout.py $WORKSPACE/config/zuul/layout.yaml job-list.txt diff --git a/jenkins_job_builder/ci-infra.yaml b/jenkins_job_builder/ci-infra.yaml index f8384b4b..d924a3da 100644 --- a/jenkins_job_builder/ci-infra.yaml +++ b/jenkins_job_builder/ci-infra.yaml @@ -71,6 +71,24 @@ publishers: - console-log +- job: + name: sahara-ci-layout + project-type: freestyle + defaults: global + description: "This job is managed by Jenkins Job Builder, do not edit it through WebUI.\ + \n

Please use this repository to make changes: https://git.openstack.org/openstack/sahara-ci-config\ + \n

This job check compatibility zuul layout and jobs from jjb" + disabled: false + concurrent: false + node: master + + builders: + - gerrit-git-prep + - shell: "$WORKSPACE/host-scripts/check_layout.sh" + + publishers: + - console-log + - job: name: update-config node: master