Use venv instead of virtualenv in generate script

The gate nodes no longer have the virtualenv package globally installed
and available, resulting in our nightly job failing with the error:

FileNotFoundError: [Errno 2] No such file or directory: 'virtualenv'

To get around this, this patch updates our generate.py code to use the
venv module that is part of the standard lib in Python 3.3 and later.

Change-Id: I128ce15a1b6ce885dacae4ecd160f5892215683b
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
This commit is contained in:
Sean McGinnis 2020-06-26 10:39:48 -05:00
parent c905979a82
commit 8c58c188a0
No known key found for this signature in database
GPG Key ID: CE7EE4BFAF8D70C8
3 changed files with 28 additions and 10 deletions

View File

@ -42,6 +42,8 @@ python3-all [platform:dpkg]
python-all-dev [platform:dpkg]
python-devel [platform:rpm !platform:centos-8]
python3-devel [platform:rpm]
# Ubuntu packages venv separately, otherwise standard
python3-venv [platform:dpkg]
swig
systemd-devel [platform:redhat]
uuid-dev [platform:dpkg]

View File

@ -74,7 +74,7 @@ def _freeze(requirements, python):
version = '.'.join(version_all.split('.')[:2])
with fixtures.TempDir() as temp:
output.append(subprocess.check_output(
['virtualenv', '-p', python, temp.path]))
[python, '-m', 'venv', temp.path]))
pip_bin = os.path.join(temp.path, 'bin', 'pip')
output.append(subprocess.check_output(
[pip_bin, 'install', '-U', 'pip', 'setuptools', 'wheel']))

View File

@ -11,6 +11,7 @@
# under the License.
import os.path
import subprocess
import fixtures
import testtools
@ -22,21 +23,36 @@ from openstack_requirements.cmds import generate
class TestFreeze(testtools.TestCase):
def test_freeze_smoke(self):
# Use an aribtrary python. The installation of virtualenv system wide
# is presumed.
versions = ['/usr/bin/python%(v)s' % dict(v=v) for v in
["2.7", "3.4"]]
found = [v for v in versions if os.path.exists(v)][0]
# Use an arbitrary python, but make sure it has the venv standard lib.
versions = ['/usr/bin/python3.%(v)s' % dict(v=v) for v in range(5, 10)]
found = [v for v in versions if os.path.exists(v)]
found_with_venv = []
for py in found:
output = str(subprocess.check_output(
[py,
'-c',
'import pkgutil; [print(x) for x in pkgutil.iter_modules()]']
))
# Needs both venv and ensurepip
if 'venv' in output and 'ensurepip' in output:
found_with_venv.append(py)
if len(found_with_venv) == 0:
self.skipTest('Unable to find python that includes venv module')
# Grab the latest version available as that is the most likely to
# break.
pyversion = found_with_venv[-1]
req = self.useFixture(fixtures.TempDir()).path + '/r.txt'
with open(req, 'wt') as output:
output.write('fixtures==1.2.0')
frozen = generate._freeze(req, found)
expected_version = found[-3:]
output.write('fixtures==2.0.0')
frozen = generate._freeze(req, pyversion)
expected_version = pyversion[-3:]
self.expectThat(frozen, matchers.HasLength(2))
self.expectThat(frozen[0], matchers.Equals(expected_version))
# There are multiple items in the dependency tree of fixtures.
# Since this is a smoke test, just ensure fixtures is there.
self.expectThat(frozen[1], matchers.Contains(('fixtures', '1.2.0')))
self.expectThat(frozen[1], matchers.Contains(('fixtures', '2.0.0')))
class TestParse(testtools.TestCase):