1 # Copyright (C) 2016 Nippon Telegraph and Telephone Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
22 from six.moves import urllib
24 from nose.tools import ok_
27 LOG = logging.getLogger(__name__)
29 MOD_DIR = os.path.dirname('file://' + sys.modules[__name__].__file__)
30 _RYU_REQUIREMENTS_FILES = [
31 '../../../tools/pip-requires',
32 '../../../tools/optional-requires',
34 RYU_REQUIREMENTS_FILES = [
35 os.path.join(MOD_DIR, f) for f in _RYU_REQUIREMENTS_FILES]
37 OPENSTACK_REQUIREMENTS_REPO = 'https://github.com/openstack/requirements'
38 OPENSTACK_REQUIREMENTS_URL = (
39 'https://github.com/openstack/requirements/raw/master/')
40 _OPENSTACK_REQUIREMENTS_FILES = [
42 'global-requirements.txt',
44 OPENSTACK_REQUIREMENTS_FILES = [
45 urllib.parse.urljoin(OPENSTACK_REQUIREMENTS_URL, f)
46 for f in _OPENSTACK_REQUIREMENTS_FILES]
49 def _get_requirements(files):
52 response = urllib.request.urlopen(f)
53 contents = response.read().decode('utf-8')
54 for r in pkg_resources.parse_requirements(contents):
55 requirements[r.name] = str(r)
60 OPENSTACK_REQUIREMENTS = _get_requirements(OPENSTACK_REQUIREMENTS_FILES)
61 RYU_REQUIREMENTS = _get_requirements(RYU_REQUIREMENTS_FILES)
64 class TestRequirements(unittest.TestCase):
66 Test whether the requirements of Ryu has no conflict with that
76 def test_with_openstack_requirements(self):
78 for name, req in OPENSTACK_REQUIREMENTS.items():
79 if name in RYU_REQUIREMENTS:
80 ok_(pkg_resources.require(req))
81 except pkg_resources.VersionConflict as e:
83 'Some requirements of Ryu are conflicting with that of '
84 'OpenStack project: %s', OPENSTACK_REQUIREMENTS_REPO)