diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..46f27a2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +.DS_Store +*.swp +*~ +*.pyc +.tox/ +.test/ +/.project +/.pydevproject +*.egg +specs/output diff --git a/.gitreview b/.gitreview new file mode 100644 index 0000000..ef82c66 --- /dev/null +++ b/.gitreview @@ -0,0 +1,4 @@ +[gerrit] +host=review.openstack.org +port=29418 +project=openstack-infra/project-config-example.git diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..7214687 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,2 @@ +hacking>=0.10,<0.11 +bashate>=0.2 diff --git a/tools/jenkins-projects-checks.py b/tools/jenkins-projects-checks.py new file mode 100755 index 0000000..3c753c2 --- /dev/null +++ b/tools/jenkins-projects-checks.py @@ -0,0 +1,67 @@ +#! /usr/bin/env python + +# 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 sys + + +def normalize(s): + "Normalize string for comparison." + return s.lower().replace("_", "-") + + +def check_sections(): + """Check that the projects are in alphabetical order per section + and that indenting looks correct""" + + # Note that the file has different sections and we need to check + # entries within these sections only + errors = False + last = "" + count = 1 + for line in open('jenkins/jobs/projects.yaml', 'r'): + if line.startswith('# Section:'): + last = "" + section = line[10:].strip() + print("Checking section '%s'" % section) + if line.startswith(' name: '): + i = line.find(' name: ') + current = line[i + 7:].strip() + if normalize(last) > normalize(current): + print(" Wrong alphabetical order: %(last)s, %(current)s" % + {"last": last, "current": current}) + errors = True + last = current + if (len(line) - len(line.lstrip(' '))) % 2 != 0: + print("Line %(count)s not indented by multiple of 2:\n\t%(line)s" % + {"count": count, "line": line}) + errors = True + + count = count+1 + + return errors + + +def check_all(): + errors = check_sections() + + if errors: + print("Found errors in jenkins/jobs/projects.yaml!") + else: + print("No errors found in jenkins/jobs/projects.yaml!") + return errors + +if __name__ == "__main__": + sys.exit(check_all()) diff --git a/tools/layout-checks.py b/tools/layout-checks.py new file mode 100755 index 0000000..d8c51d3 --- /dev/null +++ b/tools/layout-checks.py @@ -0,0 +1,105 @@ +#!/usr/bin/env 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 + print("\nChecking for usage of merge template") + print("====================================") + 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_sections(): + """Check that the projects are in alphabetical order per section.""" + + print("Checking sections for alphabetical order") + print("========================================") + # Note that the file has different sections and we need to sort + # entries within these sections. + errors = False + # Skip all entries before the first section header + firstEntry = True + last = "" + for line in open('zuul/layout.yaml', 'r'): + if line.startswith('# Section:'): + last = "" + section = line[10:].strip() + print("Checking section '%s'" % section) + firstEntry = False + if line.startswith(' - name: ') and not firstEntry: + current = line[10:].strip() + if (normalize(last) > normalize(current) and + last != 'z/tempest'): + print(" Wrong alphabetical order: %(last)s, %(current)s" % + {"last": last, "current": current}) + errors = True + last = current + return errors + +def check_formatting(): + errors = False + count = 1 + + print("Checking indents") + print("================") + + for line in open('zuul/layout.yaml', 'r'): + if (len(line) - len(line.lstrip(' '))) % 2 != 0: + print("Line %(count)s not indented by multiple of 2:\n\t%(line)s" % + {"count": count, "line": line}) + errors = True + count = count + 1 + + return errors + +def check_all(): + errors = check_sections() + errors = check_formatting() or errors + + if errors: + print("\nFound errors in layout.yaml!") + else: + print("\nNo errors found in layout.yaml!") + return errors + +if __name__ == "__main__": + sys.exit(check_all()) diff --git a/tools/run-bashate.sh b/tools/run-bashate.sh new file mode 100755 index 0000000..9de12b8 --- /dev/null +++ b/tools/run-bashate.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +ROOT=$(readlink -fn $(dirname $0)/.. ) +find $ROOT -not -wholename \*.tox/\* -and -not -wholename \*.test/\* -and \( -name \*.sh -or -name \*rc -or -name functions\* \) -print0 | xargs -0 bashate -v diff --git a/tools/run-compare-xml.sh b/tools/run-compare-xml.sh new file mode 100755 index 0000000..49e210f --- /dev/null +++ b/tools/run-compare-xml.sh @@ -0,0 +1,54 @@ +#!/bin/bash -e + +# Copyright (c) 2012, AT&T Labs, Yun Mao +# All Rights Reserved. +# Copyright 2012 Hewlett-Packard Development Company, L.P. +# +# 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. + +rm -fr .test +mkdir .test +cd .test +/usr/zuul-env/bin/zuul-cloner -m ../tools/run-compare-clonemap.yaml --cache-dir /opt/git git://git.openstack.org openstack-infra/jenkins-job-builder +cd jenkins-job-builder +# These are $WORKSPACE/.test/jenkins-job-builder/.test/... +mkdir -p .test/old/config +mkdir -p .test/old/out +mkdir -p .test/new/config +mkdir -p .test/new/out +cd ../.. + +GITHEAD=$(git rev-parse HEAD) + +# First generate output from HEAD~1 +git checkout HEAD~1 +cp jenkins/jobs/* .test/jenkins-job-builder/.test/old/config + +# Then use that as a reference to compare against HEAD +git checkout $GITHEAD +cp jenkins/jobs/* .test/jenkins-job-builder/.test/new/config + +cd .test/jenkins-job-builder + +tox -e compare-xml-old +tox -e compare-xml-new + +diff -r -N -u .test/old/out .test/new/out +CHANGED=$? # 0 == same ; 1 == different ; 2 == error + +echo +echo "You are in detached HEAD mode. If you are a developer" +echo "and not very familiar with git, you might want to do" +echo "'git checkout branch-name' to go back to your branch." + +exit $CHANGED diff --git a/tools/run-layout.sh b/tools/run-layout.sh new file mode 100755 index 0000000..c9ffcb2 --- /dev/null +++ b/tools/run-layout.sh @@ -0,0 +1,35 @@ +#!/bin/bash -e + +# Copyright 2013 OpenStack Foundation +# +# 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. + +mkdir -p .test +cd .test +[ -d zuul ] || git clone https://git.openstack.org/openstack-infra/zuul --depth 1 +[ -d jenkins-job-builder ] || git clone https://git.openstack.org/openstack-infra/jenkins-job-builder --depth 1 +cd jenkins-job-builder +# These are $WORKSPACE/.test/jenkins-job-builder/.test/... +mkdir -p .test/new/config +mkdir -p .test/new/out +cd ../.. + +cp jenkins/jobs/* .test/jenkins-job-builder/.test/new/config +cd .test/jenkins-job-builder +tox -e compare-xml-new + +cd .. +find jenkins-job-builder/.test/new/out/ -printf "%f\n" > job-list.txt + +cd zuul +tox -e venv -- zuul-server -c etc/zuul.conf-sample -l ../../zuul/layout.yaml -t ../job-list.txt diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..613e0a4 --- /dev/null +++ b/tox.ini @@ -0,0 +1,44 @@ +[tox] +minversion = 1.6 +envlist = pep8,jjb,jenkins-project,zuul +skipsdist = True + +[testenv] +deps = -r{toxinidir}/test-requirements.txt + +[testenv:pep8] +commands = + flake8 + {toxinidir}/tools/run-bashate.sh + +[testenv:venv] +commands = {posargs} + +[flake8] +show-source = True +exclude = .tox,.test +ignore = E125,H +select = H231 + +[testenv:jjb] +basepython = python2.7 +deps = jenkins-job-builder +whitelist_externals = + mkdir + rm +commands = + rm -rf {envdir}/tmp + mkdir -p {envdir}/tmp + jenkins-jobs -l debug test -o {envdir}/tmp jenkins/jobs + +[testenv:jenkins-project] +deps = +commands = + {toxinidir}/tools/jenkins-projects-checks.py + +[testenv:zuul] +basepython = python2.7 +deps = PyYAML +commands = + {toxinidir}/tools/run-layout.sh + {toxinidir}/tools/layout-checks.py