2012-09-18 00:53:05 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
2012-12-11 10:23:37 +00:00
|
|
|
tests.integration.states.pip
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
:codeauthor: :email:`Pedro Algarvio (pedro@algarvio.me)`
|
2013-06-25 07:57:26 +00:00
|
|
|
:copyright: © 2012-2013 by the SaltStack Team, see AUTHORS for more details
|
2012-12-11 10:23:37 +00:00
|
|
|
:license: Apache 2.0, see LICENSE for more details.
|
2012-09-18 00:53:05 +00:00
|
|
|
'''
|
|
|
|
|
2012-11-06 12:44:53 +00:00
|
|
|
# Import python libs
|
2012-09-18 00:53:05 +00:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
|
|
|
|
# Import salt libs
|
2013-06-25 07:57:26 +00:00
|
|
|
try:
|
|
|
|
import integration
|
|
|
|
except ImportError:
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
|
|
|
sys.path.insert(
|
|
|
|
0, os.path.abspath(
|
|
|
|
os.path.join(
|
|
|
|
os.path.dirname(__file__), '../../'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
import integration
|
2012-09-18 00:53:05 +00:00
|
|
|
|
|
|
|
|
2012-12-07 16:59:24 +00:00
|
|
|
class PipStateTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn):
|
2012-09-18 00:53:05 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(PipStateTest, self).setUp()
|
|
|
|
ret = self.run_function('cmd.has_exec', ['virtualenv'])
|
|
|
|
if not ret:
|
|
|
|
self.skipTest('virtualenv not installed')
|
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.
|
|
|
|
ret = self.run_function('state.sls', mods='pip-installed-errors')
|
2012-12-07 16:59:24 +00:00
|
|
|
self.assertSaltFalseReturn(ret)
|
|
|
|
self.assertSaltCommentRegexpMatches(
|
|
|
|
ret,
|
|
|
|
'Error installing \'supervisor\': .* '
|
|
|
|
'[nN]o such file or directory'
|
|
|
|
)
|
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)
|
|
|
|
|
2012-09-25 11:24:54 +00:00
|
|
|
def test_pip_installed_weird_install(self):
|
|
|
|
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:
|
2012-09-25 11:24:54 +00:00
|
|
|
if err.errno == 13:
|
|
|
|
# Permission denied
|
|
|
|
self.skipTest(
|
|
|
|
'You don\'t have the required permissions to run this test'
|
|
|
|
)
|
|
|
|
finally:
|
|
|
|
if os.path.isdir(ographite):
|
|
|
|
shutil.rmtree(ographite)
|
|
|
|
|
2012-11-06 12:44:53 +00:00
|
|
|
venv_dir = os.path.join(
|
|
|
|
integration.SYS_TMP_DIR, 'pip-installed-weird-install'
|
|
|
|
)
|
2012-09-25 11:24:54 +00:00
|
|
|
try:
|
|
|
|
# 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
|
2012-09-25 11:24:54 +00:00
|
|
|
for key in ret.keys():
|
|
|
|
self.assertTrue(ret[key]['result'])
|
|
|
|
if ret[key]['comment'] == 'Created new virtualenv':
|
|
|
|
continue
|
|
|
|
self.assertEqual(
|
|
|
|
ret[key]['comment'],
|
2013-03-12 04:03:12 +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\'.'
|
|
|
|
)
|
|
|
|
finally:
|
|
|
|
if os.path.isdir(venv_dir):
|
|
|
|
shutil.rmtree(venv_dir)
|
|
|
|
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(
|
|
|
|
ret,
|
2012-09-27 17:33:50 +00:00
|
|
|
'Error installing \'pep8\': Could not find a `pip` binary'
|
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
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
from integration import run_tests
|
|
|
|
run_tests(PipStateTest)
|