From 3fa3be7edef356fe42ed3c6adc21590604634665 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Tue, 6 May 2014 11:11:22 -0700 Subject: [PATCH] Add check job for upstream URLs on imported repos Add a check job to require upstream URLs to use a scheme that we are confident won't cause connection errors during the import. Add a tox configuration for this new job, as well as the existing alphabetical check script, to make it easier for developers to run those tests locally just by running "tox". Change-Id: I894ac0f8afb234404bb6e80e64b90aa25e052f10 --- .../jenkins_job_builder/config/infra.yaml | 21 ++++++++- .../openstack_project/files/zuul/layout.yaml | 2 + tools/check_upstream_url_scheme.py | 45 +++++++++++++++++++ tox.ini | 10 ++++- 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100755 tools/check_upstream_url_scheme.py diff --git a/modules/openstack_project/files/jenkins_job_builder/config/infra.yaml b/modules/openstack_project/files/jenkins_job_builder/config/infra.yaml index e4a5a5ebcf..adf02980f4 100644 --- a/modules/openstack_project/files/jenkins_job_builder/config/infra.yaml +++ b/modules/openstack_project/files/jenkins_job_builder/config/infra.yaml @@ -87,7 +87,26 @@ builders: - revoke-sudo - gerrit-git-prep - - shell: "tools/check_projects_yaml_alphabetized.sh" + - tox: + envlist: projects_alphabetized + github-org: openstack-infra + project: config + + publishers: + - console-log + + +- job: + name: check-projects-yaml-upstream + node: bare-precise + + builders: + - revoke-sudo + - gerrit-git-prep + - tox: + envlist: upstream + github-org: openstack-infra + project: config publishers: - console-log diff --git a/modules/openstack_project/files/zuul/layout.yaml b/modules/openstack_project/files/zuul/layout.yaml index 3840e43aa3..1a2b7be434 100644 --- a/modules/openstack_project/files/zuul/layout.yaml +++ b/modules/openstack_project/files/zuul/layout.yaml @@ -2660,6 +2660,7 @@ projects: - gate-config-irc-access - gate-ci-docs - check-projects-yaml-alphabetized + - check-projects-yaml-upstream gate: - gate-config-layout - gate-config-pep8 @@ -2667,6 +2668,7 @@ projects: - gate-config-puppet-syntax - gate-config-irc-access - check-projects-yaml-alphabetized + - check-projects-yaml-upstream post: - ci-docs diff --git a/tools/check_upstream_url_scheme.py b/tools/check_upstream_url_scheme.py new file mode 100755 index 0000000000..7ee54a6a15 --- /dev/null +++ b/tools/check_upstream_url_scheme.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python +""" +Allow git:// and https:// URLs for importing upstream repositories, +but not git@ +""" + +import argparse + +import yaml + + +parser = argparse.ArgumentParser() +parser.add_argument('-v', '--verbose', + dest='verbose', + default=False, + action='store_true', + ) +parser.add_argument( + 'infile', + help='path to review.projects.yaml', +) +args = parser.parse_args() + +projects = yaml.load(open(args.infile, 'r')) + +VALID_SCHEMES = ['https://', 'http://', 'git://'] + +for p in projects: + name = p.get('project') + if not name: + # not a project + continue + upstream = p.get('upstream') + if args.verbose: + print 'Checking %s: %r' % (name, upstream) + if not upstream: + continue + for prefix in VALID_SCHEMES: + if upstream.startswith(prefix): + break + else: + raise ValueError( + 'Upstream URLs should use a scheme in %s, found %s' % + (VALID_SCHEMES, p['project']) + ) diff --git a/tox.ini b/tox.ini index e67270ad56..da3a6128f6 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] minversion = 1.6 -envlist = pep8 +envlist = pep8,upstream,projects_alphabetized skipsdist = True [testenv] @@ -11,6 +11,14 @@ deps = -r{toxinidir}/test-requirements.txt [testenv:pep8] commands = flake8 +[testenv:upstream] +deps = PyYAML +commands = + {toxinidir}/tools/check_upstream_url_scheme.py -v modules/openstack_project/files/review.projects.yaml + +[testenv:projects_alphabetized] +commands = {toxinidir}/tools/check_projects_yaml_alphabetized.sh + [testenv:venv] commands = {posargs}