2012-09-18 00:53:05 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
2012-12-11 10:23:37 +00:00
|
|
|
:codeauthor: :email:`Pedro Algarvio (pedro@algarvio.me)`
|
2013-09-16 16:24:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
tests.integration.states.pip
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2012-09-18 00:53:05 +00:00
|
|
|
'''
|
|
|
|
|
2012-11-06 12:44:53 +00:00
|
|
|
# Import python libs
|
2014-11-21 19:05:13 +00:00
|
|
|
from __future__ import absolute_import
|
2016-09-15 03:38:13 +00:00
|
|
|
import errno
|
2012-09-18 00:53:05 +00:00
|
|
|
import os
|
2013-08-27 13:54:00 +00:00
|
|
|
import pwd
|
|
|
|
import glob
|
2012-09-18 00:53:05 +00:00
|
|
|
import shutil
|
|
|
|
|
2013-06-27 12:45:55 +00:00
|
|
|
# Import Salt Testing libs
|
2013-08-27 13:54:00 +00:00
|
|
|
from salttesting import skipIf
|
|
|
|
from salttesting.helpers import (
|
|
|
|
destructiveTest,
|
2015-01-09 17:52:55 +00:00
|
|
|
requires_system_grains,
|
2014-04-25 19:03:41 +00:00
|
|
|
with_system_user
|
2013-08-27 13:54:00 +00:00
|
|
|
)
|
2012-09-18 00:53:05 +00:00
|
|
|
# Import salt libs
|
2013-06-27 12:45:55 +00:00
|
|
|
import integration
|
2013-11-02 22:40:09 +00:00
|
|
|
import salt.utils
|
2014-01-11 19:19:29 +00:00
|
|
|
from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
|
2016-04-29 17:49:29 +00:00
|
|
|
from salt.exceptions import CommandExecutionError
|
2012-09-18 00:53:05 +00:00
|
|
|
|
2014-11-22 10:51:11 +00:00
|
|
|
# Import 3rd-party libs
|
|
|
|
import salt.ext.six as six
|
|
|
|
|
2012-09-18 00:53:05 +00:00
|
|
|
|
2014-01-11 19:19:29 +00:00
|
|
|
@skipIf(salt.utils.which_bin(KNOWN_BINARY_NAMES) is None, 'virtualenv not installed')
|
2012-12-07 16:59:24 +00:00
|
|
|
class PipStateTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn):
|
2012-09-18 00:53:05 +00:00
|
|
|
|
2016-05-12 20:54:47 +00:00
|
|
|
def test_pip_installed_removed(self):
|
|
|
|
'''
|
|
|
|
Tests installed and removed states
|
|
|
|
'''
|
|
|
|
ret = self.run_state('pip.installed', name='docker-py')
|
|
|
|
self.assertSaltTrueReturn(ret)
|
|
|
|
ret = self.run_state('pip.removed', name='docker-py')
|
|
|
|
self.assertSaltTrueReturn(ret)
|
|
|
|
|
2012-09-23 17:16:11 +00:00
|
|
|
def test_pip_installed_errors(self):
|
2012-11-06 12:44:53 +00:00
|
|
|
venv_dir = os.path.join(
|
|
|
|
integration.SYS_TMP_DIR, 'pip-installed-errors'
|
|
|
|
)
|
2012-09-23 17:16:11 +00:00
|
|
|
try:
|
|
|
|
# Since we don't have the virtualenv created, pip.installed will
|
|
|
|
# thrown and error.
|
2013-08-14 11:29:34 +00:00
|
|
|
# Example error strings:
|
|
|
|
# * "Error installing 'supervisor': /tmp/pip-installed-errors: not found"
|
|
|
|
# * "Error installing 'supervisor': /bin/sh: 1: /tmp/pip-installed-errors: not found"
|
|
|
|
# * "Error installing 'supervisor': /bin/bash: /tmp/pip-installed-errors: No such file or directory"
|
|
|
|
os.environ['SHELL'] = '/bin/sh'
|
2012-09-23 17:16:11 +00:00
|
|
|
ret = self.run_function('state.sls', mods='pip-installed-errors')
|
2012-12-07 16:59:24 +00:00
|
|
|
self.assertSaltFalseReturn(ret)
|
|
|
|
self.assertSaltCommentRegexpMatches(
|
|
|
|
ret,
|
2015-01-08 18:57:53 +00:00
|
|
|
'Error installing \'supervisor\':'
|
2012-12-07 16:59:24 +00:00
|
|
|
)
|
2012-09-23 17:16:11 +00:00
|
|
|
|
|
|
|
# We now create the missing virtualenv
|
|
|
|
ret = self.run_function('virtualenv.create', [venv_dir])
|
2012-11-06 12:44:53 +00:00
|
|
|
self.assertEqual(ret['retcode'], 0)
|
2012-09-23 17:16:11 +00:00
|
|
|
|
|
|
|
# The state should not have any issues running now
|
|
|
|
ret = self.run_function('state.sls', mods='pip-installed-errors')
|
2012-12-07 16:59:24 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
2012-09-23 17:16:11 +00:00
|
|
|
finally:
|
|
|
|
if os.path.isdir(venv_dir):
|
|
|
|
shutil.rmtree(venv_dir)
|
|
|
|
|
2015-01-09 17:52:55 +00:00
|
|
|
@requires_system_grains
|
|
|
|
def test_pip_installed_weird_install(self, grains=None):
|
2016-09-13 17:35:38 +00:00
|
|
|
# First, check to see if this is running on CentOS 5 or MacOS.
|
|
|
|
# If so, skip this test.
|
2015-01-09 17:52:55 +00:00
|
|
|
if grains['os'] in ('CentOS',) and grains['osrelease_info'][0] in (5,):
|
|
|
|
self.skipTest('This test does not run reliably on CentOS 5')
|
2016-09-13 17:35:38 +00:00
|
|
|
if grains['os'] in ('MacOS',):
|
|
|
|
self.skipTest('This test does not run reliably on MacOS')
|
2015-01-09 17:52:55 +00:00
|
|
|
|
2012-09-25 11:24:54 +00:00
|
|
|
ographite = '/opt/graphite'
|
|
|
|
if os.path.isdir(ographite):
|
|
|
|
self.skipTest(
|
|
|
|
'You already have \'{0}\'. This test would overwrite this '
|
|
|
|
'directory'.format(ographite)
|
|
|
|
)
|
|
|
|
try:
|
|
|
|
os.makedirs(ographite)
|
2013-05-04 02:53:53 +00:00
|
|
|
except OSError as err:
|
2016-09-15 03:38:13 +00:00
|
|
|
if err.errno == errno.EACCES:
|
2012-09-25 11:24:54 +00:00
|
|
|
# Permission denied
|
|
|
|
self.skipTest(
|
|
|
|
'You don\'t have the required permissions to run this test'
|
|
|
|
)
|
|
|
|
finally:
|
|
|
|
if os.path.isdir(ographite):
|
|
|
|
shutil.rmtree(ographite)
|
|
|
|
|
2016-09-15 03:38:13 +00:00
|
|
|
venv_dir = os.path.join(integration.TMP, 'pip-installed-weird-install')
|
2012-09-25 11:24:54 +00:00
|
|
|
try:
|
2016-09-15 03:38:13 +00:00
|
|
|
# We may be able to remove this, I had to add it because the custom
|
|
|
|
# modules from the test suite weren't available in the jinja
|
|
|
|
# context when running the call to state.sls that comes after.
|
|
|
|
self.run_function('saltutil.sync_modules')
|
2012-09-25 11:24:54 +00:00
|
|
|
# Since we don't have the virtualenv created, pip.installed will
|
|
|
|
# thrown and error.
|
|
|
|
ret = self.run_function(
|
|
|
|
'state.sls', mods='pip-installed-weird-install'
|
|
|
|
)
|
2012-12-07 16:59:24 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
2012-09-25 11:24:54 +00:00
|
|
|
|
2012-12-07 16:59:24 +00:00
|
|
|
# We cannot use assertInSaltComment here because we need to skip
|
|
|
|
# some of the state return parts
|
2014-11-22 10:51:11 +00:00
|
|
|
for key in six.iterkeys(ret):
|
2012-09-25 11:24:54 +00:00
|
|
|
self.assertTrue(ret[key]['result'])
|
2016-09-15 03:38:13 +00:00
|
|
|
if ret[key]['name'] != 'carbon':
|
2012-09-25 11:24:54 +00:00
|
|
|
continue
|
|
|
|
self.assertEqual(
|
|
|
|
ret[key]['comment'],
|
2013-08-08 23:43:44 +00:00
|
|
|
'There was no error installing package \'carbon\' '
|
2012-09-25 11:24:54 +00:00
|
|
|
'although it does not show when calling \'pip.freeze\'.'
|
|
|
|
)
|
2016-09-15 03:38:13 +00:00
|
|
|
break
|
|
|
|
else:
|
|
|
|
raise Exception('Expected state did not run')
|
2012-09-25 11:24:54 +00:00
|
|
|
finally:
|
|
|
|
if os.path.isdir('/opt/graphite'):
|
|
|
|
shutil.rmtree('/opt/graphite')
|
|
|
|
|
2012-09-23 17:16:11 +00:00
|
|
|
def test_issue_2028_pip_installed_state(self):
|
|
|
|
ret = self.run_function('state.sls', mods='issue-2028-pip-installed')
|
|
|
|
|
2012-11-06 12:44:53 +00:00
|
|
|
venv_dir = os.path.join(
|
|
|
|
integration.SYS_TMP_DIR, 'issue-2028-pip-installed'
|
|
|
|
)
|
2012-09-23 17:16:11 +00:00
|
|
|
|
|
|
|
try:
|
2012-12-07 16:59:24 +00:00
|
|
|
self.assertSaltTrueReturn(ret)
|
2012-09-23 17:16:11 +00:00
|
|
|
self.assertTrue(
|
|
|
|
os.path.isfile(os.path.join(venv_dir, 'bin', 'supervisord'))
|
|
|
|
)
|
|
|
|
finally:
|
|
|
|
if os.path.isdir(venv_dir):
|
|
|
|
shutil.rmtree(venv_dir)
|
2012-09-27 11:06:09 +00:00
|
|
|
|
|
|
|
def test_issue_2087_missing_pip(self):
|
2012-11-06 12:44:53 +00:00
|
|
|
venv_dir = os.path.join(
|
|
|
|
integration.SYS_TMP_DIR, 'issue-2087-missing-pip'
|
|
|
|
)
|
|
|
|
|
2012-09-27 11:06:09 +00:00
|
|
|
try:
|
|
|
|
# Let's create the testing virtualenv
|
2012-12-07 16:59:24 +00:00
|
|
|
ret = self.run_function('virtualenv.create', [venv_dir])
|
|
|
|
self.assertEqual(ret['retcode'], 0)
|
2012-09-27 11:06:09 +00:00
|
|
|
|
|
|
|
# Let's remove the pip binary
|
|
|
|
pip_bin = os.path.join(venv_dir, 'bin', 'pip')
|
|
|
|
if not os.path.isfile(pip_bin):
|
|
|
|
self.skipTest(
|
|
|
|
'Failed to find the pip binary to the test virtualenv'
|
|
|
|
)
|
|
|
|
os.remove(pip_bin)
|
|
|
|
|
|
|
|
# Let's run the state which should fail because pip is missing
|
|
|
|
ret = self.run_function('state.sls', mods='issue-2087-missing-pip')
|
2012-12-07 16:59:24 +00:00
|
|
|
self.assertSaltFalseReturn(ret)
|
|
|
|
self.assertInSaltComment(
|
2013-08-18 04:46:33 +00:00
|
|
|
'Error installing \'pep8\': Could not find a `pip` binary',
|
|
|
|
ret
|
2012-09-27 11:06:09 +00:00
|
|
|
)
|
|
|
|
finally:
|
|
|
|
if os.path.isdir(venv_dir):
|
|
|
|
shutil.rmtree(venv_dir)
|
2013-06-25 07:57:26 +00:00
|
|
|
|
2013-07-05 22:00:14 +00:00
|
|
|
def test_issue_5940_multiple_pip_mirrors(self):
|
2016-04-29 17:49:29 +00:00
|
|
|
'''
|
|
|
|
Test multiple pip mirrors. This test only works with pip < 7.0.0
|
|
|
|
'''
|
2013-07-05 22:00:14 +00:00
|
|
|
ret = self.run_function(
|
|
|
|
'state.sls', mods='issue-5940-multiple-pip-mirrors'
|
|
|
|
)
|
|
|
|
|
|
|
|
venv_dir = os.path.join(
|
|
|
|
integration.SYS_TMP_DIR, '5940-multiple-pip-mirrors'
|
|
|
|
)
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.assertSaltTrueReturn(ret)
|
|
|
|
self.assertTrue(
|
|
|
|
os.path.isfile(os.path.join(venv_dir, 'bin', 'pep8'))
|
|
|
|
)
|
2016-04-29 17:49:29 +00:00
|
|
|
except (AssertionError, CommandExecutionError):
|
|
|
|
pip_version = self.run_function('pip.version', [venv_dir])
|
|
|
|
if salt.utils.compare_versions(ver1=pip_version, oper='>=', ver2='7.0.0'):
|
|
|
|
self.skipTest('the --mirrors arg has been deprecated and removed in pip==7.0.0')
|
2013-07-05 22:00:14 +00:00
|
|
|
finally:
|
|
|
|
if os.path.isdir(venv_dir):
|
|
|
|
shutil.rmtree(venv_dir)
|
|
|
|
|
2013-08-27 13:54:00 +00:00
|
|
|
@destructiveTest
|
|
|
|
@skipIf(os.geteuid() != 0, 'you must be root to run this test')
|
2014-04-25 19:03:41 +00:00
|
|
|
@with_system_user('issue-6912', on_existing='delete', delete=True)
|
2013-08-27 13:54:00 +00:00
|
|
|
def test_issue_6912_wrong_owner(self, username):
|
|
|
|
venv_dir = os.path.join(
|
|
|
|
integration.SYS_TMP_DIR, '6912-wrong-owner'
|
|
|
|
)
|
2013-08-27 13:56:37 +00:00
|
|
|
# ----- Using runas ------------------------------------------------->
|
2013-08-27 13:54:00 +00:00
|
|
|
venv_create = self.run_function(
|
2015-01-07 18:56:57 +00:00
|
|
|
'virtualenv.create', [venv_dir], user=username
|
2013-08-27 13:54:00 +00:00
|
|
|
)
|
|
|
|
if venv_create['retcode'] > 0:
|
|
|
|
self.skipTest(
|
|
|
|
'Failed to create testcase virtual environment: {0}'.format(
|
2013-11-02 22:40:09 +00:00
|
|
|
venv_create
|
2013-08-27 13:54:00 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2013-08-29 20:21:23 +00:00
|
|
|
# Using the package name.
|
2013-08-27 13:54:00 +00:00
|
|
|
try:
|
|
|
|
ret = self.run_state(
|
2015-01-07 21:18:28 +00:00
|
|
|
'pip.installed', name='pep8', user=username, bin_env=venv_dir
|
2013-08-27 13:54:00 +00:00
|
|
|
)
|
|
|
|
self.assertSaltTrueReturn(ret)
|
|
|
|
uinfo = pwd.getpwnam(username)
|
|
|
|
for globmatch in (os.path.join(venv_dir, '**', 'pep8*'),
|
|
|
|
os.path.join(venv_dir, '*', '**', 'pep8*'),
|
|
|
|
os.path.join(venv_dir, '*', '*', '**', 'pep8*')):
|
|
|
|
for path in glob.glob(globmatch):
|
|
|
|
self.assertEqual(
|
|
|
|
uinfo.pw_uid, os.stat(path).st_uid
|
|
|
|
)
|
|
|
|
|
|
|
|
finally:
|
|
|
|
if os.path.isdir(venv_dir):
|
|
|
|
shutil.rmtree(venv_dir)
|
2013-08-29 20:21:23 +00:00
|
|
|
|
|
|
|
# Using a requirements file
|
|
|
|
venv_create = self.run_function(
|
2015-01-07 21:18:28 +00:00
|
|
|
'virtualenv.create', [venv_dir], user=username
|
2013-08-29 20:21:23 +00:00
|
|
|
)
|
|
|
|
if venv_create['retcode'] > 0:
|
|
|
|
self.skipTest(
|
|
|
|
'Failed to create testcase virtual environment: {0}'.format(
|
|
|
|
ret
|
|
|
|
)
|
|
|
|
)
|
|
|
|
req_filename = os.path.join(
|
|
|
|
integration.TMP_STATE_TREE, 'issue-6912-requirements.txt'
|
|
|
|
)
|
2013-11-02 22:40:09 +00:00
|
|
|
with salt.utils.fopen(req_filename, 'wb') as reqf:
|
|
|
|
reqf.write('pep8')
|
2013-08-29 20:21:23 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
ret = self.run_state(
|
2015-01-07 21:18:28 +00:00
|
|
|
'pip.installed', name='', user=username, bin_env=venv_dir,
|
2013-08-29 20:21:23 +00:00
|
|
|
requirements='salt://issue-6912-requirements.txt'
|
|
|
|
)
|
|
|
|
self.assertSaltTrueReturn(ret)
|
|
|
|
uinfo = pwd.getpwnam(username)
|
|
|
|
for globmatch in (os.path.join(venv_dir, '**', 'pep8*'),
|
|
|
|
os.path.join(venv_dir, '*', '**', 'pep8*'),
|
|
|
|
os.path.join(venv_dir, '*', '*', '**', 'pep8*')):
|
|
|
|
for path in glob.glob(globmatch):
|
|
|
|
self.assertEqual(
|
|
|
|
uinfo.pw_uid, os.stat(path).st_uid
|
|
|
|
)
|
|
|
|
|
|
|
|
finally:
|
|
|
|
if os.path.isdir(venv_dir):
|
|
|
|
shutil.rmtree(venv_dir)
|
|
|
|
os.unlink(req_filename)
|
2013-08-27 13:56:37 +00:00
|
|
|
# <---- Using runas --------------------------------------------------
|
|
|
|
|
|
|
|
# ----- Using user -------------------------------------------------->
|
|
|
|
venv_create = self.run_function(
|
2015-01-07 21:18:28 +00:00
|
|
|
'virtualenv.create', [venv_dir], user=username
|
2013-08-27 13:56:37 +00:00
|
|
|
)
|
|
|
|
if venv_create['retcode'] > 0:
|
|
|
|
self.skipTest(
|
|
|
|
'Failed to create testcase virtual environment: {0}'.format(
|
|
|
|
ret
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2013-08-29 20:21:23 +00:00
|
|
|
# Using the package name
|
2013-08-27 13:56:37 +00:00
|
|
|
try:
|
|
|
|
ret = self.run_state(
|
|
|
|
'pip.installed', name='pep8', user=username, bin_env=venv_dir
|
|
|
|
)
|
|
|
|
self.assertSaltTrueReturn(ret)
|
|
|
|
uinfo = pwd.getpwnam(username)
|
|
|
|
for globmatch in (os.path.join(venv_dir, '**', 'pep8*'),
|
|
|
|
os.path.join(venv_dir, '*', '**', 'pep8*'),
|
|
|
|
os.path.join(venv_dir, '*', '*', '**', 'pep8*')):
|
|
|
|
for path in glob.glob(globmatch):
|
|
|
|
self.assertEqual(
|
|
|
|
uinfo.pw_uid, os.stat(path).st_uid
|
|
|
|
)
|
|
|
|
|
|
|
|
finally:
|
|
|
|
if os.path.isdir(venv_dir):
|
|
|
|
shutil.rmtree(venv_dir)
|
2013-08-29 20:21:23 +00:00
|
|
|
|
|
|
|
# Using a requirements file
|
|
|
|
venv_create = self.run_function(
|
2015-01-07 21:18:28 +00:00
|
|
|
'virtualenv.create', [venv_dir], user=username
|
2013-08-29 20:21:23 +00:00
|
|
|
)
|
|
|
|
if venv_create['retcode'] > 0:
|
|
|
|
self.skipTest(
|
|
|
|
'Failed to create testcase virtual environment: {0}'.format(
|
|
|
|
ret
|
|
|
|
)
|
|
|
|
)
|
|
|
|
req_filename = os.path.join(
|
|
|
|
integration.TMP_STATE_TREE, 'issue-6912-requirements.txt'
|
|
|
|
)
|
2013-11-02 22:40:09 +00:00
|
|
|
with salt.utils.fopen(req_filename, 'wb') as reqf:
|
|
|
|
reqf.write('pep8')
|
2013-08-29 20:21:23 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
ret = self.run_state(
|
|
|
|
'pip.installed', name='', user=username, bin_env=venv_dir,
|
|
|
|
requirements='salt://issue-6912-requirements.txt'
|
|
|
|
)
|
|
|
|
self.assertSaltTrueReturn(ret)
|
|
|
|
uinfo = pwd.getpwnam(username)
|
|
|
|
for globmatch in (os.path.join(venv_dir, '**', 'pep8*'),
|
|
|
|
os.path.join(venv_dir, '*', '**', 'pep8*'),
|
|
|
|
os.path.join(venv_dir, '*', '*', '**', 'pep8*')):
|
|
|
|
for path in glob.glob(globmatch):
|
|
|
|
self.assertEqual(
|
|
|
|
uinfo.pw_uid, os.stat(path).st_uid
|
|
|
|
)
|
|
|
|
|
|
|
|
finally:
|
|
|
|
if os.path.isdir(venv_dir):
|
|
|
|
shutil.rmtree(venv_dir)
|
|
|
|
os.unlink(req_filename)
|
2013-08-27 13:56:37 +00:00
|
|
|
# <---- Using user ---------------------------------------------------
|
2013-08-27 13:54:00 +00:00
|
|
|
|
2013-09-10 09:52:17 +00:00
|
|
|
def test_issue_6833_pip_upgrade_pip(self):
|
|
|
|
# Create the testing virtualenv
|
|
|
|
venv_dir = os.path.join(
|
|
|
|
integration.TMP, '6833-pip-upgrade-pip'
|
|
|
|
)
|
|
|
|
ret = self.run_function('virtualenv.create', [venv_dir])
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
self.assertEqual(ret['retcode'], 0)
|
|
|
|
self.assertIn(
|
|
|
|
'New python executable',
|
|
|
|
ret['stdout']
|
|
|
|
)
|
|
|
|
except AssertionError:
|
|
|
|
import pprint
|
|
|
|
pprint.pprint(ret)
|
|
|
|
raise
|
|
|
|
|
|
|
|
# Let's install a fixed version pip over whatever pip was
|
|
|
|
# previously installed
|
|
|
|
ret = self.run_function(
|
Test with a more recent pip version to avoid a traceback
```
07:39:05,449 [salt.minion :1178][ERROR ] A command in 'pip.list' had a problem: Traceback (most recent call last):
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/bin/pip", line 9, in <module>
load_entry_point('pip==1.3.1', 'console_scripts', 'pip')()
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pkg_resources/__init__.py", line 546, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pkg_resources/__init__.py", line 2666, in load_entry_point
return ep.load()
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pkg_resources/__init__.py", line 2339, in load
return self.resolve()
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pkg_resources/__init__.py", line 2345, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/__init__.py", line 13, in <module>
from pip.commands import commands, get_similar_commands, get_summaries
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/commands/__init__.py", line 6, in <module>
from pip.commands.bundle import BundleCommand
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/commands/bundle.py", line 5, in <module>
from pip.commands.install import InstallCommand
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/commands/install.py", line 5, in <module>
from pip.req import InstallRequirement, RequirementSet, parse_requirements
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/req/__init__.py", line 3, in <module>
from .req_install import InstallRequirement
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/req/req_install.py", line 20, in <module>
import pip.wheel
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/wheel.py", line 23, in <module>
from pip.exceptions import InvalidWheelFilename, UnsupportedWheel
ImportError: cannot import name InvalidWheelFilename
```
2015-04-22 15:13:58 +00:00
|
|
|
'pip.install', ['pip==6.0'], upgrade=True,
|
2013-09-10 09:52:17 +00:00
|
|
|
bin_env=venv_dir
|
|
|
|
)
|
|
|
|
try:
|
|
|
|
self.assertEqual(ret['retcode'], 0)
|
|
|
|
self.assertIn(
|
|
|
|
'Successfully installed pip',
|
|
|
|
ret['stdout']
|
|
|
|
)
|
|
|
|
except AssertionError:
|
|
|
|
import pprint
|
|
|
|
pprint.pprint(ret)
|
|
|
|
raise
|
|
|
|
|
2016-09-12 18:17:30 +00:00
|
|
|
# Let's make sure we have pip 6.0 installed
|
2013-09-10 09:52:17 +00:00
|
|
|
self.assertEqual(
|
2013-09-11 09:54:43 +00:00
|
|
|
self.run_function('pip.list', ['pip'], bin_env=venv_dir),
|
Test with a more recent pip version to avoid a traceback
```
07:39:05,449 [salt.minion :1178][ERROR ] A command in 'pip.list' had a problem: Traceback (most recent call last):
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/bin/pip", line 9, in <module>
load_entry_point('pip==1.3.1', 'console_scripts', 'pip')()
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pkg_resources/__init__.py", line 546, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pkg_resources/__init__.py", line 2666, in load_entry_point
return ep.load()
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pkg_resources/__init__.py", line 2339, in load
return self.resolve()
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pkg_resources/__init__.py", line 2345, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/__init__.py", line 13, in <module>
from pip.commands import commands, get_similar_commands, get_summaries
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/commands/__init__.py", line 6, in <module>
from pip.commands.bundle import BundleCommand
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/commands/bundle.py", line 5, in <module>
from pip.commands.install import InstallCommand
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/commands/install.py", line 5, in <module>
from pip.req import InstallRequirement, RequirementSet, parse_requirements
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/req/__init__.py", line 3, in <module>
from .req_install import InstallRequirement
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/req/req_install.py", line 20, in <module>
import pip.wheel
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/wheel.py", line 23, in <module>
from pip.exceptions import InvalidWheelFilename, UnsupportedWheel
ImportError: cannot import name InvalidWheelFilename
```
2015-04-22 15:13:58 +00:00
|
|
|
{'pip': '6.0'}
|
2013-09-10 09:52:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Now the actual pip upgrade pip test
|
|
|
|
ret = self.run_state(
|
Test with a more recent pip version to avoid a traceback
```
07:39:05,449 [salt.minion :1178][ERROR ] A command in 'pip.list' had a problem: Traceback (most recent call last):
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/bin/pip", line 9, in <module>
load_entry_point('pip==1.3.1', 'console_scripts', 'pip')()
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pkg_resources/__init__.py", line 546, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pkg_resources/__init__.py", line 2666, in load_entry_point
return ep.load()
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pkg_resources/__init__.py", line 2339, in load
return self.resolve()
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pkg_resources/__init__.py", line 2345, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/__init__.py", line 13, in <module>
from pip.commands import commands, get_similar_commands, get_summaries
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/commands/__init__.py", line 6, in <module>
from pip.commands.bundle import BundleCommand
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/commands/bundle.py", line 5, in <module>
from pip.commands.install import InstallCommand
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/commands/install.py", line 5, in <module>
from pip.req import InstallRequirement, RequirementSet, parse_requirements
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/req/__init__.py", line 3, in <module>
from .req_install import InstallRequirement
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/req/req_install.py", line 20, in <module>
import pip.wheel
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/wheel.py", line 23, in <module>
from pip.exceptions import InvalidWheelFilename, UnsupportedWheel
ImportError: cannot import name InvalidWheelFilename
```
2015-04-22 15:13:58 +00:00
|
|
|
'pip.installed', name='pip==6.0.7', upgrade=True,
|
2013-09-10 09:52:17 +00:00
|
|
|
bin_env=venv_dir
|
|
|
|
)
|
|
|
|
try:
|
|
|
|
self.assertSaltTrueReturn(ret)
|
|
|
|
self.assertInSaltReturn(
|
|
|
|
'Installed',
|
|
|
|
ret,
|
Test with a more recent pip version to avoid a traceback
```
07:39:05,449 [salt.minion :1178][ERROR ] A command in 'pip.list' had a problem: Traceback (most recent call last):
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/bin/pip", line 9, in <module>
load_entry_point('pip==1.3.1', 'console_scripts', 'pip')()
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pkg_resources/__init__.py", line 546, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pkg_resources/__init__.py", line 2666, in load_entry_point
return ep.load()
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pkg_resources/__init__.py", line 2339, in load
return self.resolve()
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pkg_resources/__init__.py", line 2345, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/__init__.py", line 13, in <module>
from pip.commands import commands, get_similar_commands, get_summaries
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/commands/__init__.py", line 6, in <module>
from pip.commands.bundle import BundleCommand
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/commands/bundle.py", line 5, in <module>
from pip.commands.install import InstallCommand
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/commands/install.py", line 5, in <module>
from pip.req import InstallRequirement, RequirementSet, parse_requirements
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/req/__init__.py", line 3, in <module>
from .req_install import InstallRequirement
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/req/req_install.py", line 20, in <module>
import pip.wheel
File "/tmp/salt-tests-tmpdir/6833-pip-upgrade-pip/lib/python2.6/site-packages/pip/wheel.py", line 23, in <module>
from pip.exceptions import InvalidWheelFilename, UnsupportedWheel
ImportError: cannot import name InvalidWheelFilename
```
2015-04-22 15:13:58 +00:00
|
|
|
['changes', 'pip==6.0.7']
|
2013-09-10 09:52:17 +00:00
|
|
|
)
|
|
|
|
except AssertionError:
|
|
|
|
import pprint
|
|
|
|
pprint.pprint(ret)
|
|
|
|
raise
|
|
|
|
finally:
|
|
|
|
if os.path.isdir(venv_dir):
|
|
|
|
shutil.rmtree(venv_dir)
|
|
|
|
|
2013-11-02 22:40:09 +00:00
|
|
|
def test_pip_installed_specific_env(self):
|
|
|
|
# Create the testing virtualenv
|
|
|
|
venv_dir = os.path.join(
|
|
|
|
integration.TMP, 'pip-installed-specific-env'
|
|
|
|
)
|
|
|
|
|
|
|
|
# Let's write a requirements file
|
|
|
|
requirements_file = os.path.join(
|
|
|
|
integration.TMP_PRODENV_STATE_TREE, 'prod-env-requirements.txt'
|
|
|
|
)
|
|
|
|
with salt.utils.fopen(requirements_file, 'wb') as reqf:
|
|
|
|
reqf.write('pep8\n')
|
|
|
|
|
|
|
|
try:
|
2015-01-05 22:20:18 +00:00
|
|
|
self.run_function('virtualenv.create', [venv_dir])
|
2013-11-02 22:40:09 +00:00
|
|
|
|
|
|
|
# The requirements file should not be found the base environment
|
|
|
|
ret = self.run_state(
|
|
|
|
'pip.installed', name='', bin_env=venv_dir,
|
|
|
|
requirements='salt://prod-env-requirements.txt'
|
|
|
|
)
|
|
|
|
self.assertSaltFalseReturn(ret)
|
|
|
|
self.assertInSaltComment(
|
|
|
|
"'salt://prod-env-requirements.txt' not found", ret
|
|
|
|
)
|
|
|
|
|
|
|
|
# The requirements file must be found in the prod environment
|
|
|
|
ret = self.run_state(
|
2013-11-06 23:36:40 +00:00
|
|
|
'pip.installed', name='', bin_env=venv_dir, saltenv='prod',
|
2013-11-02 22:40:09 +00:00
|
|
|
requirements='salt://prod-env-requirements.txt'
|
|
|
|
)
|
|
|
|
self.assertSaltTrueReturn(ret)
|
|
|
|
self.assertInSaltComment(
|
2015-01-05 22:36:45 +00:00
|
|
|
'Successfully processed requirements file '
|
|
|
|
'salt://prod-env-requirements.txt', ret
|
2013-11-02 22:40:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# We're using the base environment but we're passing the prod
|
|
|
|
# environment as an url arg to salt://
|
2013-11-06 23:36:40 +00:00
|
|
|
ret = self.run_state(
|
|
|
|
'pip.installed', name='', bin_env=venv_dir,
|
|
|
|
requirements='salt://prod-env-requirements.txt?saltenv=prod'
|
|
|
|
)
|
|
|
|
self.assertSaltTrueReturn(ret)
|
|
|
|
self.assertInSaltComment(
|
2015-01-05 22:36:45 +00:00
|
|
|
'Requirements were already installed.',
|
|
|
|
ret
|
2013-11-06 23:36:40 +00:00
|
|
|
)
|
2013-11-02 22:40:09 +00:00
|
|
|
finally:
|
|
|
|
if os.path.isdir(venv_dir):
|
|
|
|
shutil.rmtree(venv_dir)
|
|
|
|
if os.path.isfile(requirements_file):
|
|
|
|
os.unlink(requirements_file)
|
|
|
|
|
2015-04-05 00:00:08 +00:00
|
|
|
def test_22359_pip_installed_unless_does_not_trigger_warnings(self):
|
|
|
|
# This test case should be moved to a format_call unit test specific to
|
|
|
|
# the state internal keywords
|
|
|
|
venv_dir = venv_dir = os.path.join(
|
|
|
|
integration.TMP, 'pip-installed-unless'
|
|
|
|
)
|
|
|
|
venv_create = self.run_function('virtualenv.create', [venv_dir])
|
|
|
|
if venv_create['retcode'] > 0:
|
|
|
|
self.skipTest(
|
|
|
|
'Failed to create testcase virtual environment: {0}'.format(
|
|
|
|
venv_create
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
try:
|
|
|
|
ret = self.run_state(
|
|
|
|
'pip.installed', name='pep8', bin_env=venv_dir, unless='/bin/false'
|
|
|
|
)
|
|
|
|
self.assertSaltTrueReturn(ret)
|
2017-02-21 18:15:52 +00:00
|
|
|
self.assertNotIn('warnings', next(six.itervalues(ret)))
|
2015-04-05 00:00:08 +00:00
|
|
|
finally:
|
|
|
|
if os.path.isdir(venv_dir):
|
|
|
|
shutil.rmtree(venv_dir)
|