summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoss Brattain <ross.b.brattain@intel.com>2017-11-17 09:55:41 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-11-17 09:55:41 +0000
commitb22b09d3e58bc01105165434a1220f581d6ab31b (patch)
tree9e82a87e03db7d6cdb8c76c8ef4254a67fbac0a9
parent680cd988b2dfc5a0074cb829e5bae69f0bc7a6af (diff)
parentb80b0fc323d4ec2bca2a9c10acac51176d36ce6f (diff)
Merge "Check requirements against OpenStack requirements"
-rw-r--r--test-requirements.txt9
-rw-r--r--tools/os-requirements-check.py111
-rw-r--r--tox.ini8
3 files changed, 127 insertions, 1 deletions
diff --git a/test-requirements.txt b/test-requirements.txt
new file mode 100644
index 000000000..538777039
--- /dev/null
+++ b/test-requirements.txt
@@ -0,0 +1,9 @@
+# The order of packages is significant, because pip processes them in the order
+# of appearance. Changing the order has an impact on the overall integration
+# process, which may cause wedges in the gate later.
+
+packaging==16.8.0 # BSD or Apache License, Version 2.0
+
+# Yardstick F release <-> OpenStack Pike release
+openstack_requirements==1.1.0 # OSI Approved Apache Software License
+-e git+https://github.com/openstack/requirements.git@stable/pike#egg=os_requirements
diff --git a/tools/os-requirements-check.py b/tools/os-requirements-check.py
new file mode 100644
index 000000000..c19fbce55
--- /dev/null
+++ b/tools/os-requirements-check.py
@@ -0,0 +1,111 @@
+# Copyright (c) 2017 Intel Corporation
+#
+# 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 argparse
+import collections
+import os
+from packaging import version as pkg_version
+import sys
+
+from openstack_requirements import requirement
+
+
+PROJECT_REQUIREMENTS_FILES = ['requirements.txt']
+QUALIFIER_CHARS = ['<', '>', '!', '=']
+
+
+def _grab_args():
+ """Grab and return arguments"""
+ parser = argparse.ArgumentParser(
+ description='Check if project requirements have changed')
+
+ parser.add_argument('env_dir', help='tox environment directory')
+ return parser.parse_args()
+
+
+def _extract_reqs(file_name, blacklist=None):
+ blacklist = blacklist or {}
+ content = open(file_name, 'rt').read()
+ reqs = collections.defaultdict(tuple)
+ parsed = requirement.parse(content)
+ for name, entries in ((name, entries) for (name, entries) in parsed.items()
+ if (name and name not in blacklist)):
+ list_reqs = [r for (r, line) in entries]
+ # Strip the comments out before checking if there are duplicates
+ list_reqs_stripped = [r._replace(comment='') for r in list_reqs]
+ if len(list_reqs_stripped) != len(set(list_reqs_stripped)):
+ print('Requirements file %s has duplicate entries for package '
+ '"%s: %r' % (file_name, name, list_reqs))
+ reqs[name] = list_reqs
+ return reqs
+
+
+def _extract_qualifier_version(specifier):
+ index = 1
+ # Find qualifier (one or two chars).
+ if specifier[0] in QUALIFIER_CHARS and specifier[1] in QUALIFIER_CHARS:
+ index = 2
+ qualifier = specifier[:index]
+ version = pkg_version.Version(specifier[index:])
+ return qualifier, version
+
+
+def main():
+ args = _grab_args()
+
+ # Build a list of requirements from the global list in the
+ # openstack/requirements project so we can match them to the changes
+ env_dir = args.env_dir
+ req_dir = env_dir + '/src/os-requirements/'
+ global_reqs = _extract_reqs(req_dir + '/global-requirements.txt')
+ blacklist = _extract_reqs(req_dir + '/blacklist.txt')
+
+ # Build a list of project requirements.
+ failed = False
+ local_dir = os.getcwd()
+ for file_name in PROJECT_REQUIREMENTS_FILES:
+ print('Validating requirements file "%s"' % file_name)
+ proj_reqs = _extract_reqs(local_dir + '/' + file_name,
+ blacklist=blacklist)
+
+ for name, req in proj_reqs.items():
+ global_req = global_reqs.get(name)
+ if not global_req:
+ continue
+ global_req = global_req[0]
+ req = req[0]
+ if not global_req.specifiers:
+ continue
+
+ specifiers = global_req.specifiers.split(',')
+ for spec in specifiers:
+ _, req_version = _extract_qualifier_version(req.specifiers)
+ g_qualifier, g_version = _extract_qualifier_version(spec)
+ if g_qualifier == '!=' and g_version == req_version:
+ print('Package "%s" version %s is not compatible' %
+ (name, req_version))
+ failed = True
+ if g_qualifier == '>=' and g_version > req_version:
+ print('Package "%s" version %s outdated, minimum version '
+ '%s' % (name, req_version, g_version))
+ failed = True
+
+ if failed:
+ print('Incompatible requirement found!')
+ sys.exit(1)
+ print('Updated requirements match openstack/requirements')
+
+
+if __name__ == '__main__':
+ main()
diff --git a/tox.ini b/tox.ini
index 54ca1fefb..6c568f3fe 100644
--- a/tox.ini
+++ b/tox.ini
@@ -6,7 +6,9 @@ envlist = py27,py3
[testenv]
usedevelop=True
passenv = http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY
-deps = -rrequirements.txt
+deps =
+ -r{toxinidir}/requirements.txt
+ -r{toxinidir}/test-requirements.txt
commands = /bin/bash ./run_tests.sh
whitelist_externals = /bin/bash
@@ -28,3 +30,7 @@ setenv =
ignore = E123,E125,H803
max-line-length = 99
exclude = .venv,.git,.tox,dist,docs,*egg,build
+
+[testenv:os-requirements]
+commands =
+ python {toxinidir}/tools/os-requirements-check.py {envdir}