2012-09-27 11:06:09 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-12-11 10:23:37 +00:00
|
|
|
'''
|
2018-05-28 21:13:12 +00:00
|
|
|
:codeauthor: Pedro Algarvio (pedro@algarvio.me)
|
2013-09-16 16:24:00 +00:00
|
|
|
|
|
|
|
tests.integration.modules.pip
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2012-12-11 10:23:37 +00:00
|
|
|
'''
|
2012-09-27 11:06:09 +00:00
|
|
|
|
2012-12-11 10:23:37 +00:00
|
|
|
# Import python libs
|
2018-01-19 05:49:04 +00:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
2012-09-27 11:06:09 +00:00
|
|
|
import os
|
2015-12-27 03:30:27 +00:00
|
|
|
import re
|
2018-04-27 21:15:34 +00:00
|
|
|
import shutil
|
2012-09-27 11:06:09 +00:00
|
|
|
import tempfile
|
|
|
|
|
2013-06-27 11:36:37 +00:00
|
|
|
# Import Salt Testing libs
|
2017-04-03 16:04:09 +00:00
|
|
|
from tests.support.case import ModuleCase
|
2017-02-27 13:58:07 +00:00
|
|
|
from tests.support.unit import skipIf
|
2017-04-03 16:04:09 +00:00
|
|
|
from tests.support.paths import TMP
|
2017-04-04 17:57:27 +00:00
|
|
|
from tests.support.helpers import skip_if_not_root
|
2013-06-27 11:36:37 +00:00
|
|
|
|
2012-09-27 11:06:09 +00:00
|
|
|
# Import salt libs
|
2017-07-18 16:31:01 +00:00
|
|
|
import salt.utils.files
|
Use explicit unicode strings + break up salt.utils
This PR is part of what will be an ongoing effort to use explicit
unicode strings in Salt. Because Python 3 does not suport Python 2's raw
unicode string syntax (i.e. `ur'\d+'`), we must use
`salt.utils.locales.sdecode()` to ensure that the raw string is unicode.
However, because of how `salt/utils/__init__.py` has evolved into the
hulking monstrosity it is today, this means importing a large module in
places where it is not needed, which could negatively impact
performance. For this reason, this PR also breaks out some of the
functions from `salt/utils/__init__.py` into new/existing modules under
`salt/utils/`. The long term goal will be that the modules within this
directory do not depend on importing `salt.utils`.
A summary of the changes in this PR is as follows:
* Moves the following functions from `salt.utils` to new locations
(including a deprecation warning if invoked from `salt.utils`):
`to_bytes`, `to_str`, `to_unicode`, `str_to_num`, `is_quoted`,
`dequote`, `is_hex`, `is_bin_str`, `rand_string`,
`contains_whitespace`, `clean_kwargs`, `invalid_kwargs`, `which`,
`which_bin`, `path_join`, `shlex_split`, `rand_str`, `is_windows`,
`is_proxy`, `is_linux`, `is_darwin`, `is_sunos`, `is_smartos`,
`is_smartos_globalzone`, `is_smartos_zone`, `is_freebsd`, `is_netbsd`,
`is_openbsd`, `is_aix`
* Moves the functions already deprecated by @rallytime to the bottom of
`salt/utils/__init__.py` for better organization, so we can keep the
deprecated ones separate from the ones yet to be deprecated as we
continue to break up `salt.utils`
* Updates `salt/*.py` and all files under `salt/client/` to use explicit
unicode string literals.
* Gets rid of implicit imports of `salt.utils` (e.g. `from salt.utils
import foo` becomes `import salt.utils.foo as foo`).
* Renames the `test.rand_str` function to `test.random_hash` to more
accurately reflect what it does
* Modifies `salt.utils.stringutils.random()` (née `salt.utils.rand_string()`)
such that it returns a string matching the passed size. Previously
this function would get `size` bytes from `os.urandom()`,
base64-encode it, and return the result, which would in most cases not
be equal to the passed size.
2017-07-25 01:47:15 +00:00
|
|
|
import salt.utils.path
|
2018-05-07 17:36:47 +00:00
|
|
|
import salt.utils.platform
|
2014-01-11 19:19:29 +00:00
|
|
|
from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
|
2012-09-27 11:06:09 +00:00
|
|
|
|
|
|
|
|
Use explicit unicode strings + break up salt.utils
This PR is part of what will be an ongoing effort to use explicit
unicode strings in Salt. Because Python 3 does not suport Python 2's raw
unicode string syntax (i.e. `ur'\d+'`), we must use
`salt.utils.locales.sdecode()` to ensure that the raw string is unicode.
However, because of how `salt/utils/__init__.py` has evolved into the
hulking monstrosity it is today, this means importing a large module in
places where it is not needed, which could negatively impact
performance. For this reason, this PR also breaks out some of the
functions from `salt/utils/__init__.py` into new/existing modules under
`salt/utils/`. The long term goal will be that the modules within this
directory do not depend on importing `salt.utils`.
A summary of the changes in this PR is as follows:
* Moves the following functions from `salt.utils` to new locations
(including a deprecation warning if invoked from `salt.utils`):
`to_bytes`, `to_str`, `to_unicode`, `str_to_num`, `is_quoted`,
`dequote`, `is_hex`, `is_bin_str`, `rand_string`,
`contains_whitespace`, `clean_kwargs`, `invalid_kwargs`, `which`,
`which_bin`, `path_join`, `shlex_split`, `rand_str`, `is_windows`,
`is_proxy`, `is_linux`, `is_darwin`, `is_sunos`, `is_smartos`,
`is_smartos_globalzone`, `is_smartos_zone`, `is_freebsd`, `is_netbsd`,
`is_openbsd`, `is_aix`
* Moves the functions already deprecated by @rallytime to the bottom of
`salt/utils/__init__.py` for better organization, so we can keep the
deprecated ones separate from the ones yet to be deprecated as we
continue to break up `salt.utils`
* Updates `salt/*.py` and all files under `salt/client/` to use explicit
unicode string literals.
* Gets rid of implicit imports of `salt.utils` (e.g. `from salt.utils
import foo` becomes `import salt.utils.foo as foo`).
* Renames the `test.rand_str` function to `test.random_hash` to more
accurately reflect what it does
* Modifies `salt.utils.stringutils.random()` (née `salt.utils.rand_string()`)
such that it returns a string matching the passed size. Previously
this function would get `size` bytes from `os.urandom()`,
base64-encode it, and return the result, which would in most cases not
be equal to the passed size.
2017-07-25 01:47:15 +00:00
|
|
|
@skipIf(salt.utils.path.which_bin(KNOWN_BINARY_NAMES) is None, 'virtualenv not installed')
|
2017-04-03 16:04:09 +00:00
|
|
|
class PipModuleTest(ModuleCase):
|
2012-09-27 11:06:09 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(PipModuleTest, self).setUp()
|
|
|
|
|
2017-04-03 16:04:09 +00:00
|
|
|
self.venv_test_dir = tempfile.mkdtemp(dir=TMP)
|
2012-09-27 11:06:09 +00:00
|
|
|
self.venv_dir = os.path.join(self.venv_test_dir, 'venv')
|
2013-07-04 17:57:42 +00:00
|
|
|
for key in os.environ.copy():
|
|
|
|
if key.startswith('PIP_'):
|
|
|
|
os.environ.pop(key)
|
|
|
|
self.pip_temp = os.path.join(self.venv_test_dir, '.pip-temp')
|
|
|
|
if not os.path.isdir(self.pip_temp):
|
|
|
|
os.makedirs(self.pip_temp)
|
|
|
|
os.environ['PIP_SOURCE_DIR'] = os.environ['PIP_BUILD_DIR'] = ''
|
2012-09-27 11:06:09 +00:00
|
|
|
|
2018-08-01 21:28:57 +00:00
|
|
|
def tearDown(self):
|
|
|
|
if 'PIP_SOURCE_DIR' in os.environ:
|
|
|
|
os.environ.pop('PIP_SOURCE_DIR')
|
|
|
|
|
2016-09-29 06:14:37 +00:00
|
|
|
def _check_download_error(self, ret):
|
2016-09-29 06:11:38 +00:00
|
|
|
'''
|
|
|
|
Checks to see if a download error looks transitory
|
|
|
|
'''
|
2016-10-04 12:09:47 +00:00
|
|
|
return any(w in ret for w in ['URLError', 'Download error'])
|
2016-09-29 06:11:38 +00:00
|
|
|
|
2018-04-10 19:09:20 +00:00
|
|
|
def pip_successful_install(self, target, expect=('irc3-plugins-test', 'pep8',)):
|
2015-12-28 18:48:16 +00:00
|
|
|
'''
|
|
|
|
isolate regex for extracting `successful install` message from pip
|
|
|
|
'''
|
2015-12-28 17:19:05 +00:00
|
|
|
|
2015-12-28 18:02:24 +00:00
|
|
|
expect = set(expect)
|
2015-12-28 18:48:16 +00:00
|
|
|
expect_str = '|'.join(expect)
|
2015-12-28 17:19:05 +00:00
|
|
|
|
2015-12-28 18:02:24 +00:00
|
|
|
success = re.search(
|
|
|
|
r'^.*Successfully installed\s([^\n]+)(?:Clean.*)?',
|
|
|
|
target,
|
|
|
|
re.M | re.S)
|
2015-12-28 17:19:05 +00:00
|
|
|
|
2015-12-28 18:02:24 +00:00
|
|
|
success_for = re.findall(
|
2015-12-28 18:48:16 +00:00
|
|
|
r'({0})(?:-(?:[\d\.-]))?'.format(expect_str),
|
2015-12-28 18:02:24 +00:00
|
|
|
success.groups()[0]
|
|
|
|
) if success else []
|
2015-12-28 17:19:05 +00:00
|
|
|
|
2015-12-28 18:02:24 +00:00
|
|
|
return expect.issubset(set(success_for))
|
2015-12-28 17:19:05 +00:00
|
|
|
|
2012-09-27 11:06:09 +00:00
|
|
|
def test_issue_2087_missing_pip(self):
|
|
|
|
# Let's create the testing virtualenv
|
|
|
|
self.run_function('virtualenv.create', [self.venv_dir])
|
|
|
|
|
|
|
|
# Let's remove the pip binary
|
|
|
|
pip_bin = os.path.join(self.venv_dir, 'bin', 'pip')
|
2018-05-14 19:45:37 +00:00
|
|
|
site_dir = self.run_function('virtualenv.get_distribution_path', [self.venv_dir, 'pip'])
|
2018-05-07 17:36:47 +00:00
|
|
|
if salt.utils.platform.is_windows():
|
2018-04-27 21:15:34 +00:00
|
|
|
pip_bin = os.path.join(self.venv_dir, 'Scripts', 'pip.exe')
|
|
|
|
site_dir = os.path.join(self.venv_dir, 'lib', 'site-packages')
|
2012-09-27 11:06:09 +00:00
|
|
|
if not os.path.isfile(pip_bin):
|
|
|
|
self.skipTest(
|
|
|
|
'Failed to find the pip binary to the test virtualenv'
|
|
|
|
)
|
|
|
|
os.remove(pip_bin)
|
|
|
|
|
2018-04-27 21:15:34 +00:00
|
|
|
# Also remove the pip dir from site-packages
|
|
|
|
# This is needed now that we're using python -m pip instead of the
|
|
|
|
# pip binary directly. python -m pip will still work even if the
|
|
|
|
# pip binary is missing
|
|
|
|
shutil.rmtree(os.path.join(site_dir, 'pip'))
|
|
|
|
|
2012-09-27 11:06:09 +00:00
|
|
|
# Let's run a pip depending functions
|
|
|
|
for func in ('pip.freeze', 'pip.list'):
|
|
|
|
ret = self.run_function(func, bin_env=self.venv_dir)
|
2015-05-15 06:00:22 +00:00
|
|
|
self.assertIn(
|
|
|
|
'Command required for \'{0}\' not found: '
|
2018-04-27 21:15:34 +00:00
|
|
|
'Could not find a `pip` binary'.format(func),
|
2015-05-15 06:00:22 +00:00
|
|
|
ret
|
2012-09-27 11:06:09 +00:00
|
|
|
)
|
|
|
|
|
2017-04-04 17:57:27 +00:00
|
|
|
@skip_if_not_root
|
2018-04-27 21:15:34 +00:00
|
|
|
def test_requirements_as_list_of_chains__cwd_set__absolute_file_path(self):
|
2015-12-28 09:30:19 +00:00
|
|
|
self.run_function('virtualenv.create', [self.venv_dir])
|
|
|
|
|
|
|
|
# Create a requirements file that depends on another one.
|
|
|
|
|
|
|
|
req1_filename = os.path.join(self.venv_dir, 'requirements1.txt')
|
|
|
|
req1b_filename = os.path.join(self.venv_dir, 'requirements1b.txt')
|
|
|
|
req2_filename = os.path.join(self.venv_dir, 'requirements2.txt')
|
|
|
|
req2b_filename = os.path.join(self.venv_dir, 'requirements2b.txt')
|
|
|
|
|
2017-07-18 16:31:01 +00:00
|
|
|
with salt.utils.files.fopen(req1_filename, 'w') as f:
|
2015-12-28 09:30:19 +00:00
|
|
|
f.write('-r requirements1b.txt\n')
|
2017-07-18 16:31:01 +00:00
|
|
|
with salt.utils.files.fopen(req1b_filename, 'w') as f:
|
2018-04-10 19:09:20 +00:00
|
|
|
f.write('irc3-plugins-test\n')
|
2017-07-18 16:31:01 +00:00
|
|
|
with salt.utils.files.fopen(req2_filename, 'w') as f:
|
2015-12-28 09:30:19 +00:00
|
|
|
f.write('-r requirements2b.txt\n')
|
2017-07-18 16:31:01 +00:00
|
|
|
with salt.utils.files.fopen(req2b_filename, 'w') as f:
|
2015-12-28 09:30:19 +00:00
|
|
|
f.write('pep8\n')
|
|
|
|
|
|
|
|
requirements_list = [req1_filename, req2_filename]
|
|
|
|
|
|
|
|
ret = self.run_function(
|
2018-04-27 21:15:34 +00:00
|
|
|
'pip.install', requirements=requirements_list,
|
2015-12-28 09:30:19 +00:00
|
|
|
bin_env=self.venv_dir, cwd=self.venv_dir
|
|
|
|
)
|
|
|
|
try:
|
|
|
|
self.assertEqual(ret['retcode'], 0)
|
|
|
|
|
2015-12-28 17:19:05 +00:00
|
|
|
found = self.pip_successful_install(ret['stdout'])
|
2015-12-28 09:30:19 +00:00
|
|
|
|
|
|
|
self.assertTrue(found)
|
|
|
|
except (AssertionError, TypeError):
|
|
|
|
import pprint
|
|
|
|
pprint.pprint(ret)
|
|
|
|
raise
|
|
|
|
|
2017-04-04 17:57:27 +00:00
|
|
|
@skip_if_not_root
|
2018-04-27 21:15:34 +00:00
|
|
|
def test_requirements_as_list_of_chains__cwd_not_set__absolute_file_path(self):
|
2015-12-28 09:30:19 +00:00
|
|
|
self.run_function('virtualenv.create', [self.venv_dir])
|
|
|
|
|
|
|
|
# Create a requirements file that depends on another one.
|
|
|
|
|
|
|
|
req1_filename = os.path.join(self.venv_dir, 'requirements1.txt')
|
|
|
|
req1b_filename = os.path.join(self.venv_dir, 'requirements1b.txt')
|
|
|
|
req2_filename = os.path.join(self.venv_dir, 'requirements2.txt')
|
|
|
|
req2b_filename = os.path.join(self.venv_dir, 'requirements2b.txt')
|
|
|
|
|
2017-07-18 16:31:01 +00:00
|
|
|
with salt.utils.files.fopen(req1_filename, 'w') as f:
|
2015-12-28 09:30:19 +00:00
|
|
|
f.write('-r requirements1b.txt\n')
|
2017-07-18 16:31:01 +00:00
|
|
|
with salt.utils.files.fopen(req1b_filename, 'w') as f:
|
2018-04-10 19:09:20 +00:00
|
|
|
f.write('irc3-plugins-test\n')
|
2017-07-18 16:31:01 +00:00
|
|
|
with salt.utils.files.fopen(req2_filename, 'w') as f:
|
2015-12-28 09:30:19 +00:00
|
|
|
f.write('-r requirements2b.txt\n')
|
2017-07-18 16:31:01 +00:00
|
|
|
with salt.utils.files.fopen(req2b_filename, 'w') as f:
|
2015-12-28 09:30:19 +00:00
|
|
|
f.write('pep8\n')
|
|
|
|
|
|
|
|
requirements_list = [req1_filename, req2_filename]
|
|
|
|
|
|
|
|
ret = self.run_function(
|
2018-04-27 21:15:34 +00:00
|
|
|
'pip.install', requirements=requirements_list, bin_env=self.venv_dir
|
2015-12-28 09:30:19 +00:00
|
|
|
)
|
|
|
|
try:
|
|
|
|
self.assertEqual(ret['retcode'], 0)
|
|
|
|
|
2015-12-28 17:19:05 +00:00
|
|
|
found = self.pip_successful_install(ret['stdout'])
|
2015-12-28 09:30:19 +00:00
|
|
|
|
|
|
|
self.assertTrue(found)
|
|
|
|
|
|
|
|
except (AssertionError, TypeError):
|
|
|
|
import pprint
|
|
|
|
pprint.pprint(ret)
|
|
|
|
raise
|
|
|
|
|
2017-04-04 17:57:27 +00:00
|
|
|
@skip_if_not_root
|
2018-04-27 21:15:34 +00:00
|
|
|
def test_requirements_as_list__absolute_file_path(self):
|
2015-12-27 03:30:27 +00:00
|
|
|
self.run_function('virtualenv.create', [self.venv_dir])
|
|
|
|
|
|
|
|
req1_filename = os.path.join(self.venv_dir, 'requirements.txt')
|
|
|
|
req2_filename = os.path.join(self.venv_dir, 'requirements2.txt')
|
|
|
|
|
2017-07-18 16:31:01 +00:00
|
|
|
with salt.utils.files.fopen(req1_filename, 'w') as f:
|
2018-04-10 19:09:20 +00:00
|
|
|
f.write('irc3-plugins-test\n')
|
2017-07-18 16:31:01 +00:00
|
|
|
with salt.utils.files.fopen(req2_filename, 'w') as f:
|
2015-12-27 03:30:27 +00:00
|
|
|
f.write('pep8\n')
|
|
|
|
|
|
|
|
requirements_list = [req1_filename, req2_filename]
|
|
|
|
|
|
|
|
ret = self.run_function(
|
2018-04-27 21:15:34 +00:00
|
|
|
'pip.install', requirements=requirements_list, bin_env=self.venv_dir
|
2015-12-27 03:30:27 +00:00
|
|
|
)
|
|
|
|
|
2015-12-28 17:19:05 +00:00
|
|
|
found = self.pip_successful_install(ret['stdout'])
|
2015-12-27 03:30:27 +00:00
|
|
|
|
2015-12-28 17:19:05 +00:00
|
|
|
try:
|
|
|
|
self.assertEqual(ret['retcode'], 0)
|
2015-12-27 03:30:27 +00:00
|
|
|
self.assertTrue(found)
|
|
|
|
|
|
|
|
except (AssertionError, TypeError):
|
|
|
|
import pprint
|
|
|
|
pprint.pprint(ret)
|
|
|
|
raise
|
|
|
|
|
2017-04-04 17:57:27 +00:00
|
|
|
@skip_if_not_root
|
2018-04-27 21:15:34 +00:00
|
|
|
def test_requirements_as_list__non_absolute_file_path(self):
|
2015-12-27 03:30:27 +00:00
|
|
|
self.run_function('virtualenv.create', [self.venv_dir])
|
|
|
|
|
|
|
|
# Create a requirements file that depends on another one.
|
|
|
|
|
|
|
|
req1_filename = 'requirements.txt'
|
|
|
|
req2_filename = 'requirements2.txt'
|
|
|
|
req_cwd = self.venv_dir
|
|
|
|
|
|
|
|
req1_filepath = os.path.join(req_cwd, req1_filename)
|
|
|
|
req2_filepath = os.path.join(req_cwd, req2_filename)
|
|
|
|
|
2017-07-18 16:31:01 +00:00
|
|
|
with salt.utils.files.fopen(req1_filepath, 'w') as f:
|
2018-04-10 19:09:20 +00:00
|
|
|
f.write('irc3-plugins-test\n')
|
2017-07-18 16:31:01 +00:00
|
|
|
with salt.utils.files.fopen(req2_filepath, 'w') as f:
|
2015-12-27 03:30:27 +00:00
|
|
|
f.write('pep8\n')
|
|
|
|
|
|
|
|
requirements_list = [req1_filename, req2_filename]
|
|
|
|
|
|
|
|
ret = self.run_function(
|
2018-04-27 21:15:34 +00:00
|
|
|
'pip.install', requirements=requirements_list,
|
2015-12-27 03:30:27 +00:00
|
|
|
bin_env=self.venv_dir, cwd=req_cwd
|
|
|
|
)
|
|
|
|
try:
|
|
|
|
self.assertEqual(ret['retcode'], 0)
|
|
|
|
|
2015-12-28 17:19:05 +00:00
|
|
|
found = self.pip_successful_install(ret['stdout'])
|
2015-12-27 03:30:27 +00:00
|
|
|
self.assertTrue(found)
|
|
|
|
|
|
|
|
except (AssertionError, TypeError):
|
|
|
|
import pprint
|
|
|
|
pprint.pprint(ret)
|
|
|
|
raise
|
|
|
|
|
2017-04-04 17:57:27 +00:00
|
|
|
@skip_if_not_root
|
2018-04-27 21:15:34 +00:00
|
|
|
def test_chained_requirements__absolute_file_path(self):
|
2015-12-27 03:30:27 +00:00
|
|
|
self.run_function('virtualenv.create', [self.venv_dir])
|
|
|
|
|
|
|
|
# Create a requirements file that depends on another one.
|
|
|
|
|
|
|
|
req1_filename = os.path.join(self.venv_dir, 'requirements.txt')
|
|
|
|
req2_filename = os.path.join(self.venv_dir, 'requirements2.txt')
|
|
|
|
|
2017-07-18 16:31:01 +00:00
|
|
|
with salt.utils.files.fopen(req1_filename, 'w') as f:
|
2015-12-27 03:30:27 +00:00
|
|
|
f.write('-r requirements2.txt')
|
2017-07-18 16:31:01 +00:00
|
|
|
with salt.utils.files.fopen(req2_filename, 'w') as f:
|
2015-12-27 03:30:27 +00:00
|
|
|
f.write('pep8')
|
|
|
|
|
|
|
|
ret = self.run_function(
|
2018-04-27 21:15:34 +00:00
|
|
|
'pip.install', requirements=req1_filename, bin_env=self.venv_dir
|
2015-12-27 03:30:27 +00:00
|
|
|
)
|
|
|
|
try:
|
|
|
|
self.assertEqual(ret['retcode'], 0)
|
|
|
|
self.assertIn('installed pep8', ret['stdout'])
|
|
|
|
except (AssertionError, TypeError):
|
|
|
|
import pprint
|
|
|
|
pprint.pprint(ret)
|
|
|
|
raise
|
|
|
|
|
2017-04-04 17:57:27 +00:00
|
|
|
@skip_if_not_root
|
2018-04-27 21:15:34 +00:00
|
|
|
def test_chained_requirements__non_absolute_file_path(self):
|
2015-12-27 03:30:27 +00:00
|
|
|
self.run_function('virtualenv.create', [self.venv_dir])
|
|
|
|
|
|
|
|
# Create a requirements file that depends on another one.
|
|
|
|
req_basepath = (self.venv_dir)
|
|
|
|
|
|
|
|
req1_filename = 'requirements.txt'
|
|
|
|
req2_filename = 'requirements2.txt'
|
|
|
|
|
|
|
|
req1_file = os.path.join(self.venv_dir, req1_filename)
|
|
|
|
req2_file = os.path.join(self.venv_dir, req2_filename)
|
|
|
|
|
2017-07-18 16:31:01 +00:00
|
|
|
with salt.utils.files.fopen(req1_file, 'w') as f:
|
2015-12-27 03:30:27 +00:00
|
|
|
f.write('-r requirements2.txt')
|
2017-07-18 16:31:01 +00:00
|
|
|
with salt.utils.files.fopen(req2_file, 'w') as f:
|
2015-12-27 03:30:27 +00:00
|
|
|
f.write('pep8')
|
|
|
|
|
|
|
|
ret = self.run_function(
|
2018-04-27 21:15:34 +00:00
|
|
|
'pip.install', requirements=req1_filename, cwd=req_basepath,
|
|
|
|
bin_env=self.venv_dir
|
2015-12-27 03:30:27 +00:00
|
|
|
)
|
|
|
|
try:
|
|
|
|
self.assertEqual(ret['retcode'], 0)
|
|
|
|
self.assertIn('installed pep8', ret['stdout'])
|
|
|
|
except (AssertionError, TypeError):
|
|
|
|
import pprint
|
|
|
|
pprint.pprint(ret)
|
|
|
|
raise
|
|
|
|
|
2017-04-04 17:57:27 +00:00
|
|
|
@skip_if_not_root
|
2018-04-27 21:15:34 +00:00
|
|
|
def test_issue_4805_nested_requirements(self):
|
2013-05-05 03:09:50 +00:00
|
|
|
self.run_function('virtualenv.create', [self.venv_dir])
|
|
|
|
|
|
|
|
# Create a requirements file that depends on another one.
|
|
|
|
req1_filename = os.path.join(self.venv_dir, 'requirements.txt')
|
|
|
|
req2_filename = os.path.join(self.venv_dir, 'requirements2.txt')
|
2017-07-18 16:31:01 +00:00
|
|
|
with salt.utils.files.fopen(req1_filename, 'w') as f:
|
2013-05-05 03:09:50 +00:00
|
|
|
f.write('-r requirements2.txt')
|
2017-07-18 16:31:01 +00:00
|
|
|
with salt.utils.files.fopen(req2_filename, 'w') as f:
|
2013-05-05 03:09:50 +00:00
|
|
|
f.write('pep8')
|
|
|
|
|
2013-08-12 12:36:52 +00:00
|
|
|
ret = self.run_function(
|
2018-04-27 21:15:34 +00:00
|
|
|
'pip.install', requirements=req1_filename, bin_env=self.venv_dir)
|
2016-09-29 06:11:38 +00:00
|
|
|
if self._check_download_error(ret['stdout']):
|
|
|
|
self.skipTest('Test skipped due to pip download error')
|
2013-07-04 17:57:42 +00:00
|
|
|
try:
|
|
|
|
self.assertEqual(ret['retcode'], 0)
|
|
|
|
self.assertIn('installed pep8', ret['stdout'])
|
|
|
|
except (AssertionError, TypeError):
|
|
|
|
import pprint
|
|
|
|
pprint.pprint(ret)
|
|
|
|
raise
|
2013-05-05 03:09:50 +00:00
|
|
|
|
2012-09-27 17:33:50 +00:00
|
|
|
def test_pip_uninstall(self):
|
|
|
|
# Let's create the testing virtualenv
|
|
|
|
self.run_function('virtualenv.create', [self.venv_dir])
|
|
|
|
ret = self.run_function('pip.install', ['pep8'], bin_env=self.venv_dir)
|
2016-09-29 06:11:38 +00:00
|
|
|
if self._check_download_error(ret['stdout']):
|
|
|
|
self.skipTest('Test skipped due to pip download error')
|
2012-09-27 17:33:50 +00:00
|
|
|
self.assertEqual(ret['retcode'], 0)
|
|
|
|
self.assertIn('installed pep8', ret['stdout'])
|
2012-12-11 10:23:37 +00:00
|
|
|
ret = self.run_function(
|
|
|
|
'pip.uninstall', ['pep8'], bin_env=self.venv_dir
|
|
|
|
)
|
2013-07-04 17:57:42 +00:00
|
|
|
try:
|
|
|
|
self.assertEqual(ret['retcode'], 0)
|
|
|
|
self.assertIn('uninstalled pep8', ret['stdout'])
|
|
|
|
except AssertionError:
|
|
|
|
import pprint
|
|
|
|
pprint.pprint(ret)
|
|
|
|
raise
|
2012-09-27 17:33:50 +00:00
|
|
|
|
2013-02-07 23:51:05 +00:00
|
|
|
def test_pip_install_upgrade(self):
|
|
|
|
# Create the testing virtualenv
|
|
|
|
self.run_function('virtualenv.create', [self.venv_dir])
|
|
|
|
ret = self.run_function(
|
2013-02-08 00:30:40 +00:00
|
|
|
'pip.install', ['pep8==1.3.4'], bin_env=self.venv_dir
|
2013-02-07 23:51:05 +00:00
|
|
|
)
|
2016-09-29 06:11:38 +00:00
|
|
|
if self._check_download_error(ret['stdout']):
|
|
|
|
self.skipTest('Test skipped due to pip download error')
|
2013-07-04 17:57:42 +00:00
|
|
|
try:
|
|
|
|
self.assertEqual(ret['retcode'], 0)
|
|
|
|
self.assertIn('installed pep8', ret['stdout'])
|
|
|
|
except AssertionError:
|
|
|
|
import pprint
|
|
|
|
pprint.pprint(ret)
|
|
|
|
raise
|
|
|
|
|
2013-02-07 23:51:05 +00:00
|
|
|
ret = self.run_function(
|
|
|
|
'pip.install',
|
|
|
|
['pep8'],
|
|
|
|
bin_env=self.venv_dir,
|
|
|
|
upgrade=True
|
|
|
|
)
|
2016-09-29 06:11:38 +00:00
|
|
|
if self._check_download_error(ret['stdout']):
|
|
|
|
self.skipTest('Test skipped due to pip download error')
|
2013-07-04 17:57:42 +00:00
|
|
|
try:
|
|
|
|
self.assertEqual(ret['retcode'], 0)
|
|
|
|
self.assertIn('installed pep8', ret['stdout'])
|
|
|
|
except AssertionError:
|
|
|
|
import pprint
|
|
|
|
pprint.pprint(ret)
|
|
|
|
raise
|
|
|
|
|
2013-02-07 23:51:05 +00:00
|
|
|
ret = self.run_function(
|
|
|
|
'pip.uninstall', ['pep8'], bin_env=self.venv_dir
|
|
|
|
)
|
2013-07-04 17:57:42 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
self.assertEqual(ret['retcode'], 0)
|
|
|
|
self.assertIn('uninstalled pep8', ret['stdout'])
|
|
|
|
except AssertionError:
|
|
|
|
import pprint
|
|
|
|
pprint.pprint(ret)
|
|
|
|
raise
|
|
|
|
|
|
|
|
def test_pip_install_multiple_editables(self):
|
|
|
|
editables = [
|
|
|
|
'git+https://github.com/jek/blinker.git#egg=Blinker',
|
|
|
|
'git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting'
|
|
|
|
]
|
|
|
|
|
|
|
|
# Create the testing virtualenv
|
|
|
|
self.run_function('virtualenv.create', [self.venv_dir])
|
|
|
|
ret = self.run_function(
|
|
|
|
'pip.install', [],
|
|
|
|
editable='{0}'.format(','.join(editables)),
|
|
|
|
bin_env=self.venv_dir
|
|
|
|
)
|
2016-09-29 06:11:38 +00:00
|
|
|
if self._check_download_error(ret['stdout']):
|
|
|
|
self.skipTest('Test skipped due to pip download error')
|
2013-07-04 17:57:42 +00:00
|
|
|
try:
|
|
|
|
self.assertEqual(ret['retcode'], 0)
|
|
|
|
self.assertIn(
|
|
|
|
'Successfully installed Blinker SaltTesting', ret['stdout']
|
|
|
|
)
|
|
|
|
except AssertionError:
|
|
|
|
import pprint
|
|
|
|
pprint.pprint(ret)
|
|
|
|
raise
|
|
|
|
|
|
|
|
def test_pip_install_multiple_editables_and_pkgs(self):
|
|
|
|
editables = [
|
|
|
|
'git+https://github.com/jek/blinker.git#egg=Blinker',
|
|
|
|
'git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting'
|
|
|
|
]
|
|
|
|
|
|
|
|
# Create the testing virtualenv
|
|
|
|
self.run_function('virtualenv.create', [self.venv_dir])
|
|
|
|
ret = self.run_function(
|
|
|
|
'pip.install', ['pep8'],
|
|
|
|
editable='{0}'.format(','.join(editables)),
|
|
|
|
bin_env=self.venv_dir
|
|
|
|
)
|
2016-09-29 06:11:38 +00:00
|
|
|
if self._check_download_error(ret['stdout']):
|
|
|
|
self.skipTest('Test skipped due to pip download error')
|
2013-07-04 17:57:42 +00:00
|
|
|
try:
|
|
|
|
self.assertEqual(ret['retcode'], 0)
|
2015-04-20 13:45:25 +00:00
|
|
|
for package in ('Blinker', 'SaltTesting', 'pep8'):
|
2017-03-31 11:22:33 +00:00
|
|
|
self.assertRegex(
|
2015-04-20 13:45:25 +00:00
|
|
|
ret['stdout'],
|
|
|
|
r'(?:.*)(Successfully installed)(?:.*)({0})(?:.*)'.format(package)
|
|
|
|
)
|
2013-07-04 17:57:42 +00:00
|
|
|
except AssertionError:
|
|
|
|
import pprint
|
|
|
|
pprint.pprint(ret)
|
|
|
|
raise
|
2013-02-07 23:51:05 +00:00
|
|
|
|
2018-06-18 17:58:33 +00:00
|
|
|
@skipIf(not os.path.isfile('pip3'), 'test where pip3 is installed')
|
|
|
|
@skipIf(salt.utils.platform.is_windows(), 'test specific for linux usage of /bin/python')
|
|
|
|
def test_system_pip3(self):
|
|
|
|
self.run_function('pip.install', pkgs=['lazyimport==0.0.1'], bin_env='/bin/pip3')
|
|
|
|
ret1 = self.run_function('cmd.run', '/bin/pip3 freeze | grep lazyimport')
|
|
|
|
self.run_function('pip.uninstall', pkgs=['lazyimport'], bin_env='/bin/pip3')
|
|
|
|
ret2 = self.run_function('cmd.run', '/bin/pip3 freeze | grep lazyimport')
|
|
|
|
assert 'lazyimport==0.0.1' in ret1
|
|
|
|
assert ret2 == ''
|
|
|
|
|
2012-09-27 11:06:09 +00:00
|
|
|
def tearDown(self):
|
|
|
|
super(PipModuleTest, self).tearDown()
|
|
|
|
if os.path.isdir(self.venv_test_dir):
|
2018-04-27 21:15:34 +00:00
|
|
|
shutil.rmtree(self.venv_test_dir, ignore_errors=True)
|
2013-07-04 17:57:42 +00:00
|
|
|
if os.path.isdir(self.pip_temp):
|
2018-04-27 21:15:34 +00:00
|
|
|
shutil.rmtree(self.pip_temp, ignore_errors=True)
|
2017-03-06 16:45:59 +00:00
|
|
|
del self.venv_dir
|
|
|
|
del self.venv_test_dir
|
|
|
|
del self.pip_temp
|