mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge branch '2017.7' into skip_diskusage
This commit is contained in:
commit
068da8ad7d
41 changed files with 1429 additions and 1080 deletions
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
<% vagrant = system('which vagrant 2>/dev/null >/dev/null') %>
|
||||
<% vagrant = system('gem list -i kitchen-vagrant 2>/dev/null >/dev/null') %>
|
||||
<% version = '2017.7.4' %>
|
||||
<% platformsfile = ENV['SALT_KITCHEN_PLATFORMS'] || '.kitchen/platforms.yml' %>
|
||||
<% driverfile = ENV['SALT_KITCHEN_DRIVER'] || '.kitchen/driver.yml' %>
|
||||
|
@ -92,12 +92,9 @@ platforms:
|
|||
- yum install -y upstart
|
||||
provisioner:
|
||||
salt_bootstrap_options: -P -p rsync -y -x python2.7 -X git v<%= version %> >/dev/null
|
||||
- name: ubuntu-rolling
|
||||
- name: ubuntu-18.04
|
||||
driver_config:
|
||||
image: ubuntu:rolling
|
||||
run_command: /lib/systemd/systemd
|
||||
provisioner:
|
||||
salt_bootstrap_url: https://raw.githubusercontent.com/saltstack/salt-bootstrap/develop/bootstrap-salt.sh
|
||||
- name: ubuntu-16.04
|
||||
driver_config:
|
||||
run_command: /lib/systemd/systemd
|
||||
|
|
|
@ -38,7 +38,10 @@ from __future__ import division
|
|||
import re
|
||||
from docutils import nodes
|
||||
from docutils.parsers.rst import directives
|
||||
from sphinx.util.compat import Directive
|
||||
try:
|
||||
from sphinx.util.compat import Directive
|
||||
except ImportError:
|
||||
from docutils.parsers.rst import Directive
|
||||
|
||||
CONTROL_HEIGHT = 30
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
===========================
|
||||
Salt 2017.7.6 Release Notes
|
||||
In Progress: Salt 2017.7.6 Release Notes
|
||||
===========================
|
||||
|
||||
Version 2017.7.6 is a bugfix release for :ref:`2017.7.0 <release-2017-7-0>`.
|
||||
Version 2017.7.6 is an **unreleased** bugfix release for :ref:`2017.7.0 <release-2017-7-0>`.
|
||||
This release is still in progress and has not been released yet.
|
||||
|
||||
Option to Return to Previous Pillar Include Behavior
|
||||
----------------------------------------------------
|
||||
|
|
|
@ -35,7 +35,7 @@ Function Get-Settings {
|
|||
|
||||
# Prerequisite software
|
||||
$Prerequisites = @{
|
||||
"NSIS" = "nsis-3.0b1-setup.exe"
|
||||
"NSIS" = "nsis-3.03-setup.exe"
|
||||
"VCforPython" = "VCForPython27.msi"
|
||||
"VCppBuildTools" = "visualcppbuildtools_full.exe"
|
||||
}
|
||||
|
@ -59,21 +59,15 @@ Function Get-Settings {
|
|||
|
||||
# Filenames for 64 bit Windows
|
||||
$64bitPrograms = @{
|
||||
"PyCrypto2" = "pycrypto-2.6.1-cp27-none-win_amd64.whl"
|
||||
"Python2" = "python-2.7.13.amd64.msi"
|
||||
"PyYAML2" = "PyYAML-3.11.win-amd64-py2.7.exe"
|
||||
"Python3" = "python-3.5.3-amd64.exe"
|
||||
"PyWin323" = "pywin32-220.1-cp35-cp35m-win_amd64.whl"
|
||||
}
|
||||
$ini.Add("64bitPrograms", $64bitPrograms)
|
||||
|
||||
# Filenames for 32 bit Windows
|
||||
$32bitPrograms = @{
|
||||
"PyCrypto2" = "pycrypto-2.6.1-cp27-none-win32.whl"
|
||||
"Python2" = "python-2.7.13.msi"
|
||||
"PyYAML2" = "PyYAML-3.11.win32-py2.7.exe"
|
||||
"Python3" = "python-3.5.3.exe"
|
||||
"PyWin323" = "pywin32-220.1-cp35-cp35m-win32.whl"
|
||||
}
|
||||
$ini.Add("32bitPrograms", $32bitPrograms)
|
||||
|
||||
|
|
4
requirements/base-py2.txt
Normal file
4
requirements/base-py2.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
-r base.txt
|
||||
|
||||
# Required by Tornado to handle threads stuff.
|
||||
futures>=2.0
|
1
requirements/base-py3.txt
Normal file
1
requirements/base-py3.txt
Normal file
|
@ -0,0 +1 @@
|
|||
-r base.txt
|
|
@ -47,11 +47,6 @@ from salt.exceptions import (
|
|||
# Import third party libs
|
||||
import salt.ext.six as six
|
||||
# pylint: disable=import-error
|
||||
try:
|
||||
import zmq
|
||||
HAS_ZMQ = True
|
||||
except ImportError:
|
||||
HAS_ZMQ = False
|
||||
|
||||
# Try to import range from https://github.com/ytoolshed/range
|
||||
HAS_RANGE = False
|
||||
|
|
|
@ -56,11 +56,7 @@ try:
|
|||
HAS_WINSHELL = True
|
||||
except ImportError:
|
||||
HAS_WINSHELL = False
|
||||
try:
|
||||
import zmq
|
||||
HAS_ZMQ = True
|
||||
except ImportError:
|
||||
HAS_ZMQ = False
|
||||
from salt.utils.zeromq import zmq
|
||||
|
||||
# The directory where salt thin is deployed
|
||||
DEFAULT_THIN_DIR = '/var/tmp/.%%USER%%_%%FQDNUUID%%_salt'
|
||||
|
@ -207,7 +203,7 @@ class SSH(object):
|
|||
'''
|
||||
def __init__(self, opts):
|
||||
pull_sock = os.path.join(opts['sock_dir'], 'master_event_pull.ipc')
|
||||
if os.path.isfile(pull_sock) and HAS_ZMQ:
|
||||
if os.path.exists(pull_sock) and zmq:
|
||||
self.event = salt.utils.event.get_event(
|
||||
'master',
|
||||
opts['sock_dir'],
|
||||
|
|
|
@ -15,15 +15,12 @@ import errno
|
|||
# Import ioflo libs
|
||||
import ioflo.base.deeding
|
||||
# Import third party libs
|
||||
try:
|
||||
import zmq
|
||||
import salt.master
|
||||
import salt.crypt
|
||||
import salt.daemons.masterapi
|
||||
import salt.payload
|
||||
HAS_ZMQ = True
|
||||
except ImportError:
|
||||
HAS_ZMQ = False
|
||||
from salt.utils.zeromq import zmq
|
||||
import salt.master
|
||||
import salt.crypt
|
||||
import salt.daemons.masterapi
|
||||
import salt.payload
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -159,7 +156,7 @@ class SaltZmqPublisher(ioflo.base.deeding.Deed):
|
|||
'''
|
||||
Set up tracking value(s)
|
||||
'''
|
||||
if not HAS_ZMQ:
|
||||
if not zmq:
|
||||
return
|
||||
self.created = False
|
||||
self.serial = salt.payload.Serial(self.opts.value)
|
||||
|
|
|
@ -173,11 +173,7 @@ from __future__ import absolute_import
|
|||
import logging
|
||||
|
||||
# Import third party libraries
|
||||
try:
|
||||
import zmq
|
||||
HAS_ZMQ = True
|
||||
except ImportError:
|
||||
HAS_ZMQ = False
|
||||
from salt.utils.zeromq import zmq
|
||||
|
||||
try:
|
||||
# pylint: disable=W0611
|
||||
|
@ -209,7 +205,7 @@ def __virtual__():
|
|||
'''
|
||||
Load only if napalm-logs is installed.
|
||||
'''
|
||||
if not HAS_NAPALM_LOGS or not HAS_ZMQ:
|
||||
if not HAS_NAPALM_LOGS or not zmq:
|
||||
return (False, 'napalm_syslog could not be loaded. \
|
||||
Please install napalm-logs library amd ZeroMQ.')
|
||||
return True
|
||||
|
|
|
@ -28,23 +28,9 @@ except ImportError:
|
|||
# pylint: disable=import-error,no-name-in-module,redefined-builtin
|
||||
import salt.ext.six as six
|
||||
from salt.ext.six.moves import range
|
||||
from salt.utils.zeromq import zmq, ZMQDefaultLoop, install_zmq, ZMQ_VERSION_INFO
|
||||
# pylint: enable=import-error,no-name-in-module,redefined-builtin
|
||||
|
||||
try:
|
||||
import zmq
|
||||
import zmq.eventloop.ioloop
|
||||
# support pyzmq 13.0.x, TODO: remove once we force people to 14.0.x
|
||||
if not hasattr(zmq.eventloop.ioloop, 'ZMQIOLoop'):
|
||||
zmq.eventloop.ioloop.ZMQIOLoop = zmq.eventloop.ioloop.IOLoop
|
||||
HAS_ZMQ = True
|
||||
except ImportError:
|
||||
HAS_ZMQ = False
|
||||
|
||||
import tornado
|
||||
TORNADO_50 = tornado.version_info >= (5,)
|
||||
|
||||
from salt.utils.async import LOOP_CLASS
|
||||
|
||||
import tornado.gen # pylint: disable=F0401
|
||||
|
||||
# Import salt libs
|
||||
|
@ -378,23 +364,13 @@ class Master(SMaster):
|
|||
|
||||
:param dict: The salt options
|
||||
'''
|
||||
if HAS_ZMQ:
|
||||
# Warn if ZMQ < 3.2
|
||||
try:
|
||||
zmq_version_info = zmq.zmq_version_info()
|
||||
except AttributeError:
|
||||
# PyZMQ <= 2.1.9 does not have zmq_version_info, fall back to
|
||||
# using zmq.zmq_version() and build a version info tuple.
|
||||
zmq_version_info = tuple(
|
||||
[int(x) for x in zmq.zmq_version().split('.')]
|
||||
)
|
||||
if zmq_version_info < (3, 2):
|
||||
log.warning(
|
||||
'You have a version of ZMQ less than ZMQ 3.2! There are '
|
||||
'known connection keep-alive issues with ZMQ < 3.2 which '
|
||||
'may result in loss of contact with minions. Please '
|
||||
'upgrade your ZMQ!'
|
||||
)
|
||||
if zmq and ZMQ_VERSION_INFO < (3, 2):
|
||||
log.warning(
|
||||
'You have a version of ZMQ less than ZMQ 3.2! There are '
|
||||
'known connection keep-alive issues with ZMQ < 3.2 which '
|
||||
'may result in loss of contact with minions. Please '
|
||||
'upgrade your ZMQ!'
|
||||
)
|
||||
SMaster.__init__(self, opts)
|
||||
|
||||
def __set_max_open_files(self):
|
||||
|
@ -858,9 +834,8 @@ class MWorker(SignalHandlingMultiprocessingProcess):
|
|||
Bind to the local port
|
||||
'''
|
||||
# using ZMQIOLoop since we *might* need zmq in there
|
||||
if HAS_ZMQ and not TORNADO_50:
|
||||
zmq.eventloop.ioloop.install()
|
||||
self.io_loop = LOOP_CLASS()
|
||||
install_zmq()
|
||||
self.io_loop = ZMQDefaultLoop()
|
||||
self.io_loop.make_current()
|
||||
for req_channel in self.req_channels:
|
||||
req_channel.post_fork(self._handle_payload, io_loop=self.io_loop) # TODO: cleaner? Maybe lazily?
|
||||
|
|
|
@ -30,23 +30,10 @@ if six.PY3:
|
|||
else:
|
||||
import salt.ext.ipaddress as ipaddress
|
||||
from salt.ext.six.moves import range
|
||||
from salt.utils.zeromq import zmq, ZMQDefaultLoop, install_zmq, ZMQ_VERSION_INFO
|
||||
|
||||
# pylint: enable=no-name-in-module,redefined-builtin
|
||||
from salt.utils.async import LOOP_CLASS
|
||||
|
||||
# Import third party libs
|
||||
try:
|
||||
import zmq
|
||||
# TODO: cleanup
|
||||
import zmq.eventloop.ioloop
|
||||
# support pyzmq 13.0.x, TODO: remove once we force people to 14.0.x
|
||||
if not hasattr(zmq.eventloop.ioloop, 'ZMQIOLoop'):
|
||||
zmq.eventloop.ioloop.ZMQIOLoop = zmq.eventloop.ioloop.IOLoop
|
||||
HAS_ZMQ = True
|
||||
except ImportError:
|
||||
HAS_ZMQ = False
|
||||
|
||||
import tornado
|
||||
TORNADO_50 = tornado.version_info >= (5,)
|
||||
|
||||
HAS_RANGE = False
|
||||
try:
|
||||
|
@ -620,7 +607,7 @@ class MinionBase(object):
|
|||
if self.opts['transport'] == 'detect':
|
||||
self.opts['detect_mode'] = True
|
||||
for trans in ('zeromq', 'tcp'):
|
||||
if trans == 'zeromq' and not HAS_ZMQ:
|
||||
if trans == 'zeromq' and not zmq:
|
||||
continue
|
||||
self.opts['transport'] = trans
|
||||
pub_channel = salt.transport.client.AsyncPubChannel.factory(self.opts, **factory_kwargs)
|
||||
|
@ -657,10 +644,8 @@ class SMinion(MinionBase):
|
|||
# Clean out the proc directory (default /var/cache/salt/minion/proc)
|
||||
if (self.opts.get('file_client', 'remote') == 'remote'
|
||||
or self.opts.get('use_master_when_local', False)):
|
||||
if self.opts['transport'] == 'zeromq' and HAS_ZMQ and not TORNADO_50:
|
||||
io_loop = zmq.eventloop.ioloop.ZMQIOLoop()
|
||||
else:
|
||||
io_loop = LOOP_CLASS.current()
|
||||
install_zmq()
|
||||
io_loop = ZMQDefaultLoop.current()
|
||||
io_loop.run_sync(
|
||||
lambda: self.eval_master(self.opts, failed=True)
|
||||
)
|
||||
|
@ -806,9 +791,8 @@ class MinionManager(MinionBase):
|
|||
self.minions = []
|
||||
self.jid_queue = []
|
||||
|
||||
if HAS_ZMQ and not TORNADO_50:
|
||||
zmq.eventloop.ioloop.install()
|
||||
self.io_loop = LOOP_CLASS.current()
|
||||
install_zmq()
|
||||
self.io_loop = ZMQDefaultLoop.current()
|
||||
self.process_manager = ProcessManager(name='MultiMinionProcessManager')
|
||||
self.io_loop.spawn_callback(self.process_manager.run, async=True)
|
||||
|
||||
|
@ -955,23 +939,14 @@ class Minion(MinionBase):
|
|||
self.periodic_callbacks = {}
|
||||
|
||||
if io_loop is None:
|
||||
if HAS_ZMQ and not TORNADO_50:
|
||||
zmq.eventloop.ioloop.install()
|
||||
self.io_loop = LOOP_CLASS.current()
|
||||
install_zmq()
|
||||
self.io_loop = ZMQDefaultLoop.current()
|
||||
else:
|
||||
self.io_loop = io_loop
|
||||
|
||||
# Warn if ZMQ < 3.2
|
||||
if HAS_ZMQ:
|
||||
try:
|
||||
zmq_version_info = zmq.zmq_version_info()
|
||||
except AttributeError:
|
||||
# PyZMQ <= 2.1.9 does not have zmq_version_info, fall back to
|
||||
# using zmq.zmq_version() and build a version info tuple.
|
||||
zmq_version_info = tuple(
|
||||
[int(x) for x in zmq.zmq_version().split('.')] # pylint: disable=no-member
|
||||
)
|
||||
if zmq_version_info < (3, 2):
|
||||
if zmq:
|
||||
if ZMQ_VERSION_INFO < (3, 2):
|
||||
log.warning(
|
||||
'You have a version of ZMQ less than ZMQ 3.2! There are '
|
||||
'known connection keep-alive issues with ZMQ < 3.2 which '
|
||||
|
@ -2636,9 +2611,8 @@ class SyndicManager(MinionBase):
|
|||
self.jid_forward_cache = set()
|
||||
|
||||
if io_loop is None:
|
||||
if HAS_ZMQ and not TORNADO_50:
|
||||
zmq.eventloop.ioloop.install()
|
||||
self.io_loop = LOOP_CLASS.current()
|
||||
install_zmq()
|
||||
self.io_loop = ZMQDefaultLoop.current()
|
||||
else:
|
||||
self.io_loop = io_loop
|
||||
|
||||
|
|
|
@ -2302,10 +2302,10 @@ def create_route(route_table_id=None, destination_cidr_block=None,
|
|||
'must be provided.')
|
||||
|
||||
if not _exactly_one((gateway_id, internet_gateway_name, instance_id, interface_id, vpc_peering_connection_id,
|
||||
nat_gateway_id, nat_gateway_subnet_id, nat_gateway_subnet_name)):
|
||||
nat_gateway_id, nat_gateway_subnet_id, nat_gateway_subnet_name, vpc_peering_connection_name)):
|
||||
raise SaltInvocationError('Only one of gateway_id, internet_gateway_name, instance_id, '
|
||||
'interface_id, vpc_peering_connection_id, nat_gateway_id, '
|
||||
'nat_gateway_subnet_id or nat_gateway_subnet_name may be provided.')
|
||||
'nat_gateway_subnet_id, nat_gateway_subnet_name or vpc_peering_connection_name may be provided.')
|
||||
|
||||
if destination_cidr_block is None:
|
||||
raise SaltInvocationError('destination_cidr_block is required.')
|
||||
|
|
|
@ -28,6 +28,7 @@ import salt.utils
|
|||
import salt.utils.files
|
||||
import salt.utils.powershell
|
||||
import salt.utils.timed_subprocess
|
||||
import salt.utils.win_dacl
|
||||
import salt.grains.extra
|
||||
import salt.ext.six as six
|
||||
from salt.utils import vt
|
||||
|
@ -2071,11 +2072,14 @@ def script(source,
|
|||
)
|
||||
kwargs.pop('__env__')
|
||||
|
||||
win_cwd = False
|
||||
if salt.utils.is_windows() and runas and cwd is None:
|
||||
# Create a temp working directory
|
||||
cwd = tempfile.mkdtemp(dir=__opts__['cachedir'])
|
||||
__salt__['win_dacl.add_ace'](
|
||||
cwd, 'File', runas, 'READ&EXECUTE', 'ALLOW',
|
||||
'FOLDER&SUBFOLDERS&FILES')
|
||||
win_cwd = True
|
||||
salt.utils.win_dacl.set_permissions(obj_name=cwd,
|
||||
principal=runas,
|
||||
permissions='full_control')
|
||||
|
||||
path = salt.utils.files.mkstemp(dir=cwd, suffix=os.path.splitext(source)[1])
|
||||
|
||||
|
@ -2089,10 +2093,10 @@ def script(source,
|
|||
saltenv,
|
||||
**kwargs)
|
||||
if not fn_:
|
||||
if salt.utils.is_windows() and runas:
|
||||
_cleanup_tempfile(path)
|
||||
# If a temp working directory was created (Windows), let's remove that
|
||||
if win_cwd:
|
||||
_cleanup_tempfile(cwd)
|
||||
else:
|
||||
_cleanup_tempfile(path)
|
||||
return {'pid': 0,
|
||||
'retcode': 1,
|
||||
'stdout': '',
|
||||
|
@ -2101,10 +2105,10 @@ def script(source,
|
|||
else:
|
||||
fn_ = __salt__['cp.cache_file'](source, saltenv)
|
||||
if not fn_:
|
||||
if salt.utils.is_windows() and runas:
|
||||
_cleanup_tempfile(path)
|
||||
# If a temp working directory was created (Windows), let's remove that
|
||||
if win_cwd:
|
||||
_cleanup_tempfile(cwd)
|
||||
else:
|
||||
_cleanup_tempfile(path)
|
||||
return {'pid': 0,
|
||||
'retcode': 1,
|
||||
'stdout': '',
|
||||
|
@ -2134,10 +2138,10 @@ def script(source,
|
|||
bg=bg,
|
||||
password=password,
|
||||
**kwargs)
|
||||
if salt.utils.is_windows() and runas:
|
||||
_cleanup_tempfile(path)
|
||||
# If a temp working directory was created (Windows), let's remove that
|
||||
if win_cwd:
|
||||
_cleanup_tempfile(cwd)
|
||||
else:
|
||||
_cleanup_tempfile(path)
|
||||
return ret
|
||||
|
||||
|
||||
|
|
|
@ -77,6 +77,7 @@ of the 2015.5 branch:
|
|||
from __future__ import absolute_import
|
||||
|
||||
# Import python libs
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
|
@ -114,43 +115,82 @@ def __virtual__():
|
|||
return 'pip'
|
||||
|
||||
|
||||
def _clear_context(bin_env=None):
|
||||
'''
|
||||
Remove the cached pip version
|
||||
'''
|
||||
contextkey = 'pip.version'
|
||||
if bin_env is not None:
|
||||
contextkey = '{0}.{1}'.format(contextkey, bin_env)
|
||||
__context__.pop(contextkey, None)
|
||||
|
||||
|
||||
def _get_pip_bin(bin_env):
|
||||
'''
|
||||
Locate the pip binary, either from `bin_env` as a virtualenv, as the
|
||||
executable itself, or from searching conventional filesystem locations
|
||||
'''
|
||||
if not bin_env:
|
||||
which_result = __salt__['cmd.which_bin'](
|
||||
['pip{0}.{1}'.format(*sys.version_info[:2]),
|
||||
'pip{0}'.format(sys.version_info[0]),
|
||||
'pip', 'pip-python']
|
||||
)
|
||||
if salt.utils.is_windows() and six.PY2:
|
||||
which_result.encode('string-escape')
|
||||
if which_result is None:
|
||||
raise CommandNotFoundError('Could not find a `pip` binary')
|
||||
return which_result
|
||||
logger.debug('pip: Using pip from currently-running Python')
|
||||
return [os.path.normpath(sys.executable), '-m', 'pip']
|
||||
|
||||
# try to get python bin from virtualenv, bin_env
|
||||
python_bin = 'python.exe' if salt.utils.is_windows() else 'python'
|
||||
|
||||
def _search_paths(*basedirs):
|
||||
ret = []
|
||||
for path in basedirs:
|
||||
ret.extend([
|
||||
os.path.join(path, python_bin),
|
||||
os.path.join(path, 'bin', python_bin),
|
||||
os.path.join(path, 'Scripts', python_bin)
|
||||
])
|
||||
return ret
|
||||
|
||||
# try to get pip bin from virtualenv, bin_env
|
||||
if os.path.isdir(bin_env):
|
||||
if salt.utils.is_windows():
|
||||
if six.PY2:
|
||||
pip_bin = os.path.join(
|
||||
bin_env, 'Scripts', 'pip.exe').encode('string-escape')
|
||||
else:
|
||||
pip_bin = os.path.join(bin_env, 'Scripts', 'pip.exe')
|
||||
else:
|
||||
pip_bin = os.path.join(bin_env, 'bin', 'pip')
|
||||
if os.path.isfile(pip_bin):
|
||||
return pip_bin
|
||||
msg = 'Could not find a `pip` binary in virtualenv {0}'.format(bin_env)
|
||||
raise CommandNotFoundError(msg)
|
||||
# bin_env is the pip binary
|
||||
for bin_path in _search_paths(bin_env):
|
||||
if os.path.isfile(bin_path):
|
||||
if os.access(bin_path, os.X_OK):
|
||||
logger.debug('pip: Found python binary: %s', bin_path)
|
||||
return [os.path.normpath(bin_path), '-m', 'pip']
|
||||
else:
|
||||
logger.debug(
|
||||
'pip: Found python binary by name but it is not '
|
||||
'executable: %s', bin_path
|
||||
)
|
||||
raise CommandNotFoundError(
|
||||
'Could not find a pip binary in virtualenv {0}'.format(bin_env)
|
||||
)
|
||||
|
||||
# bin_env is the python or pip binary
|
||||
elif os.access(bin_env, os.X_OK):
|
||||
if os.path.isfile(bin_env) or os.path.islink(bin_env):
|
||||
return bin_env
|
||||
if os.path.isfile(bin_env):
|
||||
# If the python binary was passed, return it
|
||||
if 'python' in os.path.basename(bin_env):
|
||||
return [os.path.normpath(bin_env), '-m', 'pip']
|
||||
# Try to find the python binary based on the location of pip in a
|
||||
# virtual environment, should be relative
|
||||
if 'pip' in os.path.basename(bin_env):
|
||||
# Look in the same directory as the pip binary, and also its
|
||||
# parent directories.
|
||||
pip_dirname = os.path.dirname(bin_env)
|
||||
pip_parent_dir = os.path.dirname(pip_dirname)
|
||||
for bin_path in _search_paths(pip_dirname, pip_parent_dir):
|
||||
if os.path.isfile(bin_path):
|
||||
logger.debug('pip: Found python binary: %s', bin_path)
|
||||
return [os.path.normpath(bin_path), '-m', 'pip']
|
||||
|
||||
# Couldn't find python, use the passed pip binary
|
||||
# This has the limitation of being unable to update pip itself
|
||||
return [os.path.normpath(bin_env)]
|
||||
|
||||
raise CommandExecutionError(
|
||||
'Could not find a pip binary within {0}'.format(bin_env)
|
||||
)
|
||||
else:
|
||||
raise CommandNotFoundError('Could not find a `pip` binary')
|
||||
raise CommandNotFoundError(
|
||||
'Access denied to {0}, could not find a pip binary'.format(bin_env)
|
||||
)
|
||||
|
||||
|
||||
def _get_cached_requirements(requirements, saltenv):
|
||||
|
@ -267,15 +307,21 @@ def _process_requirements(requirements, cmd, cwd, saltenv, user):
|
|||
treq = tempfile.mkdtemp()
|
||||
|
||||
__salt__['file.chown'](treq, user, None)
|
||||
# In Windows, just being owner of a file isn't enough. You also
|
||||
# need permissions
|
||||
if salt.utils.is_windows():
|
||||
__utils__['win_dacl.set_permissions'](
|
||||
obj_name=treq,
|
||||
principal=user,
|
||||
permissions='read_execute')
|
||||
|
||||
current_directory = None
|
||||
|
||||
if not current_directory:
|
||||
current_directory = os.path.abspath(os.curdir)
|
||||
|
||||
logger.info('_process_requirements from directory,' +
|
||||
'%s -- requirement: %s', cwd, requirement
|
||||
)
|
||||
logger.info('_process_requirements from directory, '
|
||||
'%s -- requirement: %s', cwd, requirement)
|
||||
|
||||
if cwd is None:
|
||||
r = requirement
|
||||
|
@ -378,7 +424,6 @@ def install(pkgs=None, # pylint: disable=R0912,R0913,R0914
|
|||
global_options=None,
|
||||
install_options=None,
|
||||
user=None,
|
||||
no_chown=False,
|
||||
cwd=None,
|
||||
pre_releases=False,
|
||||
cert=None,
|
||||
|
@ -392,7 +437,8 @@ def install(pkgs=None, # pylint: disable=R0912,R0913,R0914
|
|||
trusted_host=None,
|
||||
no_cache_dir=False,
|
||||
cache_dir=None,
|
||||
no_binary=None):
|
||||
no_binary=None,
|
||||
**kwargs):
|
||||
'''
|
||||
Install packages with pip
|
||||
|
||||
|
@ -514,10 +560,6 @@ def install(pkgs=None, # pylint: disable=R0912,R0913,R0914
|
|||
user
|
||||
The user under which to run pip
|
||||
|
||||
no_chown
|
||||
When user is given, do not attempt to copy and chown a requirements
|
||||
file
|
||||
|
||||
cwd
|
||||
Current working directory to run pip from
|
||||
|
||||
|
@ -578,9 +620,14 @@ def install(pkgs=None, # pylint: disable=R0912,R0913,R0914
|
|||
editable=git+https://github.com/worldcompany/djangoembed.git#egg=djangoembed upgrade=True no_deps=True
|
||||
|
||||
'''
|
||||
pip_bin = _get_pip_bin(bin_env)
|
||||
|
||||
cmd = [pip_bin, 'install']
|
||||
if 'no_chown' in kwargs:
|
||||
salt.utils.warn_until(
|
||||
'Flourine',
|
||||
'The no_chown argument has been deprecated and is no longer used. '
|
||||
'Its functionality was removed in Boron.')
|
||||
kwargs.pop('no_chown')
|
||||
cmd = _get_pip_bin(bin_env)
|
||||
cmd.append('install')
|
||||
|
||||
cleanup_requirements, error = _process_requirements(
|
||||
requirements=requirements,
|
||||
|
@ -593,10 +640,11 @@ def install(pkgs=None, # pylint: disable=R0912,R0913,R0914
|
|||
if error:
|
||||
return error
|
||||
|
||||
cur_version = version(bin_env)
|
||||
|
||||
if use_wheel:
|
||||
min_version = '1.4'
|
||||
max_version = '9.0.3'
|
||||
cur_version = __salt__['pip.version'](bin_env)
|
||||
too_low = salt.utils.compare_versions(ver1=cur_version, oper='<', ver2=min_version)
|
||||
too_high = salt.utils.compare_versions(ver1=cur_version, oper='>', ver2=max_version)
|
||||
if too_low or too_high:
|
||||
|
@ -611,7 +659,6 @@ def install(pkgs=None, # pylint: disable=R0912,R0913,R0914
|
|||
if no_use_wheel:
|
||||
min_version = '1.4'
|
||||
max_version = '9.0.3'
|
||||
cur_version = __salt__['pip.version'](bin_env)
|
||||
too_low = salt.utils.compare_versions(ver1=cur_version, oper='<', ver2=min_version)
|
||||
too_high = salt.utils.compare_versions(ver1=cur_version, oper='>', ver2=max_version)
|
||||
if too_low or too_high:
|
||||
|
@ -625,7 +672,6 @@ def install(pkgs=None, # pylint: disable=R0912,R0913,R0914
|
|||
|
||||
if no_binary:
|
||||
min_version = '7.0.0'
|
||||
cur_version = __salt__['pip.version'](bin_env)
|
||||
too_low = salt.utils.compare_versions(ver1=cur_version, oper='<', ver2=min_version)
|
||||
if too_low:
|
||||
logger.error(
|
||||
|
@ -700,8 +746,7 @@ def install(pkgs=None, # pylint: disable=R0912,R0913,R0914
|
|||
|
||||
if mirrors:
|
||||
# https://github.com/pypa/pip/pull/2641/files#diff-3ef137fb9ffdd400f117a565cd94c188L216
|
||||
pip_version = version(pip_bin)
|
||||
if salt.utils.compare_versions(ver1=pip_version, oper='>=', ver2='7.0.0'):
|
||||
if salt.utils.compare_versions(ver1=cur_version, oper='>=', ver2='7.0.0'):
|
||||
raise CommandExecutionError(
|
||||
'pip >= 7.0.0 does not support mirror argument:'
|
||||
' use index_url and/or extra_index_url instead'
|
||||
|
@ -729,7 +774,7 @@ def install(pkgs=None, # pylint: disable=R0912,R0913,R0914
|
|||
|
||||
if download_cache or cache_dir:
|
||||
cmd.extend(['--cache-dir' if salt.utils.compare_versions(
|
||||
ver1=version(bin_env), oper='>=', ver2='6.0'
|
||||
ver1=cur_version, oper='>=', ver2='6.0'
|
||||
) else '--download-cache', download_cache or cache_dir])
|
||||
|
||||
if source:
|
||||
|
@ -766,7 +811,7 @@ def install(pkgs=None, # pylint: disable=R0912,R0913,R0914
|
|||
|
||||
if pre_releases:
|
||||
# Check the locally installed pip version
|
||||
pip_version = version(pip_bin)
|
||||
pip_version = cur_version
|
||||
|
||||
# From pip v1.4 the --pre flag is available
|
||||
if salt.utils.compare_versions(ver1=pip_version, oper='>=', ver2='1.4'):
|
||||
|
@ -847,6 +892,9 @@ def install(pkgs=None, # pylint: disable=R0912,R0913,R0914
|
|||
|
||||
cmd_kwargs = dict(saltenv=saltenv, use_vt=use_vt, runas=user)
|
||||
|
||||
if kwargs:
|
||||
cmd_kwargs.update(kwargs)
|
||||
|
||||
if env_vars:
|
||||
cmd_kwargs.setdefault('env', {}).update(_format_env_vars(env_vars))
|
||||
|
||||
|
@ -866,6 +914,7 @@ def install(pkgs=None, # pylint: disable=R0912,R0913,R0914
|
|||
python_shell=False,
|
||||
**cmd_kwargs)
|
||||
finally:
|
||||
_clear_context(bin_env)
|
||||
for tempdir in [cr for cr in cleanup_requirements if cr is not None]:
|
||||
if os.path.isdir(tempdir):
|
||||
shutil.rmtree(tempdir)
|
||||
|
@ -878,7 +927,6 @@ def uninstall(pkgs=None,
|
|||
proxy=None,
|
||||
timeout=None,
|
||||
user=None,
|
||||
no_chown=False,
|
||||
cwd=None,
|
||||
saltenv='base',
|
||||
use_vt=False):
|
||||
|
@ -911,11 +959,6 @@ def uninstall(pkgs=None,
|
|||
Set the socket timeout (default 15 seconds)
|
||||
user
|
||||
The user under which to run pip
|
||||
no_chown
|
||||
When user is given, do not attempt to copy and chown
|
||||
a requirements file (needed if the requirements file refers to other
|
||||
files via relative paths, as the copy-and-chown procedure does not
|
||||
account for such files)
|
||||
cwd
|
||||
Current working directory to run pip from
|
||||
use_vt
|
||||
|
@ -931,9 +974,8 @@ def uninstall(pkgs=None,
|
|||
salt '*' pip.uninstall <package name> bin_env=/path/to/pip_bin
|
||||
|
||||
'''
|
||||
pip_bin = _get_pip_bin(bin_env)
|
||||
|
||||
cmd = [pip_bin, 'uninstall', '-y']
|
||||
cmd = _get_pip_bin(bin_env)
|
||||
cmd.extend(['uninstall', '-y'])
|
||||
|
||||
cleanup_requirements, error = _process_requirements(
|
||||
requirements=requirements, cmd=cmd, saltenv=saltenv, user=user,
|
||||
|
@ -992,6 +1034,7 @@ def uninstall(pkgs=None,
|
|||
try:
|
||||
return __salt__['cmd.run_all'](cmd, **cmd_kwargs)
|
||||
finally:
|
||||
_clear_context(bin_env)
|
||||
for requirement in cleanup_requirements:
|
||||
if requirement:
|
||||
try:
|
||||
|
@ -1004,7 +1047,8 @@ def freeze(bin_env=None,
|
|||
user=None,
|
||||
cwd=None,
|
||||
use_vt=False,
|
||||
env_vars=None):
|
||||
env_vars=None,
|
||||
**kwargs):
|
||||
'''
|
||||
Return a list of installed packages either globally or in the specified
|
||||
virtualenv
|
||||
|
@ -1037,15 +1081,13 @@ def freeze(bin_env=None,
|
|||
The packages pip, wheel, setuptools, and distribute are included if the
|
||||
installed pip is new enough.
|
||||
'''
|
||||
pip_bin = _get_pip_bin(bin_env)
|
||||
|
||||
cmd = [pip_bin, 'freeze']
|
||||
cmd = _get_pip_bin(bin_env)
|
||||
cmd.append('freeze')
|
||||
|
||||
# Include pip, setuptools, distribute, wheel
|
||||
min_version = '8.0.3'
|
||||
cur_version = version(bin_env)
|
||||
if not salt.utils.compare_versions(ver1=cur_version, oper='>=',
|
||||
ver2=min_version):
|
||||
if salt.utils.compare_versions(ver1=cur_version, oper='<', ver2=min_version):
|
||||
logger.warning(
|
||||
('The version of pip installed is {0}, which is older than {1}. '
|
||||
'The packages pip, wheel, setuptools, and distribute will not be '
|
||||
|
@ -1055,14 +1097,16 @@ def freeze(bin_env=None,
|
|||
cmd.append('--all')
|
||||
|
||||
cmd_kwargs = dict(runas=user, cwd=cwd, use_vt=use_vt, python_shell=False)
|
||||
if kwargs:
|
||||
cmd_kwargs.update(**kwargs)
|
||||
if bin_env and os.path.isdir(bin_env):
|
||||
cmd_kwargs['env'] = {'VIRTUAL_ENV': bin_env}
|
||||
if env_vars:
|
||||
cmd_kwargs.setdefault('env', {}).update(_format_env_vars(env_vars))
|
||||
result = __salt__['cmd.run_all'](cmd, **cmd_kwargs)
|
||||
|
||||
if result['retcode'] > 0:
|
||||
raise CommandExecutionError(result['stderr'])
|
||||
if result['retcode']:
|
||||
raise CommandExecutionError(result['stderr'], info=result)
|
||||
|
||||
return result['stdout'].splitlines()
|
||||
|
||||
|
@ -1071,7 +1115,8 @@ def list_(prefix=None,
|
|||
bin_env=None,
|
||||
user=None,
|
||||
cwd=None,
|
||||
env_vars=None):
|
||||
env_vars=None,
|
||||
**kwargs):
|
||||
'''
|
||||
Filter list of installed apps from ``freeze`` and check to see if
|
||||
``prefix`` exists in the list of packages installed.
|
||||
|
@ -1100,7 +1145,11 @@ def list_(prefix=None,
|
|||
if prefix is None or 'pip'.startswith(prefix):
|
||||
packages['pip'] = version(bin_env)
|
||||
|
||||
for line in freeze(bin_env=bin_env, user=user, cwd=cwd, env_vars=env_vars):
|
||||
for line in freeze(bin_env=bin_env,
|
||||
user=user,
|
||||
cwd=cwd,
|
||||
env_vars=env_vars,
|
||||
**kwargs):
|
||||
if line.startswith('-f') or line.startswith('#'):
|
||||
# ignore -f line as it contains --find-links directory
|
||||
# ignore comment lines
|
||||
|
@ -1110,7 +1159,15 @@ def list_(prefix=None,
|
|||
continue
|
||||
elif line.startswith('-e'):
|
||||
line = line.split('-e ')[1]
|
||||
version_, name = line.split('#egg=')
|
||||
if '#egg=' in line:
|
||||
version_, name = line.split('#egg=')
|
||||
else:
|
||||
if len(line.split('===')) >= 2:
|
||||
name = line.split('===')[0]
|
||||
version_ = line.split('===')[1]
|
||||
elif len(line.split('==')) >= 2:
|
||||
name = line.split('==')[0]
|
||||
version_ = line.split('==')[1]
|
||||
elif len(line.split('===')) >= 2:
|
||||
name = line.split('===')[0]
|
||||
version_ = line.split('===')[1]
|
||||
|
@ -1145,14 +1202,27 @@ def version(bin_env=None):
|
|||
|
||||
salt '*' pip.version
|
||||
'''
|
||||
pip_bin = _get_pip_bin(bin_env)
|
||||
contextkey = 'pip.version'
|
||||
if bin_env is not None:
|
||||
contextkey = '{0}.{1}'.format(contextkey, bin_env)
|
||||
|
||||
if contextkey in __context__:
|
||||
return __context__[contextkey]
|
||||
|
||||
cmd = _get_pip_bin(bin_env)[:]
|
||||
cmd.append('--version')
|
||||
|
||||
ret = __salt__['cmd.run_all'](cmd, python_shell=False)
|
||||
if ret['retcode']:
|
||||
raise CommandNotFoundError('Could not find a `pip` binary')
|
||||
|
||||
output = __salt__['cmd.run'](
|
||||
'{0} --version'.format(pip_bin), python_shell=False)
|
||||
try:
|
||||
return re.match(r'^pip (\S+)', output).group(1)
|
||||
pip_version = re.match(r'^pip (\S+)', ret['stdout']).group(1)
|
||||
except AttributeError:
|
||||
return None
|
||||
pip_version = None
|
||||
|
||||
__context__[contextkey] = pip_version
|
||||
return pip_version
|
||||
|
||||
|
||||
def list_upgrades(bin_env=None,
|
||||
|
@ -1167,28 +1237,66 @@ def list_upgrades(bin_env=None,
|
|||
|
||||
salt '*' pip.list_upgrades
|
||||
'''
|
||||
pip_bin = _get_pip_bin(bin_env)
|
||||
cmd = _get_pip_bin(bin_env)
|
||||
cmd.extend(['list', '--outdated'])
|
||||
|
||||
cmd = [pip_bin, 'list', '--outdated']
|
||||
pip_version = version(bin_env)
|
||||
# Pip started supporting the ability to output json starting with 9.0.0
|
||||
if salt.utils.compare_versions(ver1=pip_version, oper='>=', ver2='9.0.0'):
|
||||
cmd.extend(['--format', 'json'])
|
||||
|
||||
cmd_kwargs = dict(cwd=cwd, runas=user)
|
||||
if bin_env and os.path.isdir(bin_env):
|
||||
cmd_kwargs['env'] = {'VIRTUAL_ENV': bin_env}
|
||||
|
||||
result = __salt__['cmd.run_all'](cmd, **cmd_kwargs)
|
||||
if result['retcode'] > 0:
|
||||
logger.error(result['stderr'])
|
||||
raise CommandExecutionError(result['stderr'])
|
||||
if result['retcode']:
|
||||
raise CommandExecutionError(result['stderr'], info=result)
|
||||
|
||||
packages = {}
|
||||
for line in result['stdout'].splitlines():
|
||||
match = re.search(r'(\S*)\s+\(.*Latest:\s+(.*)\)', line)
|
||||
if match:
|
||||
name, version_ = match.groups()
|
||||
# Pip started supporting the ability to output json starting with 9.0.0
|
||||
# Older versions will have to parse stdout
|
||||
if salt.utils.compare_versions(ver1=pip_version, oper='<', ver2='9.0.0'):
|
||||
# Pip versions < 8.0.0 had a different output format
|
||||
# Sample data:
|
||||
# pip (Current: 7.1.2 Latest: 10.0.1 [wheel])
|
||||
# psutil (Current: 5.2.2 Latest: 5.4.5 [wheel])
|
||||
# pyasn1 (Current: 0.2.3 Latest: 0.4.2 [wheel])
|
||||
# pycparser (Current: 2.17 Latest: 2.18 [sdist])
|
||||
if salt.utils.compare_versions(ver1=pip_version, oper='<', ver2='8.0.0'):
|
||||
logger.debug('pip module: Old output format')
|
||||
pat = re.compile(r'(\S*)\s+\(.*Latest:\s+(.*)\)')
|
||||
|
||||
# New output format for version 8.0.0+
|
||||
# Sample data:
|
||||
# pip (8.0.0) - Latest: 10.0.1 [wheel]
|
||||
# psutil (5.2.2) - Latest: 5.4.5 [wheel]
|
||||
# pyasn1 (0.2.3) - Latest: 0.4.2 [wheel]
|
||||
# pycparser (2.17) - Latest: 2.18 [sdist]
|
||||
else:
|
||||
logger.error('Can\'t parse line \'{0}\''.format(line))
|
||||
continue
|
||||
packages[name] = version_
|
||||
logger.debug('pip module: New output format')
|
||||
pat = re.compile(r'(\S*)\s+\(.*\)\s+-\s+Latest:\s+(.*)')
|
||||
|
||||
for line in result['stdout'].splitlines():
|
||||
match = pat.search(line)
|
||||
if match:
|
||||
name, version_ = match.groups()
|
||||
else:
|
||||
logger.error('Can\'t parse line \'{0}\''.format(line))
|
||||
continue
|
||||
packages[name] = version_
|
||||
|
||||
else:
|
||||
logger.debug('pip module: JSON output format')
|
||||
try:
|
||||
pkgs = json.loads(result['stdout'], strict=False)
|
||||
except ValueError:
|
||||
raise CommandExecutionError('Invalid JSON', info=result)
|
||||
|
||||
for pkg in pkgs:
|
||||
packages[pkg['name']] = '{0} [{1}]'.format(pkg['latest_version'],
|
||||
pkg['latest_filetype'])
|
||||
|
||||
return packages
|
||||
|
||||
|
||||
|
@ -1217,7 +1325,11 @@ def upgrade(bin_env=None,
|
|||
'''
|
||||
.. versionadded:: 2015.5.0
|
||||
|
||||
Upgrades outdated pip packages
|
||||
Upgrades outdated pip packages.
|
||||
|
||||
.. note::
|
||||
On Windows you can't update salt from pip using salt, so salt will be
|
||||
skipped
|
||||
|
||||
Returns a dict containing the changes.
|
||||
|
||||
|
@ -1235,16 +1347,19 @@ def upgrade(bin_env=None,
|
|||
'result': True,
|
||||
'comment': '',
|
||||
}
|
||||
pip_bin = _get_pip_bin(bin_env)
|
||||
cmd = _get_pip_bin(bin_env)
|
||||
cmd.extend(['install', '-U'])
|
||||
|
||||
old = list_(bin_env=bin_env, user=user, cwd=cwd)
|
||||
|
||||
cmd = [pip_bin, 'install', '-U']
|
||||
cmd_kwargs = dict(cwd=cwd, use_vt=use_vt)
|
||||
if bin_env and os.path.isdir(bin_env):
|
||||
cmd_kwargs['env'] = {'VIRTUAL_ENV': bin_env}
|
||||
errors = False
|
||||
for pkg in list_upgrades(bin_env=bin_env, user=user, cwd=cwd):
|
||||
if pkg == 'salt':
|
||||
if salt.utils.is_windows():
|
||||
continue
|
||||
result = __salt__['cmd.run_all'](cmd + [pkg], **cmd_kwargs)
|
||||
if result['retcode'] != 0:
|
||||
errors = True
|
||||
|
@ -1253,6 +1368,7 @@ def upgrade(bin_env=None,
|
|||
if errors:
|
||||
ret['result'] = False
|
||||
|
||||
_clear_context(bin_env)
|
||||
new = list_(bin_env=bin_env, user=user, cwd=cwd)
|
||||
|
||||
ret['changes'] = salt.utils.compare_dicts(old, new)
|
||||
|
@ -1301,9 +1417,8 @@ def list_all_versions(pkg,
|
|||
|
||||
salt '*' pip.list_all_versions <package name>
|
||||
'''
|
||||
pip_bin = _get_pip_bin(bin_env)
|
||||
|
||||
cmd = [pip_bin, 'install', '{0}==versions'.format(pkg)]
|
||||
cmd = _get_pip_bin(bin_env)
|
||||
cmd.extend(['install', '{0}==versions'.format(pkg)])
|
||||
|
||||
cmd_kwargs = dict(cwd=cwd, runas=user, output_loglevel='quiet', redirect_stderr=True)
|
||||
if bin_env and os.path.isdir(bin_env):
|
||||
|
|
|
@ -56,7 +56,8 @@ def create(path,
|
|||
upgrade=None,
|
||||
user=None,
|
||||
use_vt=False,
|
||||
saltenv='base'):
|
||||
saltenv='base',
|
||||
**kwargs):
|
||||
'''
|
||||
Create a virtualenv
|
||||
|
||||
|
@ -102,6 +103,11 @@ def create(path,
|
|||
user : None
|
||||
Set ownership for the virtualenv
|
||||
|
||||
.. note::
|
||||
On Windows you must also pass a ``password`` parameter. Additionally,
|
||||
the user must have permissions to the location where the virtual
|
||||
environment is being created
|
||||
|
||||
runas : None
|
||||
Set ownership for the virtualenv
|
||||
|
||||
|
@ -161,7 +167,7 @@ def create(path,
|
|||
# Unable to import?? Let's parse the version from the console
|
||||
version_cmd = [venv_bin, '--version']
|
||||
ret = __salt__['cmd.run_all'](
|
||||
version_cmd, runas=user, python_shell=False
|
||||
version_cmd, runas=user, python_shell=False, **kwargs
|
||||
)
|
||||
if ret['retcode'] > 0 or not ret['stdout'].strip():
|
||||
raise CommandExecutionError(
|
||||
|
@ -251,7 +257,7 @@ def create(path,
|
|||
cmd.append(path)
|
||||
|
||||
# Let's create the virtualenv
|
||||
ret = __salt__['cmd.run_all'](cmd, runas=user, python_shell=False)
|
||||
ret = __salt__['cmd.run_all'](cmd, runas=user, python_shell=False, **kwargs)
|
||||
if ret['retcode'] != 0:
|
||||
# Something went wrong. Let's bail out now!
|
||||
return ret
|
||||
|
|
|
@ -718,23 +718,24 @@ def set_lcm_config(config_mode=None,
|
|||
'ApplyAndAutoCorrect'):
|
||||
error = 'config_mode must be one of ApplyOnly, ApplyAndMonitor, ' \
|
||||
'or ApplyAndAutoCorrect. Passed {0}'.format(config_mode)
|
||||
SaltInvocationError(error)
|
||||
return error
|
||||
raise SaltInvocationError(error)
|
||||
cmd += ' ConfigurationMode = "{0}";'.format(config_mode)
|
||||
if config_mode_freq:
|
||||
if not isinstance(config_mode_freq, int):
|
||||
SaltInvocationError('config_mode_freq must be an integer')
|
||||
return 'config_mode_freq must be an integer. Passed {0}'.\
|
||||
format(config_mode_freq)
|
||||
error = 'config_mode_freq must be an integer. Passed {0}'.format(
|
||||
config_mode_freq
|
||||
)
|
||||
raise SaltInvocationError(error)
|
||||
cmd += ' ConfigurationModeFrequencyMins = {0};'.format(config_mode_freq)
|
||||
if refresh_mode:
|
||||
if refresh_mode not in ('Disabled', 'Push', 'Pull'):
|
||||
SaltInvocationError('refresh_mode must be one of Disabled, Push, '
|
||||
'or Pull')
|
||||
raise SaltInvocationError(
|
||||
'refresh_mode must be one of Disabled, Push, or Pull'
|
||||
)
|
||||
cmd += ' RefreshMode = "{0}";'.format(refresh_mode)
|
||||
if refresh_freq:
|
||||
if not isinstance(refresh_freq, int):
|
||||
SaltInvocationError('refresh_freq must be an integer')
|
||||
raise SaltInvocationError('refresh_freq must be an integer')
|
||||
cmd += ' RefreshFrequencyMins = {0};'.format(refresh_freq)
|
||||
if reboot_if_needed is not None:
|
||||
if not isinstance(reboot_if_needed, bool):
|
||||
|
@ -747,8 +748,10 @@ def set_lcm_config(config_mode=None,
|
|||
if action_after_reboot:
|
||||
if action_after_reboot not in ('ContinueConfiguration',
|
||||
'StopConfiguration'):
|
||||
SaltInvocationError('action_after_reboot must be one of '
|
||||
'ContinueConfiguration or StopConfiguration')
|
||||
raise SaltInvocationError(
|
||||
'action_after_reboot must be one of '
|
||||
'ContinueConfiguration or StopConfiguration'
|
||||
)
|
||||
cmd += ' ActionAfterReboot = "{0}"'.format(action_after_reboot)
|
||||
if certificate_id is not None:
|
||||
if certificate_id == '':
|
||||
|
@ -760,7 +763,7 @@ def set_lcm_config(config_mode=None,
|
|||
cmd += ' ConfigurationID = "{0}";'.format(configuration_id)
|
||||
if allow_module_overwrite is not None:
|
||||
if not isinstance(allow_module_overwrite, bool):
|
||||
SaltInvocationError('allow_module_overwrite must be a boolean value')
|
||||
raise SaltInvocationError('allow_module_overwrite must be a boolean value')
|
||||
if allow_module_overwrite:
|
||||
allow_module_overwrite = '$true'
|
||||
else:
|
||||
|
@ -770,13 +773,14 @@ def set_lcm_config(config_mode=None,
|
|||
if debug_mode is None:
|
||||
debug_mode = 'None'
|
||||
if debug_mode not in ('None', 'ForceModuleImport', 'All'):
|
||||
SaltInvocationError('debug_mode must be one of None, '
|
||||
'ForceModuleImport, ResourceScriptBreakAll, or '
|
||||
'All')
|
||||
raise SaltInvocationError(
|
||||
'debug_mode must be one of None, ForceModuleImport, '
|
||||
'ResourceScriptBreakAll, or All'
|
||||
)
|
||||
cmd += ' DebugMode = "{0}";'.format(debug_mode)
|
||||
if status_retention_days:
|
||||
if not isinstance(status_retention_days, int):
|
||||
SaltInvocationError('status_retention_days must be an integer')
|
||||
raise SaltInvocationError('status_retention_days must be an integer')
|
||||
cmd += ' StatusRetentionTimeInDays = {0};'.format(status_retention_days)
|
||||
cmd += ' }}};'
|
||||
cmd += r'SaltConfig -OutputPath "{0}\SaltConfig"'.format(temp_dir)
|
||||
|
|
|
@ -3679,7 +3679,7 @@ def _checkAllAdmxPolicies(policy_class,
|
|||
if ENABLED_VALUE_XPATH(admx_policy) and this_policy_setting == 'Not Configured':
|
||||
# some policies have a disabled list but not an enabled list
|
||||
# added this to address those issues
|
||||
if DISABLED_LIST_XPATH(admx_policy):
|
||||
if DISABLED_LIST_XPATH(admx_policy) or DISABLED_VALUE_XPATH(admx_policy):
|
||||
element_only_enabled_disabled = False
|
||||
explicit_enable_disable_value_setting = True
|
||||
if _checkValueItemParent(admx_policy,
|
||||
|
@ -3689,14 +3689,14 @@ def _checkAllAdmxPolicies(policy_class,
|
|||
ENABLED_VALUE_XPATH,
|
||||
policy_filedata):
|
||||
this_policy_setting = 'Enabled'
|
||||
log.debug('{0} is enabled'.format(this_policyname))
|
||||
log.debug('{0} is enabled by detected ENABLED_VALUE_XPATH'.format(this_policyname))
|
||||
if this_policynamespace not in policy_vals:
|
||||
policy_vals[this_policynamespace] = {}
|
||||
policy_vals[this_policynamespace][this_policyname] = this_policy_setting
|
||||
if DISABLED_VALUE_XPATH(admx_policy) and this_policy_setting == 'Not Configured':
|
||||
# some policies have a disabled list but not an enabled list
|
||||
# added this to address those issues
|
||||
if ENABLED_LIST_XPATH(admx_policy):
|
||||
if ENABLED_LIST_XPATH(admx_policy) or ENABLED_VALUE_XPATH(admx_policy):
|
||||
element_only_enabled_disabled = False
|
||||
explicit_enable_disable_value_setting = True
|
||||
if _checkValueItemParent(admx_policy,
|
||||
|
@ -3706,25 +3706,27 @@ def _checkAllAdmxPolicies(policy_class,
|
|||
DISABLED_VALUE_XPATH,
|
||||
policy_filedata):
|
||||
this_policy_setting = 'Disabled'
|
||||
log.debug('{0} is disabled'.format(this_policyname))
|
||||
log.debug('{0} is disabled by detected DISABLED_VALUE_XPATH'.format(this_policyname))
|
||||
if this_policynamespace not in policy_vals:
|
||||
policy_vals[this_policynamespace] = {}
|
||||
policy_vals[this_policynamespace][this_policyname] = this_policy_setting
|
||||
if ENABLED_LIST_XPATH(admx_policy) and this_policy_setting == 'Not Configured':
|
||||
element_only_enabled_disabled = False
|
||||
explicit_enable_disable_value_setting = True
|
||||
if DISABLED_LIST_XPATH(admx_policy) or DISABLED_VALUE_XPATH(admx_policy):
|
||||
element_only_enabled_disabled = False
|
||||
explicit_enable_disable_value_setting = True
|
||||
if _checkListItem(admx_policy, this_policyname, this_key, ENABLED_LIST_XPATH, policy_filedata):
|
||||
this_policy_setting = 'Enabled'
|
||||
log.debug('{0} is enabled'.format(this_policyname))
|
||||
log.debug('{0} is enabled by detected ENABLED_LIST_XPATH'.format(this_policyname))
|
||||
if this_policynamespace not in policy_vals:
|
||||
policy_vals[this_policynamespace] = {}
|
||||
policy_vals[this_policynamespace][this_policyname] = this_policy_setting
|
||||
if DISABLED_LIST_XPATH(admx_policy) and this_policy_setting == 'Not Configured':
|
||||
element_only_enabled_disabled = False
|
||||
explicit_enable_disable_value_setting = True
|
||||
if ENABLED_LIST_XPATH(admx_policy) or ENABLED_VALUE_XPATH(admx_policy):
|
||||
element_only_enabled_disabled = False
|
||||
explicit_enable_disable_value_setting = True
|
||||
if _checkListItem(admx_policy, this_policyname, this_key, DISABLED_LIST_XPATH, policy_filedata):
|
||||
this_policy_setting = 'Disabled'
|
||||
log.debug('{0} is disabled'.format(this_policyname))
|
||||
log.debug('{0} is disabled by detected DISABLED_LIST_XPATH'.format(this_policyname))
|
||||
if this_policynamespace not in policy_vals:
|
||||
policy_vals[this_policynamespace] = {}
|
||||
policy_vals[this_policynamespace][this_policyname] = this_policy_setting
|
||||
|
@ -3739,7 +3741,7 @@ def _checkAllAdmxPolicies(policy_class,
|
|||
'1')),
|
||||
policy_filedata):
|
||||
this_policy_setting = 'Enabled'
|
||||
log.debug('{0} is enabled'.format(this_policyname))
|
||||
log.debug('{0} is enabled by no explicit enable/disable list or value'.format(this_policyname))
|
||||
if this_policynamespace not in policy_vals:
|
||||
policy_vals[this_policynamespace] = {}
|
||||
policy_vals[this_policynamespace][this_policyname] = this_policy_setting
|
||||
|
@ -3750,7 +3752,7 @@ def _checkAllAdmxPolicies(policy_class,
|
|||
check_deleted=True)),
|
||||
policy_filedata):
|
||||
this_policy_setting = 'Disabled'
|
||||
log.debug('{0} is disabled'.format(this_policyname))
|
||||
log.debug('{0} is disabled by no explicit enable/disable list or value'.format(this_policyname))
|
||||
if this_policynamespace not in policy_vals:
|
||||
policy_vals[this_policynamespace] = {}
|
||||
policy_vals[this_policynamespace][this_policyname] = this_policy_setting
|
||||
|
|
|
@ -429,6 +429,9 @@ class BaseSaltAPIHandler(tornado.web.RequestHandler): # pylint: disable=W0223
|
|||
'runner_async': None, # empty, since we use the same client as `runner`
|
||||
}
|
||||
|
||||
if not hasattr(self, 'ckminions'):
|
||||
self.ckminions = salt.utils.minions.CkMinions(self.application.opts)
|
||||
|
||||
@property
|
||||
def token(self):
|
||||
'''
|
||||
|
@ -921,7 +924,8 @@ class SaltAPIHandler(BaseSaltAPIHandler): # pylint: disable=W0223
|
|||
chunk['jid'] = salt.utils.jid.gen_jid()
|
||||
|
||||
# Subscribe returns from minions before firing a job
|
||||
future_minion_map = self.subscribe_minion_returns(chunk['jid'], chunk['tgt'])
|
||||
minions = set(self.ckminions.check_minions(chunk['tgt'], chunk.get('tgt_type', 'glob')))
|
||||
future_minion_map = self.subscribe_minion_returns(chunk['jid'], minions)
|
||||
|
||||
f_call = self._format_call_run_job_async(chunk)
|
||||
# fire a job off
|
||||
|
@ -940,9 +944,9 @@ class SaltAPIHandler(BaseSaltAPIHandler): # pylint: disable=W0223
|
|||
pass
|
||||
raise tornado.gen.Return('No minions matched the target. No command was sent, no jid was assigned.')
|
||||
|
||||
syndic_min_wait = None
|
||||
# wait syndic a while to avoid missing published events
|
||||
if self.application.opts['order_masters']:
|
||||
syndic_min_wait = tornado.gen.sleep(self.application.opts['syndic_wait'])
|
||||
yield tornado.gen.sleep(self.application.opts['syndic_wait'])
|
||||
|
||||
# To ensure job_not_running and all_return are terminated by each other, communicate using a future
|
||||
is_finished = Future()
|
||||
|
@ -952,10 +956,6 @@ class SaltAPIHandler(BaseSaltAPIHandler): # pylint: disable=W0223
|
|||
f_call['kwargs']['tgt_type'],
|
||||
is_finished)
|
||||
|
||||
# if we have a min_wait, do that
|
||||
if syndic_min_wait is not None:
|
||||
yield syndic_min_wait
|
||||
|
||||
minion_returns_future = self.sanitize_minion_returns(future_minion_map, pub_data['minions'], is_finished)
|
||||
|
||||
yield job_not_running_future
|
||||
|
@ -992,7 +992,7 @@ class SaltAPIHandler(BaseSaltAPIHandler): # pylint: disable=W0223
|
|||
|
||||
chunk_ret = {}
|
||||
while True:
|
||||
f = yield Any(future_minion_map.keys() + [is_finished])
|
||||
f = yield Any(list(future_minion_map.keys()) + [is_finished])
|
||||
try:
|
||||
# When finished entire routine, cleanup other futures and return result
|
||||
if f is is_finished:
|
||||
|
|
|
@ -3255,43 +3255,45 @@ class BaseHighState(object):
|
|||
'Specified SLS {0} on local filesystem cannot '
|
||||
'be found.'.format(sls)
|
||||
)
|
||||
state = None
|
||||
if not fn_:
|
||||
errors.append(
|
||||
'Specified SLS {0} in saltenv {1} is not '
|
||||
'available on the salt master or through a configured '
|
||||
'fileserver'.format(sls, saltenv)
|
||||
)
|
||||
state = None
|
||||
try:
|
||||
state = compile_template(fn_,
|
||||
self.state.rend,
|
||||
self.state.opts['renderer'],
|
||||
self.state.opts['renderer_blacklist'],
|
||||
self.state.opts['renderer_whitelist'],
|
||||
saltenv,
|
||||
sls,
|
||||
rendered_sls=mods
|
||||
)
|
||||
except SaltRenderError as exc:
|
||||
msg = 'Rendering SLS \'{0}:{1}\' failed: {2}'.format(
|
||||
saltenv, sls, exc
|
||||
)
|
||||
log.critical(msg)
|
||||
errors.append(msg)
|
||||
except Exception as exc:
|
||||
msg = 'Rendering SLS {0} failed, render error: {1}'.format(
|
||||
sls, exc
|
||||
)
|
||||
log.critical(
|
||||
msg,
|
||||
# Show the traceback if the debug logging level is enabled
|
||||
exc_info_on_loglevel=logging.DEBUG
|
||||
)
|
||||
errors.append('{0}\n{1}'.format(msg, traceback.format_exc()))
|
||||
try:
|
||||
mods.add('{0}:{1}'.format(saltenv, sls))
|
||||
except AttributeError:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
state = compile_template(fn_,
|
||||
self.state.rend,
|
||||
self.state.opts['renderer'],
|
||||
self.state.opts['renderer_blacklist'],
|
||||
self.state.opts['renderer_whitelist'],
|
||||
saltenv,
|
||||
sls,
|
||||
rendered_sls=mods
|
||||
)
|
||||
except SaltRenderError as exc:
|
||||
msg = 'Rendering SLS \'{0}:{1}\' failed: {2}'.format(
|
||||
saltenv, sls, exc
|
||||
)
|
||||
log.critical(msg)
|
||||
errors.append(msg)
|
||||
except Exception as exc:
|
||||
msg = 'Rendering SLS {0} failed, render error: {1}'.format(
|
||||
sls, exc
|
||||
)
|
||||
log.critical(
|
||||
msg,
|
||||
# Show the traceback if the debug logging level is enabled
|
||||
exc_info_on_loglevel=logging.DEBUG
|
||||
)
|
||||
errors.append('{0}\n{1}'.format(msg, traceback.format_exc()))
|
||||
try:
|
||||
mods.add('{0}:{1}'.format(saltenv, sls))
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
if state:
|
||||
if not isinstance(state, dict):
|
||||
errors.append(
|
||||
|
|
|
@ -184,24 +184,19 @@ def _check_pkg_version_format(pkg):
|
|||
return ret
|
||||
|
||||
|
||||
def _check_if_installed(prefix, state_pkg_name, version_spec,
|
||||
ignore_installed, force_reinstall,
|
||||
upgrade, user, cwd, bin_env, env_vars):
|
||||
def _check_if_installed(prefix, state_pkg_name, version_spec, ignore_installed,
|
||||
force_reinstall, upgrade, user, cwd, bin_env, env_vars,
|
||||
**kwargs):
|
||||
# result: None means the command failed to run
|
||||
# result: True means the package is installed
|
||||
# result: False means the package is not installed
|
||||
ret = {'result': False, 'comment': None}
|
||||
|
||||
# Check if the requested package is already installed.
|
||||
try:
|
||||
pip_list = __salt__['pip.list'](prefix, bin_env=bin_env,
|
||||
user=user, cwd=cwd,
|
||||
env_vars=env_vars)
|
||||
prefix_realname = _find_key(prefix, pip_list)
|
||||
except (CommandNotFoundError, CommandExecutionError) as err:
|
||||
ret['result'] = None
|
||||
ret['comment'] = 'Error installing \'{0}\': {1}'.format(state_pkg_name, err)
|
||||
return ret
|
||||
pip_list = __salt__['pip.list'](prefix, bin_env=bin_env,
|
||||
user=user, cwd=cwd,
|
||||
env_vars=env_vars, **kwargs)
|
||||
prefix_realname = _find_key(prefix, pip_list)
|
||||
|
||||
# If the package was already installed, check
|
||||
# the ignore_installed and force_reinstall flags
|
||||
|
@ -313,7 +308,6 @@ def installed(name,
|
|||
install_options=None,
|
||||
global_options=None,
|
||||
user=None,
|
||||
no_chown=False,
|
||||
cwd=None,
|
||||
pre_releases=False,
|
||||
cert=None,
|
||||
|
@ -326,7 +320,8 @@ def installed(name,
|
|||
trusted_host=None,
|
||||
no_cache_dir=False,
|
||||
cache_dir=None,
|
||||
no_binary=None):
|
||||
no_binary=None,
|
||||
**kwargs):
|
||||
'''
|
||||
Make sure the package is installed
|
||||
|
||||
|
@ -448,10 +443,6 @@ def installed(name,
|
|||
no_install
|
||||
Download and unpack all packages, but don't actually install them
|
||||
|
||||
no_chown
|
||||
When user is given, do not attempt to copy and chown
|
||||
a requirements file
|
||||
|
||||
no_cache_dir:
|
||||
Disable the cache.
|
||||
|
||||
|
@ -594,6 +585,12 @@ def installed(name,
|
|||
|
||||
.. _`virtualenv`: http://www.virtualenv.org/en/latest/
|
||||
'''
|
||||
if 'no_chown' in kwargs:
|
||||
salt.utils.warn_until(
|
||||
'Flourine',
|
||||
'The no_chown argument has been deprecated and is no longer used. '
|
||||
'Its functionality was removed in Boron.')
|
||||
kwargs.pop('no_chown')
|
||||
|
||||
if pip_bin and not bin_env:
|
||||
bin_env = pip_bin
|
||||
|
@ -619,11 +616,16 @@ def installed(name,
|
|||
ret = {'name': ';'.join(pkgs), 'result': None,
|
||||
'comment': '', 'changes': {}}
|
||||
|
||||
try:
|
||||
cur_version = __salt__['pip.version'](bin_env)
|
||||
except (CommandNotFoundError, CommandExecutionError) as err:
|
||||
ret['result'] = None
|
||||
ret['comment'] = 'Error installing \'{0}\': {1}'.format(name, err)
|
||||
return ret
|
||||
# Check that the pip binary supports the 'use_wheel' option
|
||||
if use_wheel:
|
||||
min_version = '1.4'
|
||||
max_version = '9.0.3'
|
||||
cur_version = __salt__['pip.version'](bin_env)
|
||||
too_low = salt.utils.compare_versions(ver1=cur_version, oper='<', ver2=min_version)
|
||||
too_high = salt.utils.compare_versions(ver1=cur_version, oper='>', ver2=max_version)
|
||||
if too_low or too_high:
|
||||
|
@ -637,7 +639,6 @@ def installed(name,
|
|||
if no_use_wheel:
|
||||
min_version = '1.4'
|
||||
max_version = '9.0.3'
|
||||
cur_version = __salt__['pip.version'](bin_env)
|
||||
too_low = salt.utils.compare_versions(ver1=cur_version, oper='<', ver2=min_version)
|
||||
too_high = salt.utils.compare_versions(ver1=cur_version, oper='>', ver2=max_version)
|
||||
if too_low or too_high:
|
||||
|
@ -650,7 +651,6 @@ def installed(name,
|
|||
# Check that the pip binary supports the 'no_binary' option
|
||||
if no_binary:
|
||||
min_version = '7.0.0'
|
||||
cur_version = __salt__['pip.version'](bin_env)
|
||||
too_low = salt.utils.compare_versions(ver1=cur_version, oper='<', ver2=min_version)
|
||||
if too_low:
|
||||
ret['result'] = False
|
||||
|
@ -723,7 +723,8 @@ def installed(name,
|
|||
version_spec = version_spec
|
||||
out = _check_if_installed(prefix, state_pkg_name, version_spec,
|
||||
ignore_installed, force_reinstall,
|
||||
upgrade, user, cwd, bin_env, env_vars)
|
||||
upgrade, user, cwd, bin_env, env_vars,
|
||||
**kwargs)
|
||||
# If _check_if_installed result is None, something went wrong with
|
||||
# the command running. This way we keep stateful output.
|
||||
if out['result'] is None:
|
||||
|
@ -803,7 +804,6 @@ def installed(name,
|
|||
install_options=install_options,
|
||||
global_options=global_options,
|
||||
user=user,
|
||||
no_chown=no_chown,
|
||||
cwd=cwd,
|
||||
pre_releases=pre_releases,
|
||||
cert=cert,
|
||||
|
@ -815,7 +815,8 @@ def installed(name,
|
|||
env_vars=env_vars,
|
||||
use_vt=use_vt,
|
||||
trusted_host=trusted_host,
|
||||
no_cache_dir=no_cache_dir
|
||||
no_cache_dir=no_cache_dir,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
if pip_install_call and pip_install_call.get('retcode', 1) == 0:
|
||||
|
@ -871,7 +872,8 @@ def installed(name,
|
|||
if prefix:
|
||||
pipsearch = __salt__['pip.list'](prefix, bin_env,
|
||||
user=user, cwd=cwd,
|
||||
env_vars=env_vars)
|
||||
env_vars=env_vars,
|
||||
**kwargs)
|
||||
|
||||
# If we didn't find the package in the system after
|
||||
# installing it report it
|
||||
|
|
|
@ -153,6 +153,16 @@ def __virtual__():
|
|||
return 'pkg.install' in __salt__
|
||||
|
||||
|
||||
def _warn_virtual(virtual):
|
||||
return [
|
||||
'The following package(s) are "virtual package" names: {0}. These '
|
||||
'will no longer be supported as of the Fluorine release. Please '
|
||||
'update your SLS file(s) to use the actual package name.'.format(
|
||||
', '.join(virtual)
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
def _get_comparison_spec(pkgver):
|
||||
'''
|
||||
Return a tuple containing the comparison operator and the version. If no
|
||||
|
@ -529,6 +539,11 @@ def _find_install_targets(name=None,
|
|||
was_refreshed = True
|
||||
refresh = False
|
||||
|
||||
def _get_virtual(desired):
|
||||
return [x for x in desired if cur_pkgs.get(x, []) == ['1']]
|
||||
|
||||
virtual_pkgs = []
|
||||
|
||||
if any((pkgs, sources)):
|
||||
if pkgs:
|
||||
desired = _repack_pkgs(pkgs, normalize=normalize)
|
||||
|
@ -546,6 +561,8 @@ def _find_install_targets(name=None,
|
|||
'comment': 'Invalidly formatted \'{0}\' parameter. See '
|
||||
'minion log.'.format('pkgs' if pkgs
|
||||
else 'sources')}
|
||||
|
||||
virtual_pkgs = _get_virtual(desired)
|
||||
to_unpurge = _find_unpurge_targets(desired)
|
||||
else:
|
||||
if salt.utils.is_windows():
|
||||
|
@ -566,6 +583,7 @@ def _find_install_targets(name=None,
|
|||
else:
|
||||
desired = {name: version}
|
||||
|
||||
virtual_pkgs = _get_virtual(desired)
|
||||
to_unpurge = _find_unpurge_targets(desired)
|
||||
|
||||
# FreeBSD pkg supports `openjdk` and `java/openjdk7` package names
|
||||
|
@ -582,22 +600,28 @@ def _find_install_targets(name=None,
|
|||
and not reinstall \
|
||||
and not pkg_verify:
|
||||
# The package is installed and is the correct version
|
||||
return {'name': name,
|
||||
'changes': {},
|
||||
'result': True,
|
||||
'comment': 'Version {0} of package \'{1}\' is already '
|
||||
'installed'.format(version, name)}
|
||||
ret = {'name': name,
|
||||
'changes': {},
|
||||
'result': True,
|
||||
'comment': 'Version {0} of package \'{1}\' is already '
|
||||
'installed'.format(version, name)}
|
||||
if virtual_pkgs:
|
||||
ret['warnings'] = _warn_virtual(virtual_pkgs)
|
||||
return ret
|
||||
|
||||
# if cver is not an empty string, the package is already installed
|
||||
elif cver and version is None \
|
||||
and not reinstall \
|
||||
and not pkg_verify:
|
||||
# The package is installed
|
||||
return {'name': name,
|
||||
'changes': {},
|
||||
'result': True,
|
||||
'comment': 'Package {0} is already '
|
||||
'installed'.format(name)}
|
||||
ret = {'name': name,
|
||||
'changes': {},
|
||||
'result': True,
|
||||
'comment': 'Package {0} is already '
|
||||
'installed'.format(name)}
|
||||
if virtual_pkgs:
|
||||
ret['warnings'] = _warn_virtual(virtual_pkgs)
|
||||
return ret
|
||||
|
||||
version_spec = False
|
||||
if not sources:
|
||||
|
@ -635,10 +659,13 @@ def _find_install_targets(name=None,
|
|||
if comments:
|
||||
if len(comments) > 1:
|
||||
comments.append('')
|
||||
return {'name': name,
|
||||
'changes': {},
|
||||
'result': False,
|
||||
'comment': '. '.join(comments).rstrip()}
|
||||
ret = {'name': name,
|
||||
'changes': {},
|
||||
'result': False,
|
||||
'comment': '. '.join(comments).rstrip()}
|
||||
if virtual_pkgs:
|
||||
ret['warnings'] = _warn_virtual(virtual_pkgs)
|
||||
return ret
|
||||
|
||||
# Resolve the latest package version for any packages with "latest" in the
|
||||
# package version
|
||||
|
@ -770,10 +797,13 @@ def _find_install_targets(name=None,
|
|||
problems.append(failed_verify)
|
||||
|
||||
if problems:
|
||||
return {'name': name,
|
||||
'changes': {},
|
||||
'result': False,
|
||||
'comment': ' '.join(problems)}
|
||||
ret = {'name': name,
|
||||
'changes': {},
|
||||
'result': False,
|
||||
'comment': ' '.join(problems)}
|
||||
if virtual_pkgs:
|
||||
ret['warnings'] = _warn_virtual(virtual_pkgs)
|
||||
return ret
|
||||
|
||||
if not any((targets, to_unpurge, to_reinstall)):
|
||||
# All specified packages are installed
|
||||
|
@ -788,6 +818,8 @@ def _find_install_targets(name=None,
|
|||
'comment': msg}
|
||||
if warnings:
|
||||
ret.setdefault('warnings', []).extend(warnings)
|
||||
if virtual_pkgs:
|
||||
ret.setdefault('warnings', []).extend(_warn_virtual(virtual_pkgs))
|
||||
return ret
|
||||
|
||||
return (desired, targets, to_unpurge, to_reinstall, altered_files,
|
||||
|
@ -1720,6 +1752,25 @@ def installed(
|
|||
and x not in to_reinstall]
|
||||
failed = [x for x in failed if x in targets]
|
||||
|
||||
# Check for virtual packages in list of desired packages
|
||||
if not sources:
|
||||
try:
|
||||
virtual_pkgs = []
|
||||
for pkgname in [next(iter(x)) for x in pkgs] if pkgs else [name]:
|
||||
cver = new_pkgs.get(pkgname, [])
|
||||
if '1' in cver:
|
||||
virtual_pkgs.append(pkgname)
|
||||
if virtual_pkgs:
|
||||
warnings.extend(_warn_virtual(virtual_pkgs))
|
||||
except Exception:
|
||||
# This is just some temporary code to warn the user about using
|
||||
# virtual packages. Don't let an exception break the entire
|
||||
# state.
|
||||
log.debug(
|
||||
'Failed to detect virtual packages after running '
|
||||
'pkg.install', exc_info=True
|
||||
)
|
||||
|
||||
# If there was nothing unpurged, just set the changes dict to the contents
|
||||
# of changes['installed'].
|
||||
if not changes.get('purge_desired'):
|
||||
|
|
|
@ -39,7 +39,6 @@ def managed(name,
|
|||
never_download=None,
|
||||
prompt=None,
|
||||
user=None,
|
||||
no_chown=False,
|
||||
cwd=None,
|
||||
index_url=None,
|
||||
extra_index_url=None,
|
||||
|
@ -58,7 +57,8 @@ def managed(name,
|
|||
pip_no_cache_dir=False,
|
||||
pip_cache_dir=None,
|
||||
process_dependency_links=False,
|
||||
no_binary=None):
|
||||
no_binary=None,
|
||||
**kwargs):
|
||||
'''
|
||||
Create a virtualenv and optionally manage it with pip
|
||||
|
||||
|
@ -78,11 +78,6 @@ def managed(name,
|
|||
user: None
|
||||
The user under which to run virtualenv and pip.
|
||||
|
||||
no_chown: False
|
||||
When user is given, do not attempt to copy and chown a requirements file
|
||||
(needed if the requirements file refers to other files via relative
|
||||
paths, as the copy-and-chown procedure does not account for such files)
|
||||
|
||||
cwd: None
|
||||
Path to the working directory where `pip install` is executed.
|
||||
|
||||
|
@ -133,6 +128,13 @@ def managed(name,
|
|||
- env_vars:
|
||||
PATH_VAR: '/usr/local/bin/'
|
||||
'''
|
||||
if 'no_chown' in kwargs:
|
||||
salt.utils.warn_until(
|
||||
'Flourine',
|
||||
'The no_chown argument has been deprecated and is no longer used. '
|
||||
'Its functionality was removed in Boron.')
|
||||
kwargs.pop('no_chown')
|
||||
|
||||
ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
|
||||
|
||||
if 'virtualenv.create' not in __salt__:
|
||||
|
@ -205,6 +207,7 @@ def managed(name,
|
|||
prompt=prompt,
|
||||
user=user,
|
||||
use_vt=use_vt,
|
||||
**kwargs
|
||||
)
|
||||
except CommandNotFoundError as err:
|
||||
ret['result'] = False
|
||||
|
@ -305,7 +308,6 @@ def managed(name,
|
|||
extra_index_url=extra_index_url,
|
||||
download=pip_download,
|
||||
download_cache=pip_download_cache,
|
||||
no_chown=no_chown,
|
||||
pre_releases=pre_releases,
|
||||
exists_action=pip_exists_action,
|
||||
ignore_installed=pip_ignore_installed,
|
||||
|
@ -315,7 +317,8 @@ def managed(name,
|
|||
use_vt=use_vt,
|
||||
env_vars=env_vars,
|
||||
no_cache_dir=pip_no_cache_dir,
|
||||
cache_dir=pip_cache_dir
|
||||
cache_dir=pip_cache_dir,
|
||||
**kwargs
|
||||
)
|
||||
ret['result'] &= pip_ret['retcode'] == 0
|
||||
if pip_ret['retcode'] > 0:
|
||||
|
|
|
@ -30,13 +30,11 @@ import salt.transport.server
|
|||
import salt.transport.mixins.auth
|
||||
from salt.exceptions import SaltReqTimeoutError
|
||||
|
||||
import zmq
|
||||
from salt.utils.zeromq import zmq, ZMQDefaultLoop, install_zmq, ZMQ_VERSION_INFO, LIBZMQ_VERSION_INFO
|
||||
import zmq.error
|
||||
import zmq.eventloop.ioloop
|
||||
# support pyzmq 13.0.x, TODO: remove once we force people to 14.0.x
|
||||
if not hasattr(zmq.eventloop.ioloop, 'ZMQIOLoop'):
|
||||
zmq.eventloop.ioloop.ZMQIOLoop = zmq.eventloop.ioloop.IOLoop
|
||||
import zmq.eventloop.zmqstream
|
||||
|
||||
try:
|
||||
import zmq.utils.monitor
|
||||
HAS_ZMQ_MONITOR = True
|
||||
|
@ -61,6 +59,42 @@ except ImportError:
|
|||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _get_master_uri(master_ip,
|
||||
master_port,
|
||||
source_ip=None,
|
||||
source_port=None):
|
||||
'''
|
||||
Return the ZeroMQ URI to connect the Minion to the Master.
|
||||
It supports different source IP / port, given the ZeroMQ syntax:
|
||||
|
||||
// Connecting using a IP address and bind to an IP address
|
||||
rc = zmq_connect(socket, "tcp://192.168.1.17:5555;192.168.1.1:5555"); assert (rc == 0);
|
||||
|
||||
Source: http://api.zeromq.org/4-1:zmq-tcp
|
||||
'''
|
||||
if LIBZMQ_VERSION_INFO >= (4, 1, 6) and ZMQ_VERSION_INFO >= (16, 0, 1):
|
||||
# The source:port syntax for ZeroMQ has been added in libzmq 4.1.6
|
||||
# which is included in the pyzmq wheels starting with 16.0.1.
|
||||
if source_ip or source_port:
|
||||
if source_ip and source_port:
|
||||
return 'tcp://{source_ip}:{source_port};{master_ip}:{master_port}'.format(
|
||||
source_ip=source_ip, source_port=source_port,
|
||||
master_ip=master_ip, master_port=master_port)
|
||||
elif source_ip and not source_port:
|
||||
return 'tcp://{source_ip}:0;{master_ip}:{master_port}'.format(
|
||||
source_ip=source_ip,
|
||||
master_ip=master_ip, master_port=master_port)
|
||||
elif not source_ip and source_port:
|
||||
return 'tcp://0.0.0.0:{source_port};{master_ip}:{master_port}'.format(
|
||||
source_port=source_port,
|
||||
master_ip=master_ip, master_port=master_port)
|
||||
if source_ip or source_port:
|
||||
log.warning('Unable to connect to the Master using a specific source IP / port')
|
||||
log.warning('Consider upgrading to pyzmq >= 16.0.1 and libzmq >= 4.1.6')
|
||||
return 'tcp://{master_ip}:{master_port}'.format(
|
||||
master_ip=master_ip, master_port=master_port)
|
||||
|
||||
|
||||
class AsyncZeroMQReqChannel(salt.transport.client.ReqChannel):
|
||||
'''
|
||||
Encapsulate sending routines to ZeroMQ.
|
||||
|
@ -79,9 +113,8 @@ class AsyncZeroMQReqChannel(salt.transport.client.ReqChannel):
|
|||
# do we have any mapping for this io_loop
|
||||
io_loop = kwargs.get('io_loop')
|
||||
if io_loop is None:
|
||||
if not TORNADO_50:
|
||||
zmq.eventloop.ioloop.install()
|
||||
io_loop = tornado.ioloop.IOLoop.current()
|
||||
install_zmq()
|
||||
io_loop = ZMQDefaultLoop.current()
|
||||
if io_loop not in cls.instance_map:
|
||||
cls.instance_map[io_loop] = weakref.WeakValueDictionary()
|
||||
loop_instance_map = cls.instance_map[io_loop]
|
||||
|
@ -96,7 +129,8 @@ class AsyncZeroMQReqChannel(salt.transport.client.ReqChannel):
|
|||
obj = object.__new__(cls)
|
||||
obj.__singleton_init__(opts, **kwargs)
|
||||
loop_instance_map[key] = obj
|
||||
log.trace('Inserted key into loop_instance_map id {0} for key {1} and process {2}'.format(id(loop_instance_map), key, os.getpid()))
|
||||
log.trace('Inserted key into loop_instance_map id %s for key %s and process %s',
|
||||
id(loop_instance_map), key, os.getpid())
|
||||
else:
|
||||
log.debug('Re-using AsyncZeroMQReqChannel for {0}'.format(key))
|
||||
return obj
|
||||
|
@ -148,9 +182,8 @@ class AsyncZeroMQReqChannel(salt.transport.client.ReqChannel):
|
|||
|
||||
self._io_loop = kwargs.get('io_loop')
|
||||
if self._io_loop is None:
|
||||
if not TORNADO_50:
|
||||
zmq.eventloop.ioloop.install()
|
||||
self._io_loop = tornado.ioloop.IOLoop.current()
|
||||
install_zmq()
|
||||
self._io_loop = ZMQDefaultLoop.current()
|
||||
|
||||
if self.crypt != 'clear':
|
||||
# we don't need to worry about auth as a kwarg, since its a singleton
|
||||
|
@ -290,19 +323,14 @@ class AsyncZeroMQPubChannel(salt.transport.mixins.auth.AESPubClientMixin, salt.t
|
|||
**kwargs):
|
||||
self.opts = opts
|
||||
self.ttype = 'zeromq'
|
||||
|
||||
self.io_loop = kwargs.get('io_loop')
|
||||
if self.io_loop is None:
|
||||
if not TORNADO_50:
|
||||
zmq.eventloop.ioloop.install()
|
||||
self.io_loop = tornado.ioloop.IOLoop.current()
|
||||
|
||||
self.hexid = hashlib.sha1(six.b(self.opts['id'])).hexdigest()
|
||||
install_zmq()
|
||||
self.io_loop = ZMQDefaultLoop.current()
|
||||
|
||||
self.hexid = hashlib.sha1(salt.utils.to_bytes(self.opts['id'])).hexdigest()
|
||||
self.auth = salt.crypt.AsyncAuth(self.opts, io_loop=self.io_loop)
|
||||
|
||||
self.serial = salt.payload.Serial(self.opts)
|
||||
|
||||
self.context = zmq.Context()
|
||||
self._socket = self.context.socket(zmq.SUB)
|
||||
|
||||
|
@ -334,8 +362,7 @@ class AsyncZeroMQPubChannel(salt.transport.mixins.auth.AESPubClientMixin, salt.t
|
|||
|
||||
if self.opts['recon_randomize']:
|
||||
recon_delay = randint(self.opts['recon_default'],
|
||||
self.opts['recon_default'] + self.opts['recon_max']
|
||||
)
|
||||
self.opts['recon_default'] + self.opts['recon_max'])
|
||||
|
||||
log.debug("Generated random reconnect delay between '{0}ms' and '{1}ms' ({2})".format(
|
||||
self.opts['recon_default'],
|
||||
|
@ -449,7 +476,8 @@ class AsyncZeroMQPubChannel(salt.transport.mixins.auth.AESPubClientMixin, salt.t
|
|||
return self.stream.on_recv(wrap_callback)
|
||||
|
||||
|
||||
class ZeroMQReqServerChannel(salt.transport.mixins.auth.AESReqServerMixin, salt.transport.server.ReqServerChannel):
|
||||
class ZeroMQReqServerChannel(salt.transport.mixins.auth.AESReqServerMixin,
|
||||
salt.transport.server.ReqServerChannel):
|
||||
|
||||
def __init__(self, opts):
|
||||
salt.transport.server.ReqServerChannel.__init__(self, opts)
|
||||
|
@ -469,13 +497,7 @@ class ZeroMQReqServerChannel(salt.transport.mixins.auth.AESReqServerMixin, salt.
|
|||
# IPv6 sockets work for both IPv6 and IPv4 addresses
|
||||
self.clients.setsockopt(zmq.IPV4ONLY, 0)
|
||||
self.clients.setsockopt(zmq.BACKLOG, self.opts.get('zmq_backlog', 1000))
|
||||
if HAS_ZMQ_MONITOR and self.opts['zmq_monitor']:
|
||||
# Socket monitor shall be used the only for debug purposes so using threading doesn't look too bad here
|
||||
import threading
|
||||
self._monitor = ZeroMQSocketMonitor(self.clients)
|
||||
t = threading.Thread(target=self._monitor.start_poll)
|
||||
t.start()
|
||||
|
||||
self._start_zmq_monitor()
|
||||
self.workers = self.context.socket(zmq.DEALER)
|
||||
|
||||
if self.opts.get('ipc_mode', '') == 'tcp':
|
||||
|
@ -489,7 +511,6 @@ class ZeroMQReqServerChannel(salt.transport.mixins.auth.AESReqServerMixin, salt.
|
|||
|
||||
log.info('Setting up the master communication server')
|
||||
self.clients.bind(self.uri)
|
||||
|
||||
self.workers.bind(self.w_uri)
|
||||
|
||||
while True:
|
||||
|
@ -512,10 +533,11 @@ class ZeroMQReqServerChannel(salt.transport.mixins.auth.AESReqServerMixin, salt.
|
|||
return
|
||||
log.info('MWorkerQueue under PID %s is closing', os.getpid())
|
||||
self._closing = True
|
||||
if hasattr(self, '_monitor') and self._monitor is not None:
|
||||
# pylint: disable=E0203
|
||||
if getattr(self, '_monitor', None) is not None:
|
||||
self._monitor.stop()
|
||||
self._monitor = None
|
||||
if hasattr(self, '_w_monitor') and self._w_monitor is not None:
|
||||
if getattr(self, '_w_monitor', None) is not None:
|
||||
self._w_monitor.stop()
|
||||
self._w_monitor = None
|
||||
if hasattr(self, 'clients') and self.clients.closed is False:
|
||||
|
@ -528,6 +550,7 @@ class ZeroMQReqServerChannel(salt.transport.mixins.auth.AESReqServerMixin, salt.
|
|||
self._socket.close()
|
||||
if hasattr(self, 'context') and self.context.closed is False:
|
||||
self.context.term()
|
||||
# pylint: enable=E0203
|
||||
|
||||
def pre_fork(self, process_manager):
|
||||
'''
|
||||
|
@ -538,6 +561,21 @@ class ZeroMQReqServerChannel(salt.transport.mixins.auth.AESReqServerMixin, salt.
|
|||
salt.transport.mixins.auth.AESReqServerMixin.pre_fork(self, process_manager)
|
||||
process_manager.add_process(self.zmq_device)
|
||||
|
||||
def _start_zmq_monitor(self):
|
||||
'''
|
||||
Starts ZMQ monitor for debugging purposes.
|
||||
:return:
|
||||
'''
|
||||
# Socket monitor shall be used the only for debug
|
||||
# purposes so using threading doesn't look too bad here
|
||||
|
||||
if HAS_ZMQ_MONITOR and self.opts['zmq_monitor']:
|
||||
log.debug('Starting ZMQ monitor')
|
||||
import threading
|
||||
self._w_monitor = ZeroMQSocketMonitor(self._socket)
|
||||
threading.Thread(target=self._w_monitor.start_poll).start()
|
||||
log.debug('ZMQ monitor has been started started')
|
||||
|
||||
def post_fork(self, payload_handler, io_loop):
|
||||
'''
|
||||
After forking we need to create all of the local sockets to listen to the
|
||||
|
@ -552,12 +590,7 @@ class ZeroMQReqServerChannel(salt.transport.mixins.auth.AESReqServerMixin, salt.
|
|||
|
||||
self.context = zmq.Context(1)
|
||||
self._socket = self.context.socket(zmq.REP)
|
||||
if HAS_ZMQ_MONITOR and self.opts['zmq_monitor']:
|
||||
# Socket monitor shall be used the only for debug purposes so using threading doesn't look too bad here
|
||||
import threading
|
||||
self._w_monitor = ZeroMQSocketMonitor(self._socket)
|
||||
t = threading.Thread(target=self._w_monitor.start_poll)
|
||||
t.start()
|
||||
self._start_zmq_monitor()
|
||||
|
||||
if self.opts.get('ipc_mode', '') == 'tcp':
|
||||
self.w_uri = 'tcp://127.0.0.1:{0}'.format(
|
||||
|
@ -763,27 +796,35 @@ class ZeroMQPubServerChannel(salt.transport.server.PubServerChannel):
|
|||
# Catch and handle EINTR from when this process is sent
|
||||
# SIGUSR1 gracefully so we don't choke and die horribly
|
||||
try:
|
||||
log.trace('Getting data from puller %s', pull_uri)
|
||||
package = pull_sock.recv()
|
||||
unpacked_package = salt.payload.unpackage(package)
|
||||
if six.PY3:
|
||||
unpacked_package = salt.transport.frame.decode_embedded_strs(unpacked_package)
|
||||
payload = unpacked_package['payload']
|
||||
log.trace('Accepted unpacked package from puller')
|
||||
if self.opts['zmq_filtering']:
|
||||
# if you have a specific topic list, use that
|
||||
if 'topic_lst' in unpacked_package:
|
||||
for topic in unpacked_package['topic_lst']:
|
||||
log.trace('Sending filtered data over publisher %s', pub_uri)
|
||||
# zmq filters are substring match, hash the topic
|
||||
# to avoid collisions
|
||||
htopic = hashlib.sha1(topic).hexdigest()
|
||||
pub_sock.send(htopic, flags=zmq.SNDMORE)
|
||||
pub_sock.send(payload)
|
||||
log.trace('Filtered data has been sent')
|
||||
# otherwise its a broadcast
|
||||
else:
|
||||
# TODO: constants file for "broadcast"
|
||||
log.trace('Sending broadcasted data over publisher %s', pub_uri)
|
||||
pub_sock.send('broadcast', flags=zmq.SNDMORE)
|
||||
pub_sock.send(payload)
|
||||
log.trace('Broadcasted data has been sent')
|
||||
else:
|
||||
log.trace('Sending ZMQ-unfiltered data over publisher %s', pub_uri)
|
||||
pub_sock.send(payload)
|
||||
log.trace('Unfiltered data has been sent')
|
||||
except zmq.ZMQError as exc:
|
||||
if exc.errno == errno.EINTR:
|
||||
continue
|
||||
|
@ -901,14 +942,12 @@ class AsyncReqMessageClient(object):
|
|||
self.addr = addr
|
||||
self.linger = linger
|
||||
if io_loop is None:
|
||||
if not TORNADO_50:
|
||||
zmq.eventloop.ioloop.install()
|
||||
tornado.ioloop.IOLoop.current()
|
||||
install_zmq()
|
||||
ZMQDefaultLoop.current()
|
||||
else:
|
||||
self.io_loop = io_loop
|
||||
|
||||
self.serial = salt.payload.Serial(self.opts)
|
||||
|
||||
self.context = zmq.Context()
|
||||
|
||||
# wire up sockets
|
||||
|
@ -987,7 +1026,8 @@ class AsyncReqMessageClient(object):
|
|||
|
||||
try:
|
||||
ret = yield future
|
||||
except: # pylint: disable=W0702
|
||||
except Exception as err: # pylint: disable=W0702
|
||||
log.debug('Re-init ZMQ socket: %s', err)
|
||||
self._init_socket() # re-init the zmq socket (no other way in zmq)
|
||||
del self.send_queue[0]
|
||||
continue
|
||||
|
|
|
@ -7,26 +7,9 @@ from __future__ import absolute_import
|
|||
|
||||
import tornado.ioloop
|
||||
import tornado.concurrent
|
||||
# attempt to use zmq-- if we have it otherwise fallback to tornado loop
|
||||
try:
|
||||
import zmq.eventloop.ioloop
|
||||
# support pyzmq 13.0.x, TODO: remove once we force people to 14.0.x
|
||||
if not hasattr(zmq.eventloop.ioloop, 'ZMQIOLoop'):
|
||||
zmq.eventloop.ioloop.ZMQIOLoop = zmq.eventloop.ioloop.IOLoop
|
||||
HAS_ZMQ = True
|
||||
except ImportError:
|
||||
HAS_ZMQ = False
|
||||
|
||||
import tornado
|
||||
TORNADO_50 = tornado.version_info >= (5,)
|
||||
|
||||
if HAS_ZMQ and not TORNADO_50:
|
||||
LOOP_CLASS = zmq.eventloop.ioloop.ZMQIOLoop
|
||||
else:
|
||||
import tornado.ioloop
|
||||
LOOP_CLASS = tornado.ioloop.IOLoop
|
||||
|
||||
import contextlib
|
||||
from salt.utils import zeromq
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
|
@ -60,7 +43,7 @@ class SyncWrapper(object):
|
|||
if kwargs is None:
|
||||
kwargs = {}
|
||||
|
||||
self.io_loop = LOOP_CLASS()
|
||||
self.io_loop = zeromq.ZMQDefaultLoop()
|
||||
kwargs['io_loop'] = self.io_loop
|
||||
|
||||
with current_ioloop(self.io_loop):
|
||||
|
|
|
@ -18,11 +18,7 @@ import salt.utils.dictupdate
|
|||
|
||||
# Import third party libs
|
||||
from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
|
||||
try:
|
||||
import zmq
|
||||
HAS_ZMQ = True
|
||||
except ImportError:
|
||||
HAS_ZMQ = False
|
||||
from salt.utils.zeromq import zmq
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
|
|
@ -29,12 +29,8 @@ from salt.utils.cache import CacheCli as cache_cli
|
|||
from salt.utils.process import MultiprocessingProcess
|
||||
|
||||
# Import third party libs
|
||||
import salt.ext.six as six
|
||||
try:
|
||||
import zmq
|
||||
HAS_ZMQ = True
|
||||
except ImportError:
|
||||
HAS_ZMQ = False
|
||||
from salt.ext import six
|
||||
from salt.utils.zeromq import zmq
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
|
|
@ -908,7 +908,7 @@ class SaltNova(object):
|
|||
try:
|
||||
ret[item.name] = {
|
||||
'id': item.id,
|
||||
'status': 'Running'
|
||||
'state': 'Running'
|
||||
}
|
||||
except TypeError:
|
||||
pass
|
||||
|
|
|
@ -3,21 +3,60 @@
|
|||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import Salt libs
|
||||
import logging
|
||||
import tornado.ioloop
|
||||
from salt.exceptions import SaltSystemExit
|
||||
|
||||
# Import 3rd-party libs
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
try:
|
||||
import zmq
|
||||
HAS_ZMQ = True
|
||||
except ImportError:
|
||||
HAS_ZMQ = False
|
||||
zmq = None
|
||||
log.debug('ZMQ module is not found')
|
||||
|
||||
ZMQDefaultLoop = None
|
||||
ZMQ_VERSION_INFO = (-1, -1, -1)
|
||||
LIBZMQ_VERSION_INFO = (-1, -1, -1)
|
||||
|
||||
try:
|
||||
if zmq:
|
||||
ZMQ_VERSION_INFO = tuple([int(v_el) for v_el in zmq.__version__.split('.')])
|
||||
LIBZMQ_VERSION_INFO = tuple([int(v_el) for v_el in zmq.zmq_version().split('.')])
|
||||
if ZMQ_VERSION_INFO[0] > 16: # 17.0.x+ deprecates zmq's ioloops
|
||||
ZMQDefaultLoop = tornado.ioloop.IOLoop
|
||||
except Exception:
|
||||
log.exception('Error while getting LibZMQ/PyZMQ library version')
|
||||
|
||||
if ZMQDefaultLoop is None:
|
||||
try:
|
||||
import zmq.eventloop.ioloop
|
||||
# Support for ZeroMQ 13.x
|
||||
if not hasattr(zmq.eventloop.ioloop, 'ZMQIOLoop'):
|
||||
zmq.eventloop.ioloop.ZMQIOLoop = zmq.eventloop.ioloop.IOLoop
|
||||
if tornado.version_info < (5,):
|
||||
ZMQDefaultLoop = zmq.eventloop.ioloop.ZMQIOLoop
|
||||
except ImportError:
|
||||
ZMQDefaultLoop = None
|
||||
if ZMQDefaultLoop is None:
|
||||
ZMQDefaultLoop = tornado.ioloop.IOLoop
|
||||
|
||||
|
||||
def install_zmq():
|
||||
'''
|
||||
While pyzmq 17 no longer needs any special integration for tornado,
|
||||
older version still need one.
|
||||
:return:
|
||||
'''
|
||||
if zmq and ZMQ_VERSION_INFO[0] < 17:
|
||||
if tornado.version_info < (5,):
|
||||
zmq.eventloop.ioloop.install()
|
||||
|
||||
|
||||
def check_ipc_path_max_len(uri):
|
||||
# The socket path is limited to 107 characters on Solaris and
|
||||
# Linux, and 103 characters on BSD-based systems.
|
||||
if not HAS_ZMQ:
|
||||
if zmq is None:
|
||||
return
|
||||
ipc_path_max_len = getattr(zmq, 'IPC_PATH_MAX_LEN', 103)
|
||||
if ipc_path_max_len and len(uri) > ipc_path_max_len:
|
||||
|
|
|
@ -6,3 +6,5 @@
|
|||
{#- wheels are disabled because the pip cache dir will not be owned by the above issue-1959 user. Need to check this ASAP #}
|
||||
- no_binary: ':all:'
|
||||
{%- endif %}
|
||||
- env:
|
||||
XDG_CACHE_HOME: /tmp
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
import os
|
||||
import pwd
|
||||
import shutil
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
# Import Salt Testing libs
|
||||
|
@ -73,23 +73,34 @@ class PipModuleTest(ModuleCase):
|
|||
|
||||
# Let's remove the pip binary
|
||||
pip_bin = os.path.join(self.venv_dir, 'bin', 'pip')
|
||||
py_dir = 'python{0}.{1}'.format(*sys.version_info[:2])
|
||||
site_dir = os.path.join(self.venv_dir, 'lib', py_dir, 'site-packages')
|
||||
if salt.utils.is_windows():
|
||||
pip_bin = os.path.join(self.venv_dir, 'Scripts', 'pip.exe')
|
||||
site_dir = os.path.join(self.venv_dir, 'lib', 'site-packages')
|
||||
if not os.path.isfile(pip_bin):
|
||||
self.skipTest(
|
||||
'Failed to find the pip binary to the test virtualenv'
|
||||
)
|
||||
os.remove(pip_bin)
|
||||
|
||||
# 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'))
|
||||
|
||||
# Let's run a pip depending functions
|
||||
for func in ('pip.freeze', 'pip.list'):
|
||||
ret = self.run_function(func, bin_env=self.venv_dir)
|
||||
self.assertIn(
|
||||
'Command required for \'{0}\' not found: '
|
||||
'Could not find a `pip` binary in virtualenv'.format(func),
|
||||
'Could not find a `pip` binary'.format(func),
|
||||
ret
|
||||
)
|
||||
|
||||
@skip_if_not_root
|
||||
def test_requirements_as_list_of_chains__sans_no_chown__cwd_set__absolute_file_path(self):
|
||||
def test_requirements_as_list_of_chains__cwd_set__absolute_file_path(self):
|
||||
self.run_function('virtualenv.create', [self.venv_dir])
|
||||
|
||||
# Create a requirements file that depends on another one.
|
||||
|
@ -108,11 +119,10 @@ class PipModuleTest(ModuleCase):
|
|||
with salt.utils.fopen(req2b_filename, 'w') as f:
|
||||
f.write('pep8\n')
|
||||
|
||||
this_user = pwd.getpwuid(os.getuid())[0]
|
||||
requirements_list = [req1_filename, req2_filename]
|
||||
|
||||
ret = self.run_function(
|
||||
'pip.install', requirements=requirements_list, user=this_user,
|
||||
'pip.install', requirements=requirements_list,
|
||||
bin_env=self.venv_dir, cwd=self.venv_dir
|
||||
)
|
||||
try:
|
||||
|
@ -127,7 +137,7 @@ class PipModuleTest(ModuleCase):
|
|||
raise
|
||||
|
||||
@skip_if_not_root
|
||||
def test_requirements_as_list_of_chains__sans_no_chown__cwd_not_set__absolute_file_path(self):
|
||||
def test_requirements_as_list_of_chains__cwd_not_set__absolute_file_path(self):
|
||||
self.run_function('virtualenv.create', [self.venv_dir])
|
||||
|
||||
# Create a requirements file that depends on another one.
|
||||
|
@ -146,12 +156,10 @@ class PipModuleTest(ModuleCase):
|
|||
with salt.utils.fopen(req2b_filename, 'w') as f:
|
||||
f.write('pep8\n')
|
||||
|
||||
this_user = pwd.getpwuid(os.getuid())[0]
|
||||
requirements_list = [req1_filename, req2_filename]
|
||||
|
||||
ret = self.run_function(
|
||||
'pip.install', requirements=requirements_list, user=this_user,
|
||||
bin_env=self.venv_dir
|
||||
'pip.install', requirements=requirements_list, bin_env=self.venv_dir
|
||||
)
|
||||
try:
|
||||
self.assertEqual(ret['retcode'], 0)
|
||||
|
@ -166,7 +174,7 @@ class PipModuleTest(ModuleCase):
|
|||
raise
|
||||
|
||||
@skip_if_not_root
|
||||
def test_requirements_as_list__sans_no_chown__absolute_file_path(self):
|
||||
def test_requirements_as_list__absolute_file_path(self):
|
||||
self.run_function('virtualenv.create', [self.venv_dir])
|
||||
|
||||
req1_filename = os.path.join(self.venv_dir, 'requirements.txt')
|
||||
|
@ -177,12 +185,10 @@ class PipModuleTest(ModuleCase):
|
|||
with salt.utils.fopen(req2_filename, 'w') as f:
|
||||
f.write('pep8\n')
|
||||
|
||||
this_user = pwd.getpwuid(os.getuid())[0]
|
||||
requirements_list = [req1_filename, req2_filename]
|
||||
|
||||
ret = self.run_function(
|
||||
'pip.install', requirements=requirements_list, user=this_user,
|
||||
bin_env=self.venv_dir
|
||||
'pip.install', requirements=requirements_list, bin_env=self.venv_dir
|
||||
)
|
||||
|
||||
found = self.pip_successful_install(ret['stdout'])
|
||||
|
@ -197,7 +203,7 @@ class PipModuleTest(ModuleCase):
|
|||
raise
|
||||
|
||||
@skip_if_not_root
|
||||
def test_requirements_as_list__sans_no_chown__non_absolute_file_path(self):
|
||||
def test_requirements_as_list__non_absolute_file_path(self):
|
||||
self.run_function('virtualenv.create', [self.venv_dir])
|
||||
|
||||
# Create a requirements file that depends on another one.
|
||||
|
@ -214,11 +220,10 @@ class PipModuleTest(ModuleCase):
|
|||
with salt.utils.fopen(req2_filepath, 'w') as f:
|
||||
f.write('pep8\n')
|
||||
|
||||
this_user = pwd.getpwuid(os.getuid())[0]
|
||||
requirements_list = [req1_filename, req2_filename]
|
||||
|
||||
ret = self.run_function(
|
||||
'pip.install', requirements=requirements_list, user=this_user,
|
||||
'pip.install', requirements=requirements_list,
|
||||
bin_env=self.venv_dir, cwd=req_cwd
|
||||
)
|
||||
try:
|
||||
|
@ -233,7 +238,7 @@ class PipModuleTest(ModuleCase):
|
|||
raise
|
||||
|
||||
@skip_if_not_root
|
||||
def test_chained_requirements__sans_no_chown__absolute_file_path(self):
|
||||
def test_chained_requirements__absolute_file_path(self):
|
||||
self.run_function('virtualenv.create', [self.venv_dir])
|
||||
|
||||
# Create a requirements file that depends on another one.
|
||||
|
@ -246,10 +251,8 @@ class PipModuleTest(ModuleCase):
|
|||
with salt.utils.fopen(req2_filename, 'w') as f:
|
||||
f.write('pep8')
|
||||
|
||||
this_user = pwd.getpwuid(os.getuid())[0]
|
||||
ret = self.run_function(
|
||||
'pip.install', requirements=req1_filename, user=this_user,
|
||||
bin_env=self.venv_dir
|
||||
'pip.install', requirements=req1_filename, bin_env=self.venv_dir
|
||||
)
|
||||
try:
|
||||
self.assertEqual(ret['retcode'], 0)
|
||||
|
@ -260,7 +263,7 @@ class PipModuleTest(ModuleCase):
|
|||
raise
|
||||
|
||||
@skip_if_not_root
|
||||
def test_chained_requirements__sans_no_chown__non_absolute_file_path(self):
|
||||
def test_chained_requirements__non_absolute_file_path(self):
|
||||
self.run_function('virtualenv.create', [self.venv_dir])
|
||||
|
||||
# Create a requirements file that depends on another one.
|
||||
|
@ -277,10 +280,9 @@ class PipModuleTest(ModuleCase):
|
|||
with salt.utils.fopen(req2_file, 'w') as f:
|
||||
f.write('pep8')
|
||||
|
||||
this_user = pwd.getpwuid(os.getuid())[0]
|
||||
ret = self.run_function(
|
||||
'pip.install', requirements=req1_filename, user=this_user,
|
||||
no_chown=False, cwd=req_basepath, bin_env=self.venv_dir
|
||||
'pip.install', requirements=req1_filename, cwd=req_basepath,
|
||||
bin_env=self.venv_dir
|
||||
)
|
||||
try:
|
||||
self.assertEqual(ret['retcode'], 0)
|
||||
|
@ -291,7 +293,7 @@ class PipModuleTest(ModuleCase):
|
|||
raise
|
||||
|
||||
@skip_if_not_root
|
||||
def test_issue_4805_nested_requirements_user_no_chown(self):
|
||||
def test_issue_4805_nested_requirements(self):
|
||||
self.run_function('virtualenv.create', [self.venv_dir])
|
||||
|
||||
# Create a requirements file that depends on another one.
|
||||
|
@ -302,11 +304,8 @@ class PipModuleTest(ModuleCase):
|
|||
with salt.utils.fopen(req2_filename, 'w') as f:
|
||||
f.write('pep8')
|
||||
|
||||
this_user = pwd.getpwuid(os.getuid())[0]
|
||||
ret = self.run_function(
|
||||
'pip.install', requirements=req1_filename, user=this_user,
|
||||
no_chown=True, bin_env=self.venv_dir
|
||||
)
|
||||
'pip.install', requirements=req1_filename, bin_env=self.venv_dir)
|
||||
if self._check_download_error(ret['stdout']):
|
||||
self.skipTest('Test skipped due to pip download error')
|
||||
try:
|
||||
|
@ -435,9 +434,9 @@ class PipModuleTest(ModuleCase):
|
|||
def tearDown(self):
|
||||
super(PipModuleTest, self).tearDown()
|
||||
if os.path.isdir(self.venv_test_dir):
|
||||
shutil.rmtree(self.venv_test_dir)
|
||||
shutil.rmtree(self.venv_test_dir, ignore_errors=True)
|
||||
if os.path.isdir(self.pip_temp):
|
||||
shutil.rmtree(self.pip_temp)
|
||||
shutil.rmtree(self.pip_temp, ignore_errors=True)
|
||||
del self.venv_dir
|
||||
del self.venv_test_dir
|
||||
del self.pip_temp
|
||||
|
|
|
@ -6,6 +6,7 @@ from __future__ import absolute_import
|
|||
# Import Salt Testing libs
|
||||
from tests.support.case import ModuleCase
|
||||
from tests.support.helpers import destructiveTest
|
||||
from tests.support.unit import skipIf
|
||||
|
||||
# Import Salt libs
|
||||
import salt.utils
|
||||
|
@ -30,10 +31,32 @@ class ServiceModuleTest(ModuleCase):
|
|||
self.service_name = 'org.ntp.ntpd'
|
||||
if int(os_release.split('.')[1]) >= 13:
|
||||
self.service_name = 'com.apple.AirPlayXPCHelper'
|
||||
elif salt.utils.is_windows():
|
||||
self.service_name = 'Spooler'
|
||||
|
||||
if salt.utils.which(cmd_name) is None:
|
||||
self.pre_srv_status = self.run_function('service.status', [self.service_name])
|
||||
self.pre_srv_enabled = True if self.service_name in self.run_function('service.get_enabled') else False
|
||||
|
||||
if salt.utils.which(cmd_name) is None and not salt.utils.is_windows():
|
||||
self.skipTest('{0} is not installed'.format(cmd_name))
|
||||
|
||||
def tearDown(self):
|
||||
post_srv_status = self.run_function('service.status', [self.service_name])
|
||||
post_srv_enabled = True if self.service_name in self.run_function('service.get_enabled') else False
|
||||
|
||||
if post_srv_status != self.pre_srv_status:
|
||||
if self.pre_srv_status:
|
||||
self.run_function('service.enable', [self.service_name])
|
||||
else:
|
||||
self.run_function('service.disable', [self.service_name])
|
||||
|
||||
if post_srv_enabled != self.pre_srv_enabled:
|
||||
if self.pre_srv_enabled:
|
||||
self.run_function('service.enable', [self.service_name])
|
||||
else:
|
||||
self.run_function('service.disable', [self.service_name])
|
||||
del self.service_name
|
||||
|
||||
def test_service_status_running(self):
|
||||
'''
|
||||
test service.status execution module
|
||||
|
@ -53,3 +76,37 @@ class ServiceModuleTest(ModuleCase):
|
|||
|
||||
check_service = self.run_function('service.status', [self.service_name])
|
||||
self.assertFalse(check_service)
|
||||
|
||||
def test_service_restart(self):
|
||||
'''
|
||||
test service.restart
|
||||
'''
|
||||
self.assertTrue(self.run_function('service.restart', [self.service_name]))
|
||||
|
||||
def test_service_enable(self):
|
||||
'''
|
||||
test service.get_enabled and service.enable module
|
||||
'''
|
||||
# disable service before test
|
||||
self.assertTrue(self.run_function('service.disable', [self.service_name]))
|
||||
|
||||
self.assertTrue(self.run_function('service.enable', [self.service_name]))
|
||||
self.assertIn(self.service_name, self.run_function('service.get_enabled'))
|
||||
|
||||
def test_service_disable(self):
|
||||
'''
|
||||
test service.get_disabled and service.disable module
|
||||
'''
|
||||
# enable service before test
|
||||
self.assertTrue(self.run_function('service.enable', [self.service_name]))
|
||||
|
||||
self.assertTrue(self.run_function('service.disable', [self.service_name]))
|
||||
self.assertIn(self.service_name, self.run_function('service.get_disabled'))
|
||||
|
||||
@skipIf(not salt.utils.is_windows(), 'Windows Only Test')
|
||||
def test_service_get_service_name(self):
|
||||
'''
|
||||
test service.get_service_name
|
||||
'''
|
||||
ret = self.run_function('service.get_service_name')
|
||||
self.assertIn(self.service_name, ret.values())
|
||||
|
|
|
@ -18,13 +18,9 @@ from tests.support.helpers import flaky
|
|||
from tests.support.unit import skipIf
|
||||
|
||||
# Import 3rd-party libs
|
||||
import salt.ext.six as six
|
||||
try:
|
||||
import zmq
|
||||
from zmq.eventloop.ioloop import ZMQIOLoop
|
||||
HAS_ZMQ_IOLOOP = True
|
||||
except ImportError:
|
||||
HAS_ZMQ_IOLOOP = False
|
||||
from salt.ext import six
|
||||
from salt.utils.zeromq import zmq, ZMQDefaultLoop as ZMQIOLoop
|
||||
HAS_ZMQ_IOLOOP = bool(zmq)
|
||||
|
||||
|
||||
def json_loads(data):
|
||||
|
@ -53,6 +49,7 @@ class TestSaltAPIHandler(_SaltnadoIntegrationTestCase):
|
|||
application = self.build_tornado_app(urls)
|
||||
|
||||
application.event_listener = saltnado.EventListener({}, self.opts)
|
||||
self.application = application
|
||||
return application
|
||||
|
||||
def test_root(self):
|
||||
|
@ -89,8 +86,6 @@ class TestSaltAPIHandler(_SaltnadoIntegrationTestCase):
|
|||
self.assertEqual(response.code, 302)
|
||||
self.assertEqual(response.headers['Location'], '/login')
|
||||
|
||||
# Local client tests
|
||||
@skipIf(True, 'to be re-enabled when #23623 is merged')
|
||||
def test_simple_local_post(self):
|
||||
'''
|
||||
Test a basic API of /
|
||||
|
@ -108,7 +103,8 @@ class TestSaltAPIHandler(_SaltnadoIntegrationTestCase):
|
|||
request_timeout=30,
|
||||
)
|
||||
response_obj = json_loads(response.body)
|
||||
self.assertEqual(response_obj['return'], [{'minion': True, 'sub_minion': True}])
|
||||
self.assertEqual(len(response_obj['return']), 1)
|
||||
self.assertEqual(response_obj['return'][0], {'minion': True, 'sub_minion': True})
|
||||
|
||||
def test_simple_local_post_no_tgt(self):
|
||||
'''
|
||||
|
@ -129,8 +125,6 @@ class TestSaltAPIHandler(_SaltnadoIntegrationTestCase):
|
|||
response_obj = json_loads(response.body)
|
||||
self.assertEqual(response_obj['return'], ["No minions matched the target. No command was sent, no jid was assigned."])
|
||||
|
||||
# local client request body test
|
||||
@skipIf(True, 'Undetermined race condition in test. Temporarily disabled.')
|
||||
def test_simple_local_post_only_dictionary_request(self):
|
||||
'''
|
||||
Test a basic API of /
|
||||
|
@ -148,7 +142,8 @@ class TestSaltAPIHandler(_SaltnadoIntegrationTestCase):
|
|||
request_timeout=30,
|
||||
)
|
||||
response_obj = json_loads(response.body)
|
||||
self.assertEqual(response_obj['return'], [{'minion': True, 'sub_minion': True}])
|
||||
self.assertEqual(len(response_obj['return']), 1)
|
||||
self.assertEqual(response_obj['return'][0], {'minion': True, 'sub_minion': True})
|
||||
|
||||
def test_simple_local_post_invalid_request(self):
|
||||
'''
|
||||
|
@ -263,6 +258,28 @@ class TestSaltAPIHandler(_SaltnadoIntegrationTestCase):
|
|||
response_obj = json_loads(response.body)
|
||||
self.assertEqual(response_obj['return'], [{}])
|
||||
|
||||
def test_simple_local_post_only_dictionary_request_with_order_masters(self):
|
||||
'''
|
||||
Test a basic API of /
|
||||
'''
|
||||
low = {'client': 'local',
|
||||
'tgt': '*',
|
||||
'fun': 'test.ping',
|
||||
}
|
||||
response = self.fetch('/',
|
||||
method='POST',
|
||||
body=salt.utils.json.dumps(low),
|
||||
headers={'Content-Type': self.content_type_map['json'],
|
||||
saltnado.AUTH_TOKEN_HEADER: self.token['token']},
|
||||
connect_timeout=30,
|
||||
request_timeout=30,
|
||||
)
|
||||
response_obj = salt.utils.json.loads(response.body)
|
||||
|
||||
self.application.opts['order_masters'] = []
|
||||
self.application.opts['syndic_wait'] = 5
|
||||
self.assertEqual(response_obj['return'], [{'minion': True, 'sub_minion': True}])
|
||||
|
||||
# runner tests
|
||||
def test_simple_local_runner_post(self):
|
||||
low = [{'client': 'runner',
|
||||
|
|
|
@ -11,11 +11,16 @@
|
|||
from __future__ import absolute_import
|
||||
import errno
|
||||
import os
|
||||
import pwd
|
||||
import glob
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
try:
|
||||
import pwd
|
||||
HAS_PWD = True
|
||||
except ImportError:
|
||||
HAS_PWD = False
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.mixins import SaltReturnAssertsMixin
|
||||
from tests.support.unit import skipIf
|
||||
|
@ -24,11 +29,14 @@ from tests.support.helpers import (
|
|||
destructiveTest,
|
||||
requires_system_grains,
|
||||
with_system_user,
|
||||
skip_if_not_root
|
||||
skip_if_not_root,
|
||||
with_tempdir
|
||||
)
|
||||
# Import salt libs
|
||||
from tests.support.case import ModuleCase
|
||||
import salt.utils
|
||||
import salt.utils.win_dacl
|
||||
import salt.utils.win_functions
|
||||
from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
|
||||
from salt.exceptions import CommandExecutionError
|
||||
|
||||
|
@ -47,7 +55,7 @@ class VirtualEnv(object):
|
|||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
if os.path.isdir(self.venv_dir):
|
||||
shutil.rmtree(self.venv_dir)
|
||||
shutil.rmtree(self.venv_dir, ignore_errors=True)
|
||||
|
||||
|
||||
@skipIf(salt.utils.which_bin(KNOWN_BINARY_NAMES) is None, 'virtualenv not installed')
|
||||
|
@ -113,9 +121,10 @@ class PipStateTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
else:
|
||||
os.environ['SHELL'] = orig_shell
|
||||
if os.path.isdir(venv_dir):
|
||||
shutil.rmtree(venv_dir)
|
||||
shutil.rmtree(venv_dir, ignore_errors=True)
|
||||
|
||||
@skipIf(six.PY3, 'Issue is specific to carbon module, which is PY2-only')
|
||||
@skipIf(salt.utils.is_windows(), "Carbon does not install in Windows")
|
||||
@requires_system_grains
|
||||
def test_pip_installed_weird_install(self, grains=None):
|
||||
# First, check to see if this is running on CentOS 5 or MacOS.
|
||||
|
@ -141,7 +150,7 @@ class PipStateTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
)
|
||||
finally:
|
||||
if os.path.isdir(ographite):
|
||||
shutil.rmtree(ographite)
|
||||
shutil.rmtree(ographite, ignore_errors=True)
|
||||
|
||||
venv_dir = os.path.join(RUNTIME_VARS.TMP, 'pip-installed-weird-install')
|
||||
try:
|
||||
|
@ -150,7 +159,7 @@ class PipStateTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
# context when running the call to state.sls that comes after.
|
||||
self.run_function('saltutil.sync_modules')
|
||||
# Since we don't have the virtualenv created, pip.installed will
|
||||
# thrown and error.
|
||||
# throw an error.
|
||||
ret = self.run_function(
|
||||
'state.sls', mods='pip-installed-weird-install'
|
||||
)
|
||||
|
@ -172,7 +181,7 @@ class PipStateTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
raise Exception('Expected state did not run')
|
||||
finally:
|
||||
if os.path.isdir(ographite):
|
||||
shutil.rmtree(ographite)
|
||||
shutil.rmtree(ographite, ignore_errors=True)
|
||||
|
||||
def test_issue_2028_pip_installed_state(self):
|
||||
ret = self.run_function('state.sls', mods='issue-2028-pip-installed')
|
||||
|
@ -181,14 +190,18 @@ class PipStateTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
RUNTIME_VARS.TMP, 'issue-2028-pip-installed'
|
||||
)
|
||||
|
||||
pep8_bin = os.path.join(venv_dir, 'bin', 'pep8')
|
||||
if salt.utils.is_windows():
|
||||
pep8_bin = os.path.join(venv_dir, 'Scripts', 'pep8.exe')
|
||||
|
||||
try:
|
||||
self.assertSaltTrueReturn(ret)
|
||||
self.assertTrue(
|
||||
os.path.isfile(os.path.join(venv_dir, 'bin', 'pep8'))
|
||||
os.path.isfile(pep8_bin)
|
||||
)
|
||||
finally:
|
||||
if os.path.isdir(venv_dir):
|
||||
shutil.rmtree(venv_dir)
|
||||
shutil.rmtree(venv_dir, ignore_errors=True)
|
||||
|
||||
def test_issue_2087_missing_pip(self):
|
||||
venv_dir = os.path.join(
|
||||
|
@ -202,12 +215,23 @@ class PipStateTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
|
||||
# Let's remove the pip binary
|
||||
pip_bin = os.path.join(venv_dir, 'bin', 'pip')
|
||||
py_dir = 'python{0}.{1}'.format(*sys.version_info[:2])
|
||||
site_dir = os.path.join(venv_dir, 'lib', py_dir, 'site-packages')
|
||||
if salt.utils.is_windows():
|
||||
pip_bin = os.path.join(venv_dir, 'Scripts', 'pip.exe')
|
||||
site_dir = os.path.join(venv_dir, 'lib', 'site-packages')
|
||||
if not os.path.isfile(pip_bin):
|
||||
self.skipTest(
|
||||
'Failed to find the pip binary to the test virtualenv'
|
||||
)
|
||||
os.remove(pip_bin)
|
||||
|
||||
# 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'))
|
||||
|
||||
# Let's run the state which should fail because pip is missing
|
||||
ret = self.run_function('state.sls', mods='issue-2087-missing-pip')
|
||||
self.assertSaltFalseReturn(ret)
|
||||
|
@ -217,7 +241,7 @@ class PipStateTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
)
|
||||
finally:
|
||||
if os.path.isdir(venv_dir):
|
||||
shutil.rmtree(venv_dir)
|
||||
shutil.rmtree(venv_dir, ignore_errors=True)
|
||||
|
||||
def test_issue_5940_multiple_pip_mirrors(self):
|
||||
'''
|
||||
|
@ -242,148 +266,99 @@ class PipStateTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
self.skipTest('the --mirrors arg has been deprecated and removed in pip==7.0.0')
|
||||
finally:
|
||||
if os.path.isdir(venv_dir):
|
||||
shutil.rmtree(venv_dir)
|
||||
shutil.rmtree(venv_dir, ignore_errors=True)
|
||||
|
||||
@destructiveTest
|
||||
@skip_if_not_root
|
||||
@with_system_user('issue-6912', on_existing='delete', delete=True)
|
||||
def test_issue_6912_wrong_owner(self, username):
|
||||
venv_dir = os.path.join(
|
||||
RUNTIME_VARS.TMP, '6912-wrong-owner'
|
||||
)
|
||||
# ----- Using runas ------------------------------------------------->
|
||||
venv_create = self.run_function(
|
||||
'virtualenv.create', [venv_dir], user=username
|
||||
)
|
||||
if venv_create['retcode'] > 0:
|
||||
self.skipTest(
|
||||
'Failed to create testcase virtual environment: {0}'.format(
|
||||
venv_create
|
||||
)
|
||||
)
|
||||
@with_system_user('issue-6912', on_existing='delete', delete=True,
|
||||
password='PassWord1!')
|
||||
@with_tempdir()
|
||||
def test_issue_6912_wrong_owner(self, temp_dir, username):
|
||||
# Setup virtual environment directory to be used throughout the test
|
||||
venv_dir = os.path.join(temp_dir, '6912-wrong-owner')
|
||||
|
||||
# Using the package name.
|
||||
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):
|
||||
# The virtual environment needs to be in a location that is accessible
|
||||
# by both the user running the test and the runas user
|
||||
if salt.utils.is_windows():
|
||||
salt.utils.win_dacl.set_permissions(temp_dir, username, 'full_control')
|
||||
else:
|
||||
uid = self.run_function('file.user_to_uid', [username])
|
||||
os.chown(temp_dir, uid, -1)
|
||||
|
||||
# Create the virtual environment
|
||||
venv_create = self.run_function(
|
||||
'virtualenv.create', [venv_dir], user=username,
|
||||
password='PassWord1!')
|
||||
if venv_create['retcode'] > 0:
|
||||
self.skipTest('Failed to create testcase virtual environment: {0}'
|
||||
''.format(venv_create))
|
||||
|
||||
# pip install passing the package name in `name`
|
||||
ret = self.run_state(
|
||||
'pip.installed', name='pep8', user=username, bin_env=venv_dir,
|
||||
no_cache_dir=True, password='PassWord1!')
|
||||
self.assertSaltTrueReturn(ret)
|
||||
|
||||
if HAS_PWD:
|
||||
uid = pwd.getpwnam(username).pw_uid
|
||||
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):
|
||||
if HAS_PWD:
|
||||
self.assertEqual(uid, os.stat(path).st_uid)
|
||||
elif salt.utils.is_windows():
|
||||
self.assertEqual(
|
||||
uinfo.pw_uid, os.stat(path).st_uid
|
||||
)
|
||||
salt.utils.win_dacl.get_owner(path), username)
|
||||
|
||||
finally:
|
||||
if os.path.isdir(venv_dir):
|
||||
shutil.rmtree(venv_dir)
|
||||
@destructiveTest
|
||||
@skip_if_not_root
|
||||
@with_system_user('issue-6912', on_existing='delete', delete=True,
|
||||
password='PassWord1!')
|
||||
@with_tempdir()
|
||||
def test_issue_6912_wrong_owner_requirements_file(self, temp_dir, username):
|
||||
# Setup virtual environment directory to be used throughout the test
|
||||
venv_dir = os.path.join(temp_dir, '6912-wrong-owner')
|
||||
|
||||
# Using a requirements file
|
||||
# The virtual environment needs to be in a location that is accessible
|
||||
# by both the user running the test and the runas user
|
||||
if salt.utils.is_windows():
|
||||
salt.utils.win_dacl.set_permissions(temp_dir, username, 'full_control')
|
||||
else:
|
||||
uid = self.run_function('file.user_to_uid', [username])
|
||||
os.chown(temp_dir, uid, -1)
|
||||
|
||||
# Create the virtual environment again as it should have been removed
|
||||
venv_create = self.run_function(
|
||||
'virtualenv.create', [venv_dir], user=username
|
||||
)
|
||||
'virtualenv.create', [venv_dir], user=username,
|
||||
password='PassWord1!')
|
||||
if venv_create['retcode'] > 0:
|
||||
self.skipTest(
|
||||
'Failed to create testcase virtual environment: {0}'.format(
|
||||
ret
|
||||
)
|
||||
)
|
||||
self.skipTest('failed to create testcase virtual environment: {0}'
|
||||
''.format(venv_create))
|
||||
|
||||
# pip install using a requirements file
|
||||
req_filename = os.path.join(
|
||||
RUNTIME_VARS.TMP_STATE_TREE, 'issue-6912-requirements.txt'
|
||||
)
|
||||
RUNTIME_VARS.TMP_STATE_TREE, 'issue-6912-requirements.txt')
|
||||
with salt.utils.fopen(req_filename, 'wb') as reqf:
|
||||
reqf.write(six.b('pep8'))
|
||||
|
||||
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):
|
||||
ret = self.run_state(
|
||||
'pip.installed', name='', user=username, bin_env=venv_dir,
|
||||
requirements='salt://issue-6912-requirements.txt',
|
||||
no_cache_dir=True, password='PassWord1!')
|
||||
self.assertSaltTrueReturn(ret)
|
||||
|
||||
if HAS_PWD:
|
||||
uid = pwd.getpwnam(username).pw_uid
|
||||
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):
|
||||
if HAS_PWD:
|
||||
self.assertEqual(uid, os.stat(path).st_uid)
|
||||
elif salt.utils.is_windows():
|
||||
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)
|
||||
# <---- Using runas --------------------------------------------------
|
||||
|
||||
# ----- Using user -------------------------------------------------->
|
||||
venv_create = self.run_function(
|
||||
'virtualenv.create', [venv_dir], user=username
|
||||
)
|
||||
if venv_create['retcode'] > 0:
|
||||
self.skipTest(
|
||||
'Failed to create testcase virtual environment: {0}'.format(
|
||||
ret
|
||||
)
|
||||
)
|
||||
|
||||
# Using the package name
|
||||
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)
|
||||
|
||||
# Using a requirements file
|
||||
venv_create = self.run_function(
|
||||
'virtualenv.create', [venv_dir], user=username
|
||||
)
|
||||
if venv_create['retcode'] > 0:
|
||||
self.skipTest(
|
||||
'Failed to create testcase virtual environment: {0}'.format(
|
||||
ret
|
||||
)
|
||||
)
|
||||
req_filename = os.path.join(
|
||||
RUNTIME_VARS.TMP_STATE_TREE, 'issue-6912-requirements.txt'
|
||||
)
|
||||
with salt.utils.fopen(req_filename, 'wb') as reqf:
|
||||
reqf.write(six.b('pep8'))
|
||||
|
||||
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)
|
||||
# <---- Using user ---------------------------------------------------
|
||||
salt.utils.win_dacl.get_owner(path), username)
|
||||
|
||||
def test_issue_6833_pip_upgrade_pip(self):
|
||||
# Create the testing virtualenv
|
||||
|
@ -391,6 +366,7 @@ class PipStateTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
RUNTIME_VARS.TMP, '6833-pip-upgrade-pip'
|
||||
)
|
||||
ret = self.run_function('virtualenv.create', [venv_dir])
|
||||
|
||||
try:
|
||||
try:
|
||||
self.assertEqual(ret['retcode'], 0)
|
||||
|
@ -433,18 +409,15 @@ class PipStateTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
)
|
||||
try:
|
||||
self.assertSaltTrueReturn(ret)
|
||||
self.assertInSaltReturn(
|
||||
'Installed',
|
||||
ret,
|
||||
['changes', 'pip==8.0.1']
|
||||
)
|
||||
self.assertSaltStateChangesEqual(
|
||||
ret, {'pip==8.0.1': 'Installed'})
|
||||
except AssertionError:
|
||||
import pprint
|
||||
pprint.pprint(ret)
|
||||
raise
|
||||
finally:
|
||||
if os.path.isdir(venv_dir):
|
||||
shutil.rmtree(venv_dir)
|
||||
shutil.rmtree(venv_dir, ignore_errors=True)
|
||||
|
||||
def test_pip_installed_specific_env(self):
|
||||
# Create the testing virtualenv
|
||||
|
@ -496,16 +469,14 @@ class PipStateTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
)
|
||||
finally:
|
||||
if os.path.isdir(venv_dir):
|
||||
shutil.rmtree(venv_dir)
|
||||
shutil.rmtree(venv_dir, ignore_errors=True)
|
||||
if os.path.isfile(requirements_file):
|
||||
os.unlink(requirements_file)
|
||||
|
||||
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(
|
||||
RUNTIME_VARS.TMP, 'pip-installed-unless'
|
||||
)
|
||||
venv_dir = os.path.join(RUNTIME_VARS.TMP, 'pip-installed-unless')
|
||||
venv_create = self.run_function('virtualenv.create', [venv_dir])
|
||||
if venv_create['retcode'] > 0:
|
||||
self.skipTest(
|
||||
|
@ -514,17 +485,21 @@ class PipStateTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
)
|
||||
)
|
||||
|
||||
false_cmd = '/bin/false'
|
||||
if salt.utils.is_windows():
|
||||
false_cmd = 'exit 1 >nul'
|
||||
try:
|
||||
ret = self.run_state(
|
||||
'pip.installed', name='pep8', bin_env=venv_dir, unless='/bin/false'
|
||||
'pip.installed', name='pep8', bin_env=venv_dir, unless=false_cmd
|
||||
)
|
||||
self.assertSaltTrueReturn(ret)
|
||||
self.assertNotIn('warnings', next(six.itervalues(ret)))
|
||||
finally:
|
||||
if os.path.isdir(venv_dir):
|
||||
shutil.rmtree(venv_dir)
|
||||
shutil.rmtree(venv_dir, ignore_errors=True)
|
||||
|
||||
@skipIf(sys.version_info[:2] >= (3, 6), 'Old version of virtualenv too old for python3.6')
|
||||
@skipIf(salt.utils.is_windows(), "Carbon does not install in Windows")
|
||||
def test_46127_pip_env_vars(self):
|
||||
'''
|
||||
Test that checks if env_vars passed to pip.installed are also passed
|
||||
|
@ -548,7 +523,7 @@ class PipStateTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
)
|
||||
finally:
|
||||
if os.path.isdir(ographite):
|
||||
shutil.rmtree(ographite)
|
||||
shutil.rmtree(ographite, ignore_errors=True)
|
||||
|
||||
venv_dir = os.path.join(RUNTIME_VARS.TMP, 'issue-46127-pip-env-vars')
|
||||
try:
|
||||
|
@ -557,7 +532,7 @@ class PipStateTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
# context when running the call to state.sls that comes after.
|
||||
self.run_function('saltutil.sync_modules')
|
||||
# Since we don't have the virtualenv created, pip.installed will
|
||||
# thrown and error.
|
||||
# throw an error.
|
||||
ret = self.run_function(
|
||||
'state.sls', mods='issue-46127-pip-env-vars'
|
||||
)
|
||||
|
@ -596,6 +571,6 @@ class PipStateTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
raise Exception('Expected state did not run')
|
||||
finally:
|
||||
if os.path.isdir(ographite):
|
||||
shutil.rmtree(ographite)
|
||||
shutil.rmtree(ographite, ignore_errors=True)
|
||||
if os.path.isdir(venv_dir):
|
||||
shutil.rmtree(venv_dir)
|
|
@ -29,6 +29,7 @@ import salt.ext.six as six
|
|||
from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin
|
||||
|
||||
from tests.support.unit import TestCase
|
||||
from tests.support.helpers import win32_kill_process_tree
|
||||
from tests.support.paths import CODE_DIR
|
||||
from tests.support.processes import terminate_process, terminate_process_list
|
||||
|
||||
|
@ -414,9 +415,6 @@ class TestProgram(six.with_metaclass(TestProgramMeta, object)):
|
|||
|
||||
popen_kwargs['preexec_fn'] = detach_from_parent_group
|
||||
|
||||
elif sys.platform.lower().startswith('win') and timeout is not None:
|
||||
raise RuntimeError('Timeout is not supported under windows')
|
||||
|
||||
self.argv = [self.program]
|
||||
self.argv.extend(args)
|
||||
log.debug('TestProgram.run: %s Environment %s', self.argv, env_delta)
|
||||
|
@ -431,16 +429,26 @@ class TestProgram(six.with_metaclass(TestProgramMeta, object)):
|
|||
|
||||
if datetime.now() > stop_at:
|
||||
if term_sent is False:
|
||||
# Kill the process group since sending the term signal
|
||||
# would only terminate the shell, not the command
|
||||
# executed in the shell
|
||||
os.killpg(os.getpgid(process.pid), signal.SIGINT)
|
||||
term_sent = True
|
||||
continue
|
||||
if salt.utils.is_windows():
|
||||
_, alive = win32_kill_process_tree(process.pid)
|
||||
if alive:
|
||||
log.error("Child processes still alive: %s", alive)
|
||||
else:
|
||||
# Kill the process group since sending the term signal
|
||||
# would only terminate the shell, not the command
|
||||
# executed in the shell
|
||||
os.killpg(os.getpgid(process.pid), signal.SIGINT)
|
||||
term_sent = True
|
||||
continue
|
||||
|
||||
try:
|
||||
# As a last resort, kill the process group
|
||||
os.killpg(os.getpgid(process.pid), signal.SIGKILL)
|
||||
if salt.utils.is_windows():
|
||||
_, alive = win32_kill_process_tree(process.pid)
|
||||
if alive:
|
||||
log.error("Child processes still alive: %s", alive)
|
||||
else:
|
||||
# As a last resort, kill the process group
|
||||
os.killpg(os.getpgid(process.pid), signal.SIGKILL)
|
||||
process.wait()
|
||||
except OSError as exc:
|
||||
if exc.errno != errno.ESRCH:
|
||||
|
|
|
@ -30,12 +30,15 @@ from datetime import datetime, timedelta
|
|||
|
||||
# Import salt testing libs
|
||||
from tests.support.unit import TestCase
|
||||
from tests.support.helpers import RedirectStdStreams, requires_sshd_server
|
||||
from tests.support.helpers import (
|
||||
RedirectStdStreams, requires_sshd_server, win32_kill_process_tree
|
||||
)
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
from tests.support.mixins import AdaptedConfigurationTestCaseMixin, SaltClientTestCaseMixin
|
||||
from tests.support.paths import ScriptPathMixin, INTEGRATION_TEST_DIR, CODE_DIR, PYEXEC, SCRIPT_DIR
|
||||
|
||||
# Import 3rd-party libs
|
||||
import salt.utils
|
||||
import salt.ext.six as six
|
||||
from salt.ext.six.moves import cStringIO # pylint: disable=import-error
|
||||
|
||||
|
@ -276,9 +279,6 @@ class ShellTestCase(TestCase, AdaptedConfigurationTestCaseMixin):
|
|||
|
||||
popen_kwargs['preexec_fn'] = detach_from_parent_group
|
||||
|
||||
elif sys.platform.lower().startswith('win') and timeout is not None:
|
||||
raise RuntimeError('Timeout is not supported under windows')
|
||||
|
||||
process = subprocess.Popen(cmd, **popen_kwargs)
|
||||
|
||||
if timeout is not None:
|
||||
|
@ -292,13 +292,23 @@ class ShellTestCase(TestCase, AdaptedConfigurationTestCaseMixin):
|
|||
# Kill the process group since sending the term signal
|
||||
# would only terminate the shell, not the command
|
||||
# executed in the shell
|
||||
os.killpg(os.getpgid(process.pid), signal.SIGINT)
|
||||
if salt.utils.is_windows():
|
||||
_, alive = win32_kill_process_tree(process.pid)
|
||||
if alive:
|
||||
log.error("Child processes still alive: %s", alive)
|
||||
else:
|
||||
os.killpg(os.getpgid(process.pid), signal.SIGINT)
|
||||
term_sent = True
|
||||
continue
|
||||
|
||||
try:
|
||||
# As a last resort, kill the process group
|
||||
os.killpg(os.getpgid(process.pid), signal.SIGKILL)
|
||||
if salt.utils.is_windows():
|
||||
_, alive = win32_kill_process_tree(process.pid)
|
||||
if alive:
|
||||
log.error("Child processes still alive: %s", alive)
|
||||
else:
|
||||
os.killpg(os.getpgid(process.pid), signal.SIGINT)
|
||||
except OSError as exc:
|
||||
if exc.errno != errno.ESRCH:
|
||||
# If errno is not "no such process", raise
|
||||
|
|
|
@ -19,6 +19,7 @@ import functools
|
|||
import inspect
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
import signal
|
||||
import socket
|
||||
import subprocess
|
||||
|
@ -52,6 +53,9 @@ from tests.support.unit import skip, _id
|
|||
from tests.support.mock import patch
|
||||
from tests.support.paths import FILES, TMP
|
||||
|
||||
# Import Salt libs
|
||||
import salt.utils
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -602,10 +606,10 @@ def requires_network(only_local_network=False):
|
|||
return decorator
|
||||
|
||||
|
||||
def with_system_user(username, on_existing='delete', delete=True):
|
||||
def with_system_user(username, on_existing='delete', delete=True, password=None):
|
||||
'''
|
||||
Create and optionally destroy a system user to be used within a test
|
||||
case. The system user is crated using the ``user`` salt module.
|
||||
case. The system user is created using the ``user`` salt module.
|
||||
|
||||
The decorated testcase function must accept 'username' as an argument.
|
||||
|
||||
|
@ -635,7 +639,10 @@ def with_system_user(username, on_existing='delete', delete=True):
|
|||
|
||||
# Let's add the user to the system.
|
||||
log.debug('Creating system user {0!r}'.format(username))
|
||||
create_user = cls.run_function('user.add', [username])
|
||||
kwargs = {'timeout': 60}
|
||||
if salt.utils.is_windows():
|
||||
kwargs.update({'password': password})
|
||||
create_user = cls.run_function('user.add', [username], **kwargs)
|
||||
if not create_user:
|
||||
log.debug('Failed to create system user')
|
||||
# The user was not created
|
||||
|
@ -691,7 +698,7 @@ def with_system_user(username, on_existing='delete', delete=True):
|
|||
finally:
|
||||
if delete:
|
||||
delete_user = cls.run_function(
|
||||
'user.delete', [username, True, True]
|
||||
'user.delete', [username, True, True], timeout=60
|
||||
)
|
||||
if not delete_user:
|
||||
if failure is None:
|
||||
|
@ -992,6 +999,32 @@ def with_tempfile(func):
|
|||
return wrapper
|
||||
|
||||
|
||||
class WithTempdir(object):
|
||||
def __init__(self, **kwargs):
|
||||
self.create = kwargs.pop('create', True)
|
||||
if 'dir' not in kwargs:
|
||||
kwargs['dir'] = TMP
|
||||
self.kwargs = kwargs
|
||||
|
||||
def __call__(self, func):
|
||||
self.func = func
|
||||
return functools.wraps(func)(
|
||||
lambda testcase, *args, **kwargs: self.wrap(testcase, *args, **kwargs) # pylint: disable=W0108
|
||||
)
|
||||
|
||||
def wrap(self, testcase, *args, **kwargs):
|
||||
tempdir = tempfile.mkdtemp(**self.kwargs)
|
||||
if not self.create:
|
||||
os.rmdir(tempdir)
|
||||
try:
|
||||
return self.func(testcase, tempdir, *args, **kwargs)
|
||||
finally:
|
||||
shutil.rmtree(tempdir, ignore_errors=True)
|
||||
|
||||
|
||||
with_tempdir = WithTempdir
|
||||
|
||||
|
||||
def requires_system_grains(func):
|
||||
'''
|
||||
Function decorator which loads and passes the system's grains to the test
|
||||
|
@ -1499,3 +1532,23 @@ class Webserver(object):
|
|||
'''
|
||||
self.ioloop.add_callback(self.ioloop.stop)
|
||||
self.server_thread.join()
|
||||
|
||||
|
||||
def win32_kill_process_tree(pid, sig=signal.SIGTERM, include_parent=True,
|
||||
timeout=None, on_terminate=None):
|
||||
'''
|
||||
Kill a process tree (including grandchildren) with signal "sig" and return
|
||||
a (gone, still_alive) tuple. "on_terminate", if specified, is a callabck
|
||||
function which is called as soon as a child terminates.
|
||||
'''
|
||||
if pid == os.getpid():
|
||||
raise RuntimeError("I refuse to kill myself")
|
||||
parent = psutil.Process(pid)
|
||||
children = parent.children(recursive=True)
|
||||
if include_parent:
|
||||
children.append(parent)
|
||||
for p in children:
|
||||
p.send_signal(sig)
|
||||
gone, alive = psutil.wait_procs(children, timeout=timeout,
|
||||
callback=on_terminate)
|
||||
return (gone, alive)
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
import os
|
||||
import sys
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
|
@ -26,9 +27,8 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(requirements='requirements.txt')
|
||||
expected_cmd = ['pip', 'install', '--requirement',
|
||||
'requirements.txt']
|
||||
mock.assert_called_once_with(
|
||||
expected_cmd = [sys.executable, '-m', 'pip', 'install', '--requirement', 'requirements.txt']
|
||||
mock.assert_called_with(
|
||||
expected_cmd,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
|
@ -51,7 +51,7 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting'
|
||||
]
|
||||
|
||||
expected = ['pip', 'install']
|
||||
expected = [sys.executable, '-m', 'pip', 'install']
|
||||
for item in editables:
|
||||
expected.extend(['--editable', item])
|
||||
|
||||
|
@ -59,7 +59,7 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(editable=editables)
|
||||
mock.assert_called_once_with(
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
|
@ -71,7 +71,7 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(editable=','.join(editables))
|
||||
mock.assert_called_once_with(
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
|
@ -86,7 +86,8 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting'
|
||||
]
|
||||
|
||||
expected = ['pip', 'install'] + pkgs
|
||||
expected = [sys.executable, '-m', 'pip', 'install']
|
||||
expected.extend(pkgs)
|
||||
for item in editables:
|
||||
expected.extend(['--editable', item])
|
||||
|
||||
|
@ -94,7 +95,7 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkgs=pkgs, editable=editables)
|
||||
mock.assert_called_once_with(
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
|
@ -106,7 +107,7 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkgs=','.join(pkgs), editable=','.join(editables))
|
||||
mock.assert_called_once_with(
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
|
@ -118,8 +119,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkgs=pkgs[0], editable=editables[0])
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'install', pkgs[0], '--editable', editables[0]],
|
||||
expected = [sys.executable, '-m', 'pip', 'install', pkgs[0], '--editable', editables[0]]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -137,7 +139,7 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'http://pypi.crate.io'
|
||||
]
|
||||
|
||||
expected = ['pip', 'install', '--use-mirrors']
|
||||
expected = [sys.executable, '-m', 'pip', 'install', '--use-mirrors']
|
||||
for item in mirrors:
|
||||
expected.extend(['--mirrors', item])
|
||||
expected.append('pep8')
|
||||
|
@ -146,7 +148,7 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkgs=['pep8'], mirrors=mirrors)
|
||||
mock.assert_called_once_with(
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
|
@ -158,7 +160,7 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkgs=['pep8'], mirrors=','.join(mirrors))
|
||||
mock.assert_called_once_with(
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
|
@ -166,12 +168,14 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
python_shell=False,
|
||||
)
|
||||
|
||||
expected = [sys.executable, '-m', 'pip', 'install', '--use-mirrors', '--mirrors', mirrors[0], 'pep8']
|
||||
|
||||
# As single string (just use the first element from mirrors)
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkgs=['pep8'], mirrors=mirrors[0])
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'install', '--use-mirrors', '--mirrors', mirrors[0], 'pep8'],
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -186,7 +190,7 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
]
|
||||
pkg = 'pep8'
|
||||
|
||||
expected = ['pip', 'install']
|
||||
expected = [sys.executable, '-m', 'pip', 'install']
|
||||
for item in find_links:
|
||||
expected.extend(['--find-links', item])
|
||||
expected.append(pkg)
|
||||
|
@ -195,7 +199,7 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, find_links=find_links)
|
||||
mock.assert_called_once_with(
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
|
@ -207,7 +211,7 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, find_links=','.join(find_links))
|
||||
mock.assert_called_once_with(
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
|
@ -215,12 +219,26 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
python_shell=False,
|
||||
)
|
||||
|
||||
# Valid protos work?
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, find_links=find_links)
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
python_shell=False,
|
||||
)
|
||||
|
||||
expected = [sys.executable, '-m', 'pip', 'install', '--find-links', find_links[0], pkg]
|
||||
|
||||
# As single string (just use the first element from find_links)
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, find_links=find_links[0])
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'install', '--find-links', find_links[0], pkg],
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -237,18 +255,6 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
find_links='sftp://pypi.crate.io'
|
||||
)
|
||||
|
||||
# Valid protos work?
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, find_links=find_links)
|
||||
mock.assert_called_once_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
python_shell=False,
|
||||
)
|
||||
|
||||
def test_install_no_index_with_index_url_or_extra_index_url_raises(self):
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
|
@ -277,8 +283,8 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(requirements='salt://requirements.txt')
|
||||
expected = ['pip', 'install', '--requirement', 'my_cached_reqs']
|
||||
mock.assert_called_once_with(
|
||||
expected = [sys.executable, '-m', 'pip', 'install', '--requirement', 'my_cached_reqs']
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
|
@ -288,28 +294,29 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
|
||||
def test_install_venv(self):
|
||||
with patch('os.path') as mock_path:
|
||||
mock_path.is_file.return_value = True
|
||||
mock_path.isdir.return_value = True
|
||||
|
||||
pkg = 'mock'
|
||||
|
||||
def join(*args):
|
||||
return os.sep.join(args)
|
||||
return os.path.normpath(os.sep.join(args))
|
||||
|
||||
mock_path.is_file.return_value = True
|
||||
mock_path.isdir.return_value = True
|
||||
mock_path.join = join
|
||||
|
||||
if salt.utils.is_windows():
|
||||
venv_path = 'C:\\test_env'
|
||||
bin_path = os.path.join(venv_path, 'python.exe')
|
||||
else:
|
||||
venv_path = '/test_env'
|
||||
bin_path = os.path.join(venv_path, 'python')
|
||||
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
if salt.utils.is_windows():
|
||||
venv_path = 'c:\\test_env'
|
||||
bin_path = os.path.join(venv_path, 'Scripts', 'pip.exe')
|
||||
if salt.ext.six.PY2:
|
||||
bin_path = bin_path.encode('string-escape')
|
||||
else:
|
||||
venv_path = '/test_env'
|
||||
bin_path = os.path.join(venv_path, 'bin', 'pip')
|
||||
pip.install(pkg, bin_env=venv_path)
|
||||
mock.assert_called_once_with(
|
||||
[bin_path, 'install', pkg],
|
||||
pip_bin = MagicMock(return_value=[bin_path, '-m', 'pip'])
|
||||
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}), \
|
||||
patch.object(pip, '_get_pip_bin', pip_bin):
|
||||
pip.install('mock', bin_env=venv_path)
|
||||
mock.assert_called_with(
|
||||
[bin_path, '-m', 'pip', 'install', 'mock'],
|
||||
env={'VIRTUAL_ENV': venv_path},
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
|
@ -324,8 +331,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, log=log_path)
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'install', '--log', log_path, pkg],
|
||||
expected = [sys.executable, '-m', 'pip', 'install', '--log', log_path, pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -350,12 +358,12 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
def test_install_timeout_argument_in_resulting_command(self):
|
||||
# Passing an int
|
||||
pkg = 'pep8'
|
||||
expected_prefix = ['pip', 'install', '--timeout']
|
||||
expected = [sys.executable, '-m', 'pip', 'install', '--timeout']
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, timeout=10)
|
||||
mock.assert_called_once_with(
|
||||
expected_prefix + [10, pkg],
|
||||
mock.assert_called_with(
|
||||
expected + [10, pkg],
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -366,8 +374,8 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, timeout='10')
|
||||
mock.assert_called_once_with(
|
||||
expected_prefix + ['10', pkg],
|
||||
mock.assert_called_with(
|
||||
expected + ['10', pkg],
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -390,8 +398,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, index_url=index_url)
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'install', '--index-url', index_url, pkg],
|
||||
expected = [sys.executable, '-m', 'pip', 'install', '--index-url', index_url, pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -404,8 +413,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, extra_index_url=extra_index_url)
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'install', '--extra-index-url', extra_index_url, pkg],
|
||||
expected = [sys.executable, '-m', 'pip', 'install', '--extra-index-url', extra_index_url, pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -417,8 +427,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, no_index=True)
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'install', '--no-index', pkg],
|
||||
expected = [sys.executable, '-m', 'pip', 'install', '--no-index', pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -431,8 +442,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, build=build)
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'install', '--build', build, pkg],
|
||||
expected = [sys.executable, '-m', 'pip', 'install', '--build', build, pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -445,8 +457,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, target=target)
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'install', '--target', target, pkg],
|
||||
expected = [sys.executable, '-m', 'pip', 'install', '--target', target, pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -459,8 +472,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, download=download)
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'install', '--download', download, pkg],
|
||||
expected = [sys.executable, '-m', 'pip', 'install', '--download', download, pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -472,8 +486,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, no_download=True)
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'install', '--no-download', pkg],
|
||||
expected = [sys.executable, '-m', 'pip', 'install', '--no-download', pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -495,8 +510,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
MagicMock(return_value=pip_version)):
|
||||
# test `download_cache` kwarg
|
||||
pip.install(pkg, download_cache='/tmp/foo')
|
||||
expected = [sys.executable, '-m', 'pip', 'install', cmd_arg, download_cache, pkg]
|
||||
mock.assert_called_with(
|
||||
['pip', 'install', cmd_arg, download_cache, pkg],
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -506,7 +522,7 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
# test `cache_dir` kwarg
|
||||
pip.install(pkg, cache_dir='/tmp/foo')
|
||||
mock.assert_called_with(
|
||||
['pip', 'install', cmd_arg, download_cache, pkg],
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -519,8 +535,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, source=source)
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'install', '--source', source, pkg],
|
||||
expected = [sys.executable, '-m', 'pip', 'install', '--source', source, pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -532,9 +549,10 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
for action in ('s', 'i', 'w', 'b'):
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install('pep8', exists_action=action)
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'install', '--exists-action', action, pkg],
|
||||
pip.install(pkg, exists_action=action)
|
||||
expected = [sys.executable, '-m', 'pip', 'install', '--exists-action', action, pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -558,7 +576,7 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
]
|
||||
pkg = 'pep8'
|
||||
|
||||
expected = ['pip', 'install']
|
||||
expected = [sys.executable, '-m', 'pip', 'install']
|
||||
for item in install_options:
|
||||
expected.extend(['--install-option', item])
|
||||
expected.append(pkg)
|
||||
|
@ -567,7 +585,7 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, install_options=install_options)
|
||||
mock.assert_called_once_with(
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
|
@ -579,7 +597,7 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, install_options=','.join(install_options))
|
||||
mock.assert_called_once_with(
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
|
@ -591,9 +609,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, install_options=install_options[0])
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'install', '--install-option',
|
||||
install_options[0], pkg],
|
||||
expected = [sys.executable, '-m', 'pip', 'install', '--install-option', install_options[0], pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -607,7 +625,7 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
]
|
||||
pkg = 'pep8'
|
||||
|
||||
expected = ['pip', 'install']
|
||||
expected = [sys.executable, '-m', 'pip', 'install']
|
||||
for item in global_options:
|
||||
expected.extend(['--global-option', item])
|
||||
expected.append(pkg)
|
||||
|
@ -616,7 +634,7 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, global_options=global_options)
|
||||
mock.assert_called_once_with(
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
|
@ -628,7 +646,7 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, global_options=','.join(global_options))
|
||||
mock.assert_called_once_with(
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
|
@ -640,8 +658,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, global_options=global_options[0])
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'install', '--global-option', global_options[0], pkg],
|
||||
expected = [sys.executable, '-m', 'pip', 'install', '--global-option', global_options[0], pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -653,8 +672,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, upgrade=True)
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'install', '--upgrade', pkg],
|
||||
expected = [sys.executable, '-m', 'pip', 'install', '--upgrade', pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -666,8 +686,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, force_reinstall=True)
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'install', '--force-reinstall', pkg],
|
||||
expected = [sys.executable, '-m', 'pip', 'install', '--force-reinstall', pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -679,8 +700,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, ignore_installed=True)
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'install', '--ignore-installed', pkg],
|
||||
expected = [sys.executable, '-m', 'pip', 'install', '--ignore-installed', pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -692,8 +714,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, no_deps=True)
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'install', '--no-deps', pkg],
|
||||
expected = [sys.executable, '-m', 'pip', 'install', '--no-deps', pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -705,8 +728,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, no_install=True)
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'install', '--no-install', pkg],
|
||||
expected = [sys.executable, '-m', 'pip', 'install', '--no-install', pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -719,8 +743,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(pkg, proxy=proxy)
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'install', '--proxy', proxy, pkg],
|
||||
expected = [sys.executable, '-m', 'pip', 'install', '--proxy', proxy, pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -737,7 +762,7 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'salt://requirements-1.txt', 'salt://requirements-2.txt'
|
||||
]
|
||||
|
||||
expected = ['pip', 'install']
|
||||
expected = [sys.executable, '-m', 'pip', 'install']
|
||||
for item in cached_reqs:
|
||||
expected.extend(['--requirement', item])
|
||||
|
||||
|
@ -745,7 +770,7 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(requirements=requirements)
|
||||
mock.assert_called_once_with(
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
|
@ -758,7 +783,7 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(requirements=','.join(requirements))
|
||||
mock.assert_called_once_with(
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
|
@ -771,8 +796,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.install(requirements=requirements[0])
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'install', '--requirement', cached_reqs[0]],
|
||||
expected = [sys.executable, '-m', 'pip', 'install', '--requirement', cached_reqs[0]]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -789,7 +815,7 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
'salt://requirements-1.txt', 'salt://requirements-2.txt'
|
||||
]
|
||||
|
||||
expected = ['pip', 'uninstall', '-y']
|
||||
expected = [sys.executable, '-m', 'pip', 'uninstall', '-y']
|
||||
for item in cached_reqs:
|
||||
expected.extend(['--requirement', item])
|
||||
|
||||
|
@ -797,7 +823,7 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.uninstall(requirements=requirements)
|
||||
mock.assert_called_once_with(
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
cwd=None,
|
||||
saltenv='base',
|
||||
|
@ -811,7 +837,7 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.uninstall(requirements=','.join(requirements))
|
||||
mock.assert_called_once_with(
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
cwd=None,
|
||||
saltenv='base',
|
||||
|
@ -825,8 +851,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.uninstall(requirements=requirements[0])
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'uninstall', '-y', '--requirement', cached_reqs[0]],
|
||||
expected = [sys.executable, '-m', 'pip', 'uninstall', '-y', '--requirement', cached_reqs[0]]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
cwd=None,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
|
@ -840,8 +867,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.uninstall(pkg, proxy=proxy)
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'uninstall', '-y', '--proxy', proxy, pkg],
|
||||
expected = [sys.executable, '-m', 'pip', 'uninstall', '-y', '--proxy', proxy, pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
cwd=None,
|
||||
runas=None,
|
||||
|
@ -850,22 +878,24 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
)
|
||||
|
||||
def test_uninstall_log_argument_in_resulting_command(self):
|
||||
with patch('os.path') as mock_path:
|
||||
pkg = 'pep8'
|
||||
log_path = '/tmp/pip-install.log'
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.uninstall(pkg, log=log_path)
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'uninstall', '-y', '--log', log_path, pkg],
|
||||
saltenv='base',
|
||||
cwd=None,
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
python_shell=False,
|
||||
)
|
||||
pkg = 'pep8'
|
||||
log_path = '/tmp/pip-install.log'
|
||||
|
||||
# Let's fake a non-writable log file
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.uninstall(pkg, log=log_path)
|
||||
expected = [sys.executable, '-m', 'pip', 'uninstall', '-y', '--log', log_path, pkg]
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
saltenv='base',
|
||||
cwd=None,
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
python_shell=False,
|
||||
)
|
||||
|
||||
# Let's fake a non-writable log file
|
||||
with patch('os.path') as mock_path:
|
||||
mock_path.exists.side_effect = IOError('Fooo!')
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
|
@ -878,13 +908,13 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
|
||||
def test_uninstall_timeout_argument_in_resulting_command(self):
|
||||
pkg = 'pep8'
|
||||
expected_prefix = ['pip', 'uninstall', '-y', '--timeout']
|
||||
expected = [sys.executable, '-m', 'pip', 'uninstall', '-y', '--timeout']
|
||||
# Passing an int
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.uninstall(pkg, timeout=10)
|
||||
mock.assert_called_once_with(
|
||||
expected_prefix + [10, pkg],
|
||||
mock.assert_called_with(
|
||||
expected + [10, pkg],
|
||||
cwd=None,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
|
@ -896,8 +926,8 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(pip.__salt__, {'cmd.run_all': mock}):
|
||||
pip.uninstall(pkg, timeout='10')
|
||||
mock.assert_called_once_with(
|
||||
expected_prefix + ['10', pkg],
|
||||
mock.assert_called_with(
|
||||
expected + ['10', pkg],
|
||||
cwd=None,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
|
@ -916,6 +946,7 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
)
|
||||
|
||||
def test_freeze_command(self):
|
||||
expected = [sys.executable, '-m', 'pip', 'freeze']
|
||||
eggs = [
|
||||
'M2Crypto==0.21.1',
|
||||
'-e git+git@github.com:s0undt3ch/salt-testing.git@9ed81aa2f918d59d3706e56b18f0782d1ea43bf8#egg=SaltTesting-dev',
|
||||
|
@ -933,8 +964,8 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch('salt.modules.pip.version',
|
||||
MagicMock(return_value='6.1.1')):
|
||||
ret = pip.freeze()
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'freeze'],
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
cwd=None,
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -953,8 +984,8 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch('salt.modules.pip.version',
|
||||
MagicMock(return_value='6.1.1')):
|
||||
ret = pip.freeze(env_vars={"foo": "bar"})
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'freeze'],
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
cwd=None,
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -993,8 +1024,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch('salt.modules.pip.version',
|
||||
MagicMock(return_value='9.0.1')):
|
||||
ret = pip.freeze()
|
||||
mock.assert_called_once_with(
|
||||
['pip', 'freeze', '--all'],
|
||||
expected = [sys.executable, '-m', 'pip', 'freeze', '--all']
|
||||
mock.assert_called_with(
|
||||
expected,
|
||||
cwd=None,
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -1026,8 +1058,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch('salt.modules.pip.version',
|
||||
MagicMock(return_value=mock_version)):
|
||||
ret = pip.list_()
|
||||
expected = [sys.executable, '-m', 'pip', 'freeze']
|
||||
mock.assert_called_with(
|
||||
['pip', 'freeze'],
|
||||
expected,
|
||||
cwd=None,
|
||||
runas=None,
|
||||
python_shell=False,
|
||||
|
@ -1073,8 +1106,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch('salt.modules.pip.version',
|
||||
MagicMock(return_value=mock_version)):
|
||||
ret = pip.list_()
|
||||
expected = [sys.executable, '-m', 'pip', 'freeze', '--all']
|
||||
mock.assert_called_with(
|
||||
['pip', 'freeze', '--all'],
|
||||
expected,
|
||||
cwd=None,
|
||||
runas=None,
|
||||
python_shell=False,
|
||||
|
@ -1120,8 +1154,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch('salt.modules.pip.version',
|
||||
MagicMock(return_value='6.1.1')):
|
||||
ret = pip.list_(prefix='bb')
|
||||
expected = [sys.executable, '-m', 'pip', 'freeze']
|
||||
mock.assert_called_with(
|
||||
['pip', 'freeze'],
|
||||
expected,
|
||||
cwd=None,
|
||||
runas=None,
|
||||
python_shell=False,
|
||||
|
@ -1146,8 +1181,9 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch('salt.modules.pip.version',
|
||||
MagicMock(return_value='1.3')):
|
||||
pip.install(pkg, pre_releases=True)
|
||||
expected = [sys.executable, '-m', 'pip', 'install', pkg]
|
||||
mock.assert_called_with(
|
||||
['pip', 'install', pkg],
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
@ -1159,10 +1195,11 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
|
|||
with patch.dict(pip.__salt__, {'cmd.run': mock_run,
|
||||
'cmd.run_all': mock_run_all}):
|
||||
with patch('salt.modules.pip._get_pip_bin',
|
||||
MagicMock(return_value='pip')):
|
||||
MagicMock(return_value=['pip'])):
|
||||
pip.install(pkg, pre_releases=True)
|
||||
expected = ['pip', 'install', '--pre', pkg]
|
||||
mock_run_all.assert_called_with(
|
||||
['pip', 'install', '--pre', pkg],
|
||||
expected,
|
||||
saltenv='base',
|
||||
runas=None,
|
||||
use_vt=False,
|
||||
|
|
|
@ -1,294 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
:codeauthor: :email:`Pedro Algarvio (pedro@algarvio.me)`
|
||||
|
||||
|
||||
tests.unit.states.pip_test
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin, SaltReturnAssertsMixin
|
||||
from tests.support.unit import skipIf, TestCase
|
||||
from tests.support.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch
|
||||
|
||||
# Import salt libs
|
||||
import salt.states.pip_state as pip_state
|
||||
|
||||
# Import 3rd-party libs
|
||||
try:
|
||||
import pip
|
||||
HAS_PIP = True
|
||||
except ImportError:
|
||||
HAS_PIP = False
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
@skipIf(not HAS_PIP,
|
||||
'The \'pip\' library is not importable(installed system-wide)')
|
||||
class PipStateTest(TestCase, SaltReturnAssertsMixin, LoaderModuleMockMixin):
|
||||
|
||||
def setup_loader_modules(self):
|
||||
return {
|
||||
pip_state: {
|
||||
'__env__': 'base',
|
||||
'__opts__': {'test': False},
|
||||
'__salt__': {'cmd.which_bin': lambda _: 'pip'}
|
||||
}
|
||||
}
|
||||
|
||||
def test_install_requirements_parsing(self):
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={'pep8': '1.3.3'})
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list}):
|
||||
with patch.dict(pip_state.__opts__, {'test': True}):
|
||||
ret = pip_state.installed('pep8=1.3.2')
|
||||
self.assertSaltFalseReturn({'test': ret})
|
||||
self.assertInSaltComment(
|
||||
'Invalid version specification in package pep8=1.3.2. '
|
||||
'\'=\' is not supported, use \'==\' instead.',
|
||||
{'test': ret}
|
||||
)
|
||||
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={'pep8': '1.3.3'})
|
||||
pip_install = MagicMock(return_value={'retcode': 0})
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list,
|
||||
'pip.install': pip_install}):
|
||||
with patch.dict(pip_state.__opts__, {'test': True}):
|
||||
ret = pip_state.installed('pep8>=1.3.2')
|
||||
self.assertSaltTrueReturn({'test': ret})
|
||||
self.assertInSaltComment(
|
||||
'Python package pep8>=1.3.2 was already installed',
|
||||
{'test': ret}
|
||||
)
|
||||
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={'pep8': '1.3.3'})
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list}):
|
||||
with patch.dict(pip_state.__opts__, {'test': True}):
|
||||
ret = pip_state.installed('pep8<1.3.2')
|
||||
self.assertSaltNoneReturn({'test': ret})
|
||||
self.assertInSaltComment(
|
||||
'Python package pep8<1.3.2 is set to be installed',
|
||||
{'test': ret}
|
||||
)
|
||||
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={'pep8': '1.3.2'})
|
||||
pip_install = MagicMock(return_value={'retcode': 0})
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list,
|
||||
'pip.install': pip_install}):
|
||||
with patch.dict(pip_state.__opts__, {'test': True}):
|
||||
ret = pip_state.installed('pep8>1.3.1,<1.3.3')
|
||||
self.assertSaltTrueReturn({'test': ret})
|
||||
self.assertInSaltComment(
|
||||
'Python package pep8>1.3.1,<1.3.3 was already installed',
|
||||
{'test': ret}
|
||||
)
|
||||
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={'pep8': '1.3.1'})
|
||||
pip_install = MagicMock(return_value={'retcode': 0})
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list,
|
||||
'pip.install': pip_install}):
|
||||
with patch.dict(pip_state.__opts__, {'test': True}):
|
||||
ret = pip_state.installed('pep8>1.3.1,<1.3.3')
|
||||
self.assertSaltNoneReturn({'test': ret})
|
||||
self.assertInSaltComment(
|
||||
'Python package pep8>1.3.1,<1.3.3 is set to be installed',
|
||||
{'test': ret}
|
||||
)
|
||||
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={'pep8': '1.3.1'})
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list}):
|
||||
with patch.dict(pip_state.__opts__, {'test': True}):
|
||||
ret = pip_state.installed(
|
||||
'git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting>=0.5.1'
|
||||
)
|
||||
self.assertSaltNoneReturn({'test': ret})
|
||||
self.assertInSaltComment(
|
||||
'Python package git+https://github.com/saltstack/'
|
||||
'salt-testing.git#egg=SaltTesting>=0.5.1 is set to be '
|
||||
'installed',
|
||||
{'test': ret}
|
||||
)
|
||||
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={'pep8': '1.3.1'})
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list}):
|
||||
with patch.dict(pip_state.__opts__, {'test': True}):
|
||||
ret = pip_state.installed(
|
||||
'git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting'
|
||||
)
|
||||
self.assertSaltNoneReturn({'test': ret})
|
||||
self.assertInSaltComment(
|
||||
'Python package git+https://github.com/saltstack/'
|
||||
'salt-testing.git#egg=SaltTesting is set to be '
|
||||
'installed',
|
||||
{'test': ret}
|
||||
)
|
||||
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={'pep8': '1.3.1'})
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list}):
|
||||
with patch.dict(pip_state.__opts__, {'test': True}):
|
||||
ret = pip_state.installed(
|
||||
'https://pypi.python.org/packages/source/S/SaltTesting/'
|
||||
'SaltTesting-0.5.0.tar.gz'
|
||||
'#md5=e6760af92b7165f8be53b5763e40bc24'
|
||||
)
|
||||
self.assertSaltNoneReturn({'test': ret})
|
||||
self.assertInSaltComment(
|
||||
'Python package https://pypi.python.org/packages/source/'
|
||||
'S/SaltTesting/SaltTesting-0.5.0.tar.gz'
|
||||
'#md5=e6760af92b7165f8be53b5763e40bc24 is set to be '
|
||||
'installed',
|
||||
{'test': ret}
|
||||
)
|
||||
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={'SaltTesting': '0.5.0'})
|
||||
pip_install = MagicMock(return_value={
|
||||
'retcode': 0,
|
||||
'stderr': '',
|
||||
'stdout': 'Downloading/unpacking https://pypi.python.org/packages'
|
||||
'/source/S/SaltTesting/SaltTesting-0.5.0.tar.gz\n '
|
||||
'Downloading SaltTesting-0.5.0.tar.gz\n Running '
|
||||
'setup.py egg_info for package from '
|
||||
'https://pypi.python.org/packages/source/S/SaltTesting/'
|
||||
'SaltTesting-0.5.0.tar.gz\n \nCleaning up...'
|
||||
})
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list,
|
||||
'pip.install': pip_install}):
|
||||
ret = pip_state.installed(
|
||||
'https://pypi.python.org/packages/source/S/SaltTesting/'
|
||||
'SaltTesting-0.5.0.tar.gz'
|
||||
'#md5=e6760af92b7165f8be53b5763e40bc24'
|
||||
)
|
||||
self.assertSaltTrueReturn({'test': ret})
|
||||
self.assertInSaltComment('All packages were successfully installed',
|
||||
{'test': ret}
|
||||
)
|
||||
self.assertInSaltReturn(
|
||||
'Installed',
|
||||
{'test': ret},
|
||||
('changes', 'https://pypi.python.org/packages/source/S/'
|
||||
'SaltTesting/SaltTesting-0.5.0.tar.gz'
|
||||
'#md5=e6760af92b7165f8be53b5763e40bc24==???')
|
||||
)
|
||||
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={'SaltTesting': '0.5.0'})
|
||||
pip_install = MagicMock(return_value={
|
||||
'retcode': 0,
|
||||
'stderr': '',
|
||||
'stdout': 'Cloned!'
|
||||
})
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list,
|
||||
'pip.install': pip_install}):
|
||||
with patch.dict(pip_state.__opts__, {'test': False}):
|
||||
ret = pip_state.installed(
|
||||
'git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting'
|
||||
)
|
||||
self.assertSaltTrueReturn({'test': ret})
|
||||
self.assertInSaltComment(
|
||||
'packages are already installed',
|
||||
{'test': ret}
|
||||
)
|
||||
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={'pep8': '1.3.1'})
|
||||
pip_install = MagicMock(return_value={'retcode': 0})
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list,
|
||||
'pip.install': pip_install}):
|
||||
with patch.dict(pip_state.__opts__, {'test': False}):
|
||||
ret = pip_state.installed(
|
||||
'arbitrary ID that should be ignored due to requirements specified',
|
||||
requirements='/tmp/non-existing-requirements.txt'
|
||||
)
|
||||
self.assertSaltTrueReturn({'test': ret})
|
||||
|
||||
# Test VCS installations using git+git://
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={'SaltTesting': '0.5.0'})
|
||||
pip_install = MagicMock(return_value={
|
||||
'retcode': 0,
|
||||
'stderr': '',
|
||||
'stdout': 'Cloned!'
|
||||
})
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list,
|
||||
'pip.install': pip_install}):
|
||||
with patch.dict(pip_state.__opts__, {'test': False}):
|
||||
ret = pip_state.installed(
|
||||
'git+git://github.com/saltstack/salt-testing.git#egg=SaltTesting'
|
||||
)
|
||||
self.assertSaltTrueReturn({'test': ret})
|
||||
self.assertInSaltComment(
|
||||
'packages are already installed',
|
||||
{'test': ret}
|
||||
)
|
||||
|
||||
# Test VCS installations with version info like >= 0.1
|
||||
with patch.object(pip, '__version__', MagicMock(side_effect=AttributeError(
|
||||
'Faked missing __version__ attribute'))):
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={'SaltTesting': '0.5.0'})
|
||||
pip_install = MagicMock(return_value={
|
||||
'retcode': 0,
|
||||
'stderr': '',
|
||||
'stdout': 'Cloned!'
|
||||
})
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list,
|
||||
'pip.install': pip_install}):
|
||||
with patch.dict(pip_state.__opts__, {'test': False}):
|
||||
ret = pip_state.installed(
|
||||
'git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting>=0.5.0'
|
||||
)
|
||||
self.assertSaltTrueReturn({'test': ret})
|
||||
self.assertInSaltComment(
|
||||
'packages are already installed',
|
||||
{'test': ret}
|
||||
)
|
||||
|
||||
def test_install_in_editable_mode(self):
|
||||
'''
|
||||
Check that `name` parameter containing bad characters is not parsed by
|
||||
pip when package is being installed in editable mode.
|
||||
For more information, see issue #21890.
|
||||
'''
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={})
|
||||
pip_install = MagicMock(return_value={
|
||||
'retcode': 0,
|
||||
'stderr': '',
|
||||
'stdout': 'Cloned!'
|
||||
})
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list,
|
||||
'pip.install': pip_install}):
|
||||
ret = pip_state.installed('state@name',
|
||||
cwd='/path/to/project',
|
||||
editable=['.'])
|
||||
self.assertSaltTrueReturn({'test': ret})
|
||||
self.assertInSaltComment(
|
||||
'successfully installed',
|
||||
{'test': ret}
|
||||
)
|
306
tests/unit/states/test_pip_state.py
Normal file
306
tests/unit/states/test_pip_state.py
Normal file
|
@ -0,0 +1,306 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
:codeauthor: :email:`Pedro Algarvio (pedro@algarvio.me)`
|
||||
|
||||
|
||||
tests.unit.states.pip_test
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin, SaltReturnAssertsMixin
|
||||
from tests.support.unit import skipIf, TestCase
|
||||
from tests.support.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch
|
||||
|
||||
# Import salt libs
|
||||
import salt.states.pip_state as pip_state
|
||||
import salt.utils
|
||||
|
||||
# Import 3rd-party libs
|
||||
try:
|
||||
import pip
|
||||
HAS_PIP = True
|
||||
except ImportError:
|
||||
HAS_PIP = False
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
@skipIf(not HAS_PIP,
|
||||
'The \'pip\' library is not importable(installed system-wide)')
|
||||
class PipStateTest(TestCase, SaltReturnAssertsMixin, LoaderModuleMockMixin):
|
||||
|
||||
def setup_loader_modules(self):
|
||||
return {
|
||||
pip_state: {
|
||||
'__env__': 'base',
|
||||
'__opts__': {'test': False},
|
||||
'__salt__': {'cmd.which_bin': lambda _: 'pip'}
|
||||
}
|
||||
}
|
||||
|
||||
def test_install_requirements_parsing(self):
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={'pep8': '1.3.3'})
|
||||
pip_version = pip.__version__
|
||||
mock_pip_version = MagicMock(return_value=pip_version)
|
||||
with patch.dict(pip_state.__salt__, {'pip.version': mock_pip_version}):
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list}):
|
||||
with patch.dict(pip_state.__opts__, {'test': True}):
|
||||
if salt.utils.compare_versions(ver1=pip_version,
|
||||
oper='<',
|
||||
ver2='10.0'):
|
||||
ret = pip_state.installed('pep8=1.3.2')
|
||||
self.assertSaltFalseReturn({'test': ret})
|
||||
self.assertInSaltComment(
|
||||
'Invalid version specification in package pep8=1.3.2. '
|
||||
'\'=\' is not supported, use \'==\' instead.',
|
||||
{'test': ret})
|
||||
else:
|
||||
self.assertRaises(
|
||||
pip._internal.exceptions.InstallationError,
|
||||
pip_state.installed, 'pep=1.3.2')
|
||||
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={'pep8': '1.3.3'})
|
||||
pip_install = MagicMock(return_value={'retcode': 0})
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list,
|
||||
'pip.install': pip_install}):
|
||||
with patch.dict(pip_state.__opts__, {'test': True}):
|
||||
ret = pip_state.installed('pep8>=1.3.2')
|
||||
self.assertSaltTrueReturn({'test': ret})
|
||||
self.assertInSaltComment(
|
||||
'Python package pep8>=1.3.2 was already installed',
|
||||
{'test': ret}
|
||||
)
|
||||
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={'pep8': '1.3.3'})
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list}):
|
||||
with patch.dict(pip_state.__opts__, {'test': True}):
|
||||
ret = pip_state.installed('pep8<1.3.2')
|
||||
self.assertSaltNoneReturn({'test': ret})
|
||||
self.assertInSaltComment(
|
||||
'Python package pep8<1.3.2 is set to be installed',
|
||||
{'test': ret}
|
||||
)
|
||||
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={'pep8': '1.3.2'})
|
||||
pip_install = MagicMock(return_value={'retcode': 0})
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list,
|
||||
'pip.install': pip_install}):
|
||||
with patch.dict(pip_state.__opts__, {'test': True}):
|
||||
ret = pip_state.installed('pep8>1.3.1,<1.3.3')
|
||||
self.assertSaltTrueReturn({'test': ret})
|
||||
self.assertInSaltComment(
|
||||
'Python package pep8>1.3.1,<1.3.3 was already installed',
|
||||
{'test': ret}
|
||||
)
|
||||
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={'pep8': '1.3.1'})
|
||||
pip_install = MagicMock(return_value={'retcode': 0})
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list,
|
||||
'pip.install': pip_install}):
|
||||
with patch.dict(pip_state.__opts__, {'test': True}):
|
||||
ret = pip_state.installed('pep8>1.3.1,<1.3.3')
|
||||
self.assertSaltNoneReturn({'test': ret})
|
||||
self.assertInSaltComment(
|
||||
'Python package pep8>1.3.1,<1.3.3 is set to be installed',
|
||||
{'test': ret}
|
||||
)
|
||||
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={'pep8': '1.3.1'})
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list}):
|
||||
with patch.dict(pip_state.__opts__, {'test': True}):
|
||||
ret = pip_state.installed(
|
||||
'git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting>=0.5.1'
|
||||
)
|
||||
self.assertSaltNoneReturn({'test': ret})
|
||||
self.assertInSaltComment(
|
||||
'Python package git+https://github.com/saltstack/'
|
||||
'salt-testing.git#egg=SaltTesting>=0.5.1 is set to be '
|
||||
'installed',
|
||||
{'test': ret}
|
||||
)
|
||||
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={'pep8': '1.3.1'})
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list}):
|
||||
with patch.dict(pip_state.__opts__, {'test': True}):
|
||||
ret = pip_state.installed(
|
||||
'git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting'
|
||||
)
|
||||
self.assertSaltNoneReturn({'test': ret})
|
||||
self.assertInSaltComment(
|
||||
'Python package git+https://github.com/saltstack/'
|
||||
'salt-testing.git#egg=SaltTesting is set to be '
|
||||
'installed',
|
||||
{'test': ret}
|
||||
)
|
||||
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={'pep8': '1.3.1'})
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list}):
|
||||
with patch.dict(pip_state.__opts__, {'test': True}):
|
||||
ret = pip_state.installed(
|
||||
'https://pypi.python.org/packages/source/S/SaltTesting/'
|
||||
'SaltTesting-0.5.0.tar.gz'
|
||||
'#md5=e6760af92b7165f8be53b5763e40bc24'
|
||||
)
|
||||
self.assertSaltNoneReturn({'test': ret})
|
||||
self.assertInSaltComment(
|
||||
'Python package https://pypi.python.org/packages/source/'
|
||||
'S/SaltTesting/SaltTesting-0.5.0.tar.gz'
|
||||
'#md5=e6760af92b7165f8be53b5763e40bc24 is set to be '
|
||||
'installed',
|
||||
{'test': ret}
|
||||
)
|
||||
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={'SaltTesting': '0.5.0'})
|
||||
pip_install = MagicMock(return_value={
|
||||
'retcode': 0,
|
||||
'stderr': '',
|
||||
'stdout': 'Downloading/unpacking https://pypi.python.org/packages'
|
||||
'/source/S/SaltTesting/SaltTesting-0.5.0.tar.gz\n '
|
||||
'Downloading SaltTesting-0.5.0.tar.gz\n Running '
|
||||
'setup.py egg_info for package from '
|
||||
'https://pypi.python.org/packages/source/S/SaltTesting/'
|
||||
'SaltTesting-0.5.0.tar.gz\n \nCleaning up...'
|
||||
})
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list,
|
||||
'pip.install': pip_install}):
|
||||
ret = pip_state.installed(
|
||||
'https://pypi.python.org/packages/source/S/SaltTesting/'
|
||||
'SaltTesting-0.5.0.tar.gz'
|
||||
'#md5=e6760af92b7165f8be53b5763e40bc24'
|
||||
)
|
||||
self.assertSaltTrueReturn({'test': ret})
|
||||
self.assertInSaltComment('All packages were successfully installed',
|
||||
{'test': ret}
|
||||
)
|
||||
self.assertInSaltReturn(
|
||||
'Installed',
|
||||
{'test': ret},
|
||||
('changes', 'https://pypi.python.org/packages/source/S/'
|
||||
'SaltTesting/SaltTesting-0.5.0.tar.gz'
|
||||
'#md5=e6760af92b7165f8be53b5763e40bc24==???')
|
||||
)
|
||||
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={'SaltTesting': '0.5.0'})
|
||||
pip_install = MagicMock(return_value={
|
||||
'retcode': 0,
|
||||
'stderr': '',
|
||||
'stdout': 'Cloned!'
|
||||
})
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list,
|
||||
'pip.install': pip_install}):
|
||||
with patch.dict(pip_state.__opts__, {'test': False}):
|
||||
ret = pip_state.installed(
|
||||
'git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting'
|
||||
)
|
||||
self.assertSaltTrueReturn({'test': ret})
|
||||
self.assertInSaltComment(
|
||||
'packages are already installed',
|
||||
{'test': ret}
|
||||
)
|
||||
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={'pep8': '1.3.1'})
|
||||
pip_install = MagicMock(return_value={'retcode': 0})
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list,
|
||||
'pip.install': pip_install}):
|
||||
with patch.dict(pip_state.__opts__, {'test': False}):
|
||||
ret = pip_state.installed(
|
||||
'arbitrary ID that should be ignored due to requirements specified',
|
||||
requirements='/tmp/non-existing-requirements.txt'
|
||||
)
|
||||
self.assertSaltTrueReturn({'test': ret})
|
||||
|
||||
# Test VCS installations using git+git://
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={'SaltTesting': '0.5.0'})
|
||||
pip_install = MagicMock(return_value={
|
||||
'retcode': 0,
|
||||
'stderr': '',
|
||||
'stdout': 'Cloned!'
|
||||
})
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list,
|
||||
'pip.install': pip_install}):
|
||||
with patch.dict(pip_state.__opts__, {'test': False}):
|
||||
ret = pip_state.installed(
|
||||
'git+git://github.com/saltstack/salt-testing.git#egg=SaltTesting'
|
||||
)
|
||||
self.assertSaltTrueReturn({'test': ret})
|
||||
self.assertInSaltComment(
|
||||
'packages are already installed',
|
||||
{'test': ret}
|
||||
)
|
||||
|
||||
# Test VCS installations with version info like >= 0.1
|
||||
with patch.object(pip, '__version__', MagicMock(side_effect=AttributeError(
|
||||
'Faked missing __version__ attribute'))):
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={'SaltTesting': '0.5.0'})
|
||||
pip_install = MagicMock(return_value={
|
||||
'retcode': 0,
|
||||
'stderr': '',
|
||||
'stdout': 'Cloned!'
|
||||
})
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list,
|
||||
'pip.install': pip_install}):
|
||||
with patch.dict(pip_state.__opts__, {'test': False}):
|
||||
ret = pip_state.installed(
|
||||
'git+https://github.com/saltstack/salt-testing.git#egg=SaltTesting>=0.5.0'
|
||||
)
|
||||
self.assertSaltTrueReturn({'test': ret})
|
||||
self.assertInSaltComment(
|
||||
'packages are already installed',
|
||||
{'test': ret}
|
||||
)
|
||||
|
||||
def test_install_in_editable_mode(self):
|
||||
'''
|
||||
Check that `name` parameter containing bad characters is not parsed by
|
||||
pip when package is being installed in editable mode.
|
||||
For more information, see issue #21890.
|
||||
'''
|
||||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
pip_list = MagicMock(return_value={})
|
||||
pip_install = MagicMock(return_value={
|
||||
'retcode': 0,
|
||||
'stderr': '',
|
||||
'stdout': 'Cloned!'
|
||||
})
|
||||
pip_version = MagicMock(return_value='10.0.1')
|
||||
with patch.dict(pip_state.__salt__, {'cmd.run_all': mock,
|
||||
'pip.list': pip_list,
|
||||
'pip.install': pip_install,
|
||||
'pip.version': pip_version}):
|
||||
ret = pip_state.installed('state@name',
|
||||
cwd='/path/to/project',
|
||||
editable=['.'])
|
||||
self.assertSaltTrueReturn({'test': ret})
|
||||
self.assertInSaltComment(
|
||||
'successfully installed',
|
||||
{'test': ret}
|
||||
)
|
|
@ -19,8 +19,10 @@ integration.modules.test_mine
|
|||
integration.modules.test_network
|
||||
integration.modules.test_ntp
|
||||
integration.modules.test_pillar
|
||||
integration.modules.test_pip
|
||||
integration.modules.test_pkg
|
||||
integration.modules.test_publish
|
||||
integration.modules.test_service
|
||||
integration.modules.test_state
|
||||
integration.modules.test_status
|
||||
integration.modules.test_sysmod
|
||||
|
@ -35,6 +37,7 @@ integration.runners.test_jobs
|
|||
integration.runners.test_salt
|
||||
integration.sdb.test_env
|
||||
integration.states.test_host
|
||||
integration.states.test_pip
|
||||
integration.states.test_renderers
|
||||
integration.utils.testprogram
|
||||
integration.wheel.test_client
|
||||
|
|
Loading…
Add table
Reference in a new issue