1 # Licensed under the Apache License, Version 2.0 (the "License");
2 # you may not use this file except in compliance with the License.
3 # You may obtain a copy of the License at
5 # http://www.apache.org/licenses/LICENSE-2.0
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS,
9 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
22 from pbr.tests import base
24 PIPFLAGS = shlex.split(os.environ.get('PIPFLAGS', ''))
25 PIPVERSION = os.environ.get('PIPVERSION', 'pip')
26 PBRVERSION = os.environ.get('PBRVERSION', 'pbr')
27 REPODIR = os.environ.get('REPODIR', '')
28 WHEELHOUSE = os.environ.get('WHEELHOUSE', '')
29 PIP_CMD = ['-m', 'pip'] + PIPFLAGS + ['install', '-f', WHEELHOUSE]
30 PROJECTS = shlex.split(os.environ.get('PROJECTS', ''))
36 # Future: make this path parameterisable.
37 excludes = set(['pypi-mirror', 'jeepyb', 'tempest', 'requirements'])
40 short_name = name.split('/')[-1]
42 with open(os.path.join(
43 REPODIR, short_name, 'setup.py'), 'rt') as f:
44 if 'pbr' not in f.read():
48 if short_name in excludes:
50 yield (short_name, dict(name=name, short_name=short_name))
53 class TestIntegration(base.BaseTestCase):
55 scenarios = list(all_projects())
58 # Integration tests need a higher default - big repos can be slow to
59 # clone, particularly under guest load.
60 os.environ['OS_TEST_TIMEOUT'] = os.environ.get('OS_TEST_TIMEOUT',
62 super(TestIntegration, self).setUp()
65 def venv(self, reason):
66 path = self.useFixture(fixtures.TempDir()).path
67 virtualenv.create_environment(path, clear=True)
68 python = os.path.join(path, 'bin', 'python')
69 self.useFixture(base.CapturedSubprocess(
70 'mkvenv-' + reason, [python] + PIP_CMD + [
71 '-U', PIPVERSION, 'wheel', PBRVERSION]))
74 @testtools.skipUnless(
75 os.environ.get('PBR_INTEGRATION', None) == '1',
76 'integration tests not enabled')
77 def test_integration(self):
79 # - run sdist from the repo in a venv
80 # - install the resulting tarball in a new venv
81 # - pip install the repo
82 # - pip install -e the repo
83 # We don't break these into separate tests because we'd need separate
84 # source dirs to isolate from side effects of running pip, and the
85 # overheads of setup would start to beat the benefits of parallelism.
86 self.useFixture(base.CapturedSubprocess(
88 ['python', 'update.py', os.path.join(REPODIR, self.short_name)],
89 cwd=os.path.join(REPODIR, 'requirements')))
90 self.useFixture(base.CapturedSubprocess(
91 'commit-requirements',
92 'git diff --quiet || git commit -amrequirements',
93 cwd=os.path.join(REPODIR, self.short_name), shell=True))
95 self.useFixture(fixtures.TempDir()).path, 'project')
96 self.useFixture(base.CapturedSubprocess(
98 ['git', 'clone', os.path.join(REPODIR, self.short_name), path]))
99 _, python = self.venv('sdist')
100 self.useFixture(base.CapturedSubprocess(
101 'sdist', [python, 'setup.py', 'sdist'], cwd=path))
102 _, python = self.venv('tarball')
103 filename = os.path.join(
104 path, 'dist', os.listdir(os.path.join(path, 'dist'))[0])
105 self.useFixture(base.CapturedSubprocess(
106 'tarball', [python] + PIP_CMD + [filename]))
107 root, python = self.venv('install-git')
108 self.useFixture(base.CapturedSubprocess(
109 'install-git', [python] + PIP_CMD + ['git+file://' + path]))
110 if self.short_name == 'nova':
112 for _, _, filenames in os.walk(root):
113 if 'migrate.cfg' in filenames:
115 self.assertTrue(found)
116 _, python = self.venv('install-e')
117 self.useFixture(base.CapturedSubprocess(
118 'install-e', [python] + PIP_CMD + ['-e', path]))
121 def load_tests(loader, in_tests, pattern):
122 return testscenarios.load_tests_apply_scenarios(loader, in_tests, pattern)