From c6b1ffd04f07c7c81828de8ab63bc88222e68bde Mon Sep 17 00:00:00 2001 From: Andreas Jaeger Date: Sat, 27 Sep 2014 14:41:50 +0200 Subject: [PATCH] Add more checks for zuul/layout.yaml Check that each project (with exception of z/tempest) has a merge-check template. Check projects - so far stackforge only - for alphabetical order. The merge template check is taken from a test that Jeremy shared. Change-Id: I2bc457ddfe0eca787bb88ceeb919f89d491978d7 Co-Authored-By: Jeremy Stanley --- tools/layout-checks.py | 79 ++++++++++++++++++++++++++++++++++++++++++ tox.ini | 1 + 2 files changed, 80 insertions(+) create mode 100755 tools/layout-checks.py diff --git a/tools/layout-checks.py b/tools/layout-checks.py new file mode 100755 index 0000000000..c84102d810 --- /dev/null +++ b/tools/layout-checks.py @@ -0,0 +1,79 @@ +#!/usr/bin/python + +# Copyright 2014 OpenStack Foundation +# Copyright 2014 SUSE Linux Products GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import yaml +import sys + +layout = yaml.load(open('zuul/layout.yaml')) + + +def check_merge_template(): + """Check that each job has a merge-check template.""" + + errors = False + for project in layout['projects']: + if project['name'] == 'z/tempest': + continue + try: + correct = False + for template in project['template']: + if template['name'] == 'merge-check': + correct = True + if not correct: + raise + except: + print("Project %s has no merge-check template" % project['name']) + errors = True + return errors + + +def normalize(s): + "Normalize string for comparison." + return s.lower().replace("_", "-") + + +def check_alphabetical(): + """Check that projects are sorted alphabetical.""" + + errors = False + # For now, only check sorting of stackforge projects. + last = layout['projects'][0]['name'] + for project in layout['projects']: + current = project['name'] + if not current.startswith("stackforge/"): + continue + if normalize(last) > normalize(current): + print("Wrong alphabetical order: %(last)s, %(current)s" % + {"last": last, "current": current}) + errors = True + last = current + return errors + + +def check_all(): + errors = check_alphabetical() + # TODO(jaegerandi): Disabled until it passes + #errors = check_merge_template() or errors + + if errors: + print("Found errors in layout.yaml!") + else: + print("No errors found in layout.yaml!") + return errors + +if __name__ == "__main__": + sys.exit(check_all()) diff --git a/tox.ini b/tox.ini index d0e41983f5..5d9f2c3665 100644 --- a/tox.ini +++ b/tox.ini @@ -45,6 +45,7 @@ basepython = python2.7 deps = commands = {toxinidir}/tools/run-layout.sh + {toxinidir}/tools/layout-checks.py [testenv:bashate] commands = bashate -v