Merge pull request #19579 from basepi/merge-forward-2015.2

Merge forward from 2014.7 to 2015.2
This commit is contained in:
Nicole Thomas 2015-01-09 12:51:48 -07:00
commit e46ccc8210
32 changed files with 514 additions and 331 deletions

View file

@ -548,6 +548,12 @@ New Salt-Cloud Providers
- :mod:`LXC Containers <salt.cloud.clouds.lxc>`
- :mod:`Proxmox (OpenVZ containers & KVM) <salt.cloud.clouds.proxmox>`
Salt Call Change
================
When used with a returner, salt-call now contacts a master if ``--local``
is not specicified.
Deprecations
============

View file

@ -42,6 +42,7 @@ HAS_LIBS = False
try:
import azure
import azure.servicemanagement
from azure import WindowsAzureConflictError
HAS_LIBS = True
except ImportError:
pass
@ -492,6 +493,33 @@ def create(vm_):
try:
conn.create_hosted_service(**service_kwargs)
except WindowsAzureConflictError:
log.debug("Cloud service already exists")
except Exception as exc:
error = 'The hosted service name is invalid.'
if error in str(exc):
log.error(
'Error creating {0} on Azure.\n\n'
'The hosted service name is invalid. The name can contain '
'only letters, numbers, and hyphens. The name must start with '
'a letter and must end with a letter or a number.'.format(
vm_['name']
),
# Show the traceback if the debug logging level is enabled
exc_info_on_loglevel=logging.DEBUG
)
else:
log.error(
'Error creating {0} on Azure\n\n'
'The following exception was thrown when trying to '
'run the initial deployment: \n{1}'.format(
vm_['name'], str(exc)
),
# Show the traceback if the debug logging level is enabled
exc_info_on_loglevel=logging.DEBUG
)
return False
try:
conn.create_virtual_machine_deployment(**vm_kwargs)
except Exception as exc:
error = 'The hosted service name is invalid.'
@ -700,6 +728,9 @@ def destroy(name, conn=None, call=None, kwargs=None):
if not conn:
conn = get_conn()
if kwargs is None:
kwargs = {}
service_name = kwargs.get('service_name', name)
ret = {}

View file

@ -6,11 +6,11 @@ A module to wrap (non-Windows) archive calls
'''
from __future__ import absolute_import
import os
from salt.exceptions import CommandExecutionError
from salt.ext.six import string_types
# Import salt libs
from salt.exceptions import SaltInvocationError, CommandExecutionError
from salt.ext.six import string_types
from salt.utils import \
which as _which, which_bin as _which_bin, is_windows as _is_windows
import salt.utils.decorators as decorators
@ -53,60 +53,65 @@ def tar(options, tarfile, sources=None, dest=None, cwd=None, template=None, runa
command. Beginning with 0.17.0, ``sources`` must be a comma-separated
list, and the ``cwd`` and ``template`` arguments are optional.
Uses the tar command to pack, unpack, etc tar files
Uses the tar command to pack, unpack, etc. tar files
options:
Options to pass to the ``tar`` binary.
options
Options to pass to the tar command
tarfile:
The tar filename to pack/unpack.
tarfile
The filename of the tar archive to pack/unpack
sources:
Comma delimited list of files to **pack** into the tarfile.
sources
Comma delimited list of files to **pack** into the tarfile. Can also be
passed as a python list.
dest:
The destination directory to **unpack** the tarfile to.
dest
The destination directory into which to **unpack** the tarfile
cwd:
The directory in which the tar command should be executed.
cwd : None
The directory in which the tar command should be executed. If not
specified, will default to the home directory of the user under which
the salt minion process is running.
template:
Template engine name to render the command arguments before execution.
template : None
Can be set to 'jinja' or another supported template engine to render
the command arguments before execution:
CLI Example:
.. code-block:: bash
salt '*' archive.tar cjvf /tmp/salt.tar.bz2 {{grains.saltpath}} template=jinja
CLI Examples:
.. code-block:: bash
# Create a tarfile
salt '*' archive.tar cjvf /tmp/tarfile.tar.bz2 /tmp/file_1,/tmp/file_2
The template arg can be set to ``jinja`` or another supported template
engine to render the command arguments before execution. For example:
.. code-block:: bash
salt '*' archive.tar cjvf /tmp/salt.tar.bz2 {{grains.saltpath}} template=jinja
To unpack a tarfile, for example:
.. code-block:: bash
# Unpack a tarfile
salt '*' archive.tar xf foo.tar dest=/target/directory
'''
if not options:
# Catch instances were people pass an empty string for the "options"
# argument. Someone would have to be really silly to do this, but we
# should at least let them know of their silliness.
raise SaltInvocationError('Tar options can not be empty')
if isinstance(sources, string_types):
sources = [s.strip() for s in sources.split(',')]
cmd = ['tar']
if dest:
options = 'C {0} -{1}'.format(dest, options)
cmd.extend(['-C', '{0}'.format(dest)])
cmd = 'tar -{0} {1}'.format(options, tarfile)
if sources:
cmd += ' {0}'.format(' '.join(sources))
cmd.extend(['-{0}'.format(options), '{0}'.format(tarfile)])
cmd.extend(sources)
return __salt__['cmd.run'](cmd, cwd=cwd, template=template, runas=runas).splitlines()
return __salt__['cmd.run'](cmd,
cwd=cwd,
template=template,
runas=runas,
python_shell=False).splitlines()
@decorators.which('gzip')
@ -114,24 +119,26 @@ def gzip(sourcefile, template=None, runas=None):
'''
Uses the gzip command to create gzip files
CLI Example to create ``/tmp/sourcefile.txt.gz``:
template : None
Can be set to 'jinja' or another supported template engine to render
the command arguments before execution:
.. code-block:: bash
.. code-block:: bash
salt '*' archive.gzip /tmp/sourcefile.txt
The template arg can be set to 'jinja' or another supported template
engine to render the command arguments before execution.
salt '*' archive.gzip template=jinja /tmp/{{grains.id}}.txt
CLI Example:
.. code-block:: bash
salt '*' archive.gzip template=jinja /tmp/{{grains.id}}.txt
# Create /tmp/sourcefile.txt.gz
salt '*' archive.gzip /tmp/sourcefile.txt
'''
cmd = 'gzip {0}'.format(sourcefile)
return __salt__['cmd.run'](cmd, template=template, runas=runas).splitlines()
cmd = ['gzip', '{0}'.format(sourcefile)]
return __salt__['cmd.run'](cmd,
template=template,
runas=runas,
python_shell=False).splitlines()
@decorators.which('gunzip')
@ -139,51 +146,83 @@ def gunzip(gzipfile, template=None, runas=None):
'''
Uses the gunzip command to unpack gzip files
CLI Example to create ``/tmp/sourcefile.txt``:
template : None
Can be set to 'jinja' or another supported template engine to render
the command arguments before execution:
.. code-block:: bash
.. code-block:: bash
salt '*' archive.gunzip /tmp/sourcefile.txt.gz
The template arg can be set to 'jinja' or another supported template
engine to render the command arguments before execution.
salt '*' archive.gunzip template=jinja /tmp/{{grains.id}}.txt.gz
CLI Example:
.. code-block:: bash
salt '*' archive.gunzip template=jinja /tmp/{{grains.id}}.txt.gz
# Create /tmp/sourcefile.txt
salt '*' archive.gunzip /tmp/sourcefile.txt.gz
'''
cmd = 'gunzip {0}'.format(gzipfile)
return __salt__['cmd.run'](cmd, template=template, runas=runas).splitlines()
cmd = ['gunzip', '{0}'.format(gzipfile)]
return __salt__['cmd.run'](cmd,
template=template,
runas=runas,
python_shell=False).splitlines()
@decorators.which('zip')
def cmd_zip_(zip_file, sources, template=None, runas=None):
def cmd_zip_(zip_file, sources, template=None,
cwd=None, recurse=False, runas=None):
'''
Uses the zip command to create zip files
zip_file
Path of zip file to be created
sources
Comma-separated list of sources to include in the zip file. Sources can
also be passed in a python list.
template : None
Can be set to 'jinja' or another supported template engine to render
the command arguments before execution:
.. code-block:: bash
salt '*' archive.zip template=jinja /tmp/zipfile.zip /tmp/sourcefile1,/tmp/{{grains.id}}.txt
cwd : None
Run the zip command from the specified directory. Use this argument
along with relative file paths to create zip files which do not
contain the leading directories. If not specified, this will default
to the home directory of the user under which the salt minion process
is running.
.. versionadded:: 2014.7.1
recurse : False
Recursively include contents of sources which are directories. Combine
this with the ``cwd`` argument and use relative paths for the sources
to create a zip file which does not contain the leading directories.
.. versionadded:: 2014.7.1
CLI Example:
.. code-block:: bash
salt '*' archive.zip /tmp/zipfile.zip /tmp/sourcefile1,/tmp/sourcefile2
The template arg can be set to 'jinja' or another supported template
engine to render the command arguments before execution.
For example:
.. code-block:: bash
salt '*' archive.zip template=jinja /tmp/zipfile.zip /tmp/sourcefile1,/tmp/{{grains.id}}.txt
'''
if isinstance(sources, string_types):
sources = [s.strip() for s in sources.split(',')]
cmd = 'zip {0} {1}'.format(zip_file, ' '.join(sources))
return __salt__['cmd.run'](cmd, template=template, runas=runas).splitlines()
cmd = ['zip']
if recurse:
cmd.append('-r')
cmd.append('{0}'.format(zip_file))
cmd.extend(sources)
return __salt__['cmd.run'](cmd,
cwd=cwd,
template=template,
runas=runas,
python_shell=False).splitlines()
@decorators.depends('zipfile', fallback_function=cmd_zip_)
@ -236,36 +275,50 @@ def cmd_unzip_(zip_file, dest, excludes=None, template=None, options=None, runas
'''
Uses the unzip command to unpack zip files
options:
Options to pass to the ``unzip`` binary.
zip_file
Path of zip file to be unpacked
dest
The destination directory into which the file should be unpacked
options : None
Options to pass to the ``unzip`` binary
template : None
Can be set to 'jinja' or another supported template engine to render
the command arguments before execution:
.. code-block:: bash
salt '*' archive.unzip template=jinja /tmp/zipfile.zip /tmp/{{grains.id}}/ excludes=file_1,file_2
CLI Example:
.. code-block:: bash
salt '*' archive.unzip /tmp/zipfile.zip /home/strongbad/ excludes=file_1,file_2
The template arg can be set to 'jinja' or another supported template
engine to render the command arguments before execution.
For example:
.. code-block:: bash
salt '*' archive.unzip template=jinja /tmp/zipfile.zip /tmp/{{grains.id}}/ excludes=file_1,file_2
'''
if isinstance(excludes, string_types):
excludes = [entry.strip() for entry in excludes.split(',')]
cmd = ['unzip']
if options:
cmd = 'unzip -{0} {1} -d {2}'.format(options, zip_file, dest)
else:
cmd = 'unzip {0} -d {1}'.format(zip_file, dest)
try:
if not options.startswith('-'):
options = '-{0}'.format(options)
except AttributeError:
raise SaltInvocationError(
'Invalid option(s): {0}'.format(options)
)
cmd.append(options)
cmd.extend(['{0}'.format(zip_file), '-d', '{0}'.format(dest)])
if excludes is not None:
cmd += ' -x {0}'.format(' '.join(excludes))
return __salt__['cmd.run'](cmd, template=template, runas=runas).splitlines()
cmd.append('-x')
cmd.extend(excludes)
return __salt__['cmd.run'](cmd,
template=template,
python_shell=False).splitlines()
@decorators.depends('zipfile', fallback_function=cmd_unzip_)
@ -309,39 +362,73 @@ def unzip(archive, dest, excludes=None, template=None, options=None, runas=None)
@decorators.which('rar')
def rar(rarfile, sources, template=None, runas=None):
def rar(rarfile, sources, template=None, cwd=None, runas=None):
'''
Uses the rar command to create rar files
Uses rar for Linux from http://www.rarlab.com/
Uses `rar for Linux`_ to create rar files
.. _`rar for Linux`: http://www.rarlab.com/
rarfile
Path of rar file to be created
sources
Comma-separated list of sources to include in the rar file. Sources can
also be passed in a python list.
cwd : None
Run the rar command from the specified directory. Use this argument
along with relative file paths to create rar files which do not
contain the leading directories. If not specified, this will default
to the home directory of the user under which the salt minion process
is running.
.. versionadded:: 2014.7.1
template : None
Can be set to 'jinja' or another supported template engine to render
the command arguments before execution:
.. code-block:: bash
salt '*' archive.rar template=jinja /tmp/rarfile.rar '/tmp/sourcefile1,/tmp/{{grains.id}}.txt'
CLI Example:
.. code-block:: bash
salt '*' archive.rar /tmp/rarfile.rar /tmp/sourcefile1,/tmp/sourcefile2
The template arg can be set to 'jinja' or another supported template
engine to render the command arguments before execution.
For example:
.. code-block:: bash
salt '*' archive.rar template=jinja /tmp/rarfile.rar /tmp/sourcefile1,/tmp/{{grains.id}}.txt
'''
if isinstance(sources, string_types):
sources = [s.strip() for s in sources.split(',')]
cmd = 'rar a -idp {0} {1}'.format(rarfile, ' '.join(sources))
return __salt__['cmd.run'](cmd, template=template, runas=runas).splitlines()
cmd = ['rar', 'a', '-idp', '{0}'.format(rarfile)]
cmd.extend(sources)
return __salt__['cmd.run'](cmd,
cwd=cwd,
template=template,
runas=runas,
python_shell=False).splitlines()
@decorators.which_bin(('unrar', 'rar'))
def unrar(rarfile, dest, excludes=None, template=None, runas=None):
'''
Uses the unrar command to unpack rar files
Uses rar for Linux from http://www.rarlab.com/
Uses `rar for Linux`_ to unpack rar files
.. _`rar for Linux`: http://www.rarlab.com/
rarfile
Name of rar file to be unpacked
dest
The destination directory into which to **unpack** the rar file
template : None
Can be set to 'jinja' or another supported template engine to render
the command arguments before execution:
.. code-block:: bash
salt '*' archive.unrar template=jinja /tmp/rarfile.rar /tmp/{{grains.id}}/ excludes=file_1,file_2
CLI Example:
@ -349,25 +436,19 @@ def unrar(rarfile, dest, excludes=None, template=None, runas=None):
salt '*' archive.unrar /tmp/rarfile.rar /home/strongbad/ excludes=file_1,file_2
The template arg can be set to 'jinja' or another supported template
engine to render the command arguments before execution.
For example:
.. code-block:: bash
salt '*' archive.unrar template=jinja /tmp/rarfile.rar /tmp/{{grains.id}}/ excludes=file_1,file_2
'''
if isinstance(excludes, string_types):
excludes = [entry.strip() for entry in excludes.split(',')]
cmd = [_which_bin(('unrar', 'rar')), 'x', '-idp', rarfile]
cmd = [_which_bin(('unrar', 'rar')), 'x', '-idp', '{0}'.format(rarfile)]
if excludes is not None:
for exclude in excludes:
cmd.extend(['-x', exclude])
cmd.append(dest)
return __salt__['cmd.run'](' '.join(cmd), template=template, runas=runas).splitlines()
cmd.extend(['-x', '{0}'.format(exclude)])
cmd.append('{0}'.format(dest))
return __salt__['cmd.run'](cmd,
template=template,
runas=runas,
python_shell=False).splitlines()
def _render_filenames(filenames, zip_file, saltenv, template):

View file

@ -58,7 +58,7 @@ def tune(device, **kwargs):
else:
opts += '--{0} {1} '.format(switch, kwargs[key])
cmd = 'blockdev {0}{1}'.format(opts, device)
out = __salt__['cmd.run'](cmd).splitlines()
out = __salt__['cmd.run'](cmd, python_shell=False).splitlines()
return dump(device, args)
@ -75,7 +75,7 @@ def wipe(device):
cmd = 'wipefs {0}'.format(device)
try:
out = __salt__['cmd.run_all'](cmd)
out = __salt__['cmd.run_all'](cmd, python_shell=False)
except subprocess.CalledProcessError as err:
return False
if out['retcode'] == 0:
@ -94,7 +94,7 @@ def dump(device, args=None):
cmd = 'blockdev --getro --getsz --getss --getpbsz --getiomin --getioopt --getalignoff --getmaxsect --getsize --getsize64 --getra --getfra {0}'.format(device)
ret = {}
opts = [c[2:] for c in cmd.split() if c.startswith('--')]
out = __salt__['cmd.run_all'](cmd)
out = __salt__['cmd.run_all'](cmd, python_shell=False)
if out['retcode'] == 0:
lines = [line for line in out['stdout'].splitlines() if line]
count = 0

View file

@ -66,7 +66,10 @@ def _call_brew(cmd):
Calls the brew command with the user user account of brew
'''
user = __salt__['file.get_user'](_homebrew_bin())
return __salt__['cmd.run_all'](cmd, runas=user, output_loglevel='trace')
return __salt__['cmd.run_all'](cmd,
runas=user,
output_loglevel='trace',
python_shell=False)
def list_pkgs(versions_as_list=False, **kwargs):

View file

@ -147,7 +147,10 @@ def install(dir,
if optimize is True:
cmd += ' --optimize-autoloader'
result = __salt__['cmd.run_all'](cmd, runas=runas, env={'COMPOSER_HOME': composer_home})
result = __salt__['cmd.run_all'](cmd,
runas=runas,
env={'COMPOSER_HOME': composer_home},
python_shell=False)
if result['retcode'] != 0:
raise CommandExecutionError(result['stderr'])

View file

@ -60,7 +60,7 @@ def start(name):
'''
__salt__['file.remove']('{0}/down'.format(_service_path(name)))
cmd = 'svc -u {0}'.format(_service_path(name))
return not __salt__['cmd.retcode'](cmd)
return not __salt__['cmd.retcode'](cmd, python_shell=False)
#-- states.service compatible args
@ -76,7 +76,7 @@ def stop(name):
'''
__salt__['file.touch']('{0}/down'.format(_service_path(name)))
cmd = 'svc -d {0}'.format(_service_path(name))
return not __salt__['cmd.retcode'](cmd)
return not __salt__['cmd.retcode'](cmd, python_shell=False)
def term(name):
@ -90,7 +90,7 @@ def term(name):
salt '*' daemontools.term <service name>
'''
cmd = 'svc -t {0}'.format(_service_path(name))
return not __salt__['cmd.retcode'](cmd)
return not __salt__['cmd.retcode'](cmd, python_shell=False)
#-- states.service compatible
@ -150,7 +150,7 @@ def status(name, sig=None):
salt '*' daemontools.status <service name>
'''
cmd = 'svstat {0}'.format(_service_path(name))
out = __salt__['cmd.run_stdout'](cmd)
out = __salt__['cmd.run_stdout'](cmd, python_shell=False)
try:
pid = re.search(r'\(pid (\d+)\)', out).group(1)
except AttributeError:

View file

@ -104,7 +104,7 @@ def _set_file(path):
'''
cmd = 'debconf-set-selections {0}'.format(path)
__salt__['cmd.run_stdout'](cmd)
__salt__['cmd.run_stdout'](cmd, python_shell=False)
def set_(package, question, type, value, *extra):

View file

@ -212,7 +212,7 @@ def blkid(device=None):
args = " " + device
ret = {}
for line in __salt__['cmd.run_stdout']('blkid' + args).split('\n'):
for line in __salt__['cmd.run_stdout']('blkid' + args, python_shell=False).split('\n'):
comps = line.split()
device = comps[0][:-1]
info = {}

View file

@ -65,7 +65,7 @@ def command(settings_module,
for key, value in kwargs.items():
if not key.startswith('__'):
cmd = '{0} --{1}={2}'.format(cmd, key, value)
return __salt__['cmd.run'](cmd, env=env)
return __salt__['cmd.run'](cmd, env=env, python_shell=False)
def syncdb(settings_module,

View file

@ -68,7 +68,7 @@ def list_pkgs(*packages):
'''
pkgs = {}
cmd = 'dpkg -l {0}'.format(' '.join(packages))
out = __salt__['cmd.run_all'](cmd)
out = __salt__['cmd.run_all'](cmd, python_shell=False)
if out['retcode'] != 0:
msg = 'Error: ' + out['stderr']
log.error(msg)
@ -100,7 +100,7 @@ def file_list(*packages):
ret = set([])
pkgs = {}
cmd = 'dpkg -l {0}'.format(' '.join(packages))
out = __salt__['cmd.run_all'](cmd)
out = __salt__['cmd.run_all'](cmd, python_shell=False)
if out['retcode'] != 0:
msg = 'Error: ' + out['stderr']
log.error(msg)
@ -117,7 +117,7 @@ def file_list(*packages):
for pkg in pkgs:
files = []
cmd = 'dpkg -L {0}'.format(pkg)
for line in __salt__['cmd.run'](cmd).splitlines():
for line in __salt__['cmd.run'](cmd, python_shell=False).splitlines():
files.append(line)
fileset = set(files)
ret = ret.union(fileset)
@ -142,7 +142,7 @@ def file_dict(*packages):
ret = {}
pkgs = {}
cmd = 'dpkg -l {0}'.format(' '.join(packages))
out = __salt__['cmd.run_all'](cmd)
out = __salt__['cmd.run_all'](cmd, python_shell=False)
if out['retcode'] != 0:
msg = 'Error: ' + out['stderr']
log.error(msg)
@ -159,7 +159,7 @@ def file_dict(*packages):
for pkg in pkgs:
files = []
cmd = 'dpkg -L {0}'.format(pkg)
for line in __salt__['cmd.run'](cmd).splitlines():
for line in __salt__['cmd.run'](cmd, python_shell=False).splitlines():
files.append(line)
ret[pkg] = files
return {'errors': errors, 'packages': ret}

View file

@ -98,7 +98,7 @@ def mkfs(device, fs_type, **kwargs):
else:
opts += '-{0} {1} '.format(opt, kwargs[key])
cmd = 'mke2fs -F -t {0} {1}{2}'.format(fs_type, opts, device)
out = __salt__['cmd.run'](cmd).splitlines()
out = __salt__['cmd.run'](cmd, python_shell=False).splitlines()
ret = []
for line in out:
if not line:
@ -183,7 +183,7 @@ def tune(device, **kwargs):
else:
opts += '-{0} {1} '.format(opt, kwargs[key])
cmd = 'tune2fs {0}{1}'.format(opts, device)
out = __salt__['cmd.run'](cmd).splitlines()
out = __salt__['cmd.run'](cmd, python_shell=False).splitlines()
return out
@ -229,7 +229,7 @@ def dump(device, args=None):
if args:
cmd = cmd + ' -' + args
ret = {'attributes': {}, 'blocks': {}}
out = __salt__['cmd.run'](cmd).splitlines()
out = __salt__['cmd.run'](cmd, python_shell=False).splitlines()
mode = 'opts'
group = None
for line in out:

View file

@ -77,7 +77,7 @@ def get(name):
salt '*' sysctl.get hw.physmem
'''
cmd = 'sysctl -n {0}'.format(name)
out = __salt__['cmd.run'](cmd)
out = __salt__['cmd.run'](cmd, python_shell=False)
return out
@ -93,7 +93,7 @@ def assign(name, value):
'''
ret = {}
cmd = 'sysctl {0}="{1}"'.format(name, value)
data = __salt__['cmd.run_all'](cmd)
data = __salt__['cmd.run_all'](cmd, python_shell=False)
if data['retcode'] != 0:
raise CommandExecutionError('sysctl failed: {0}'.format(

View file

@ -65,7 +65,7 @@ def _get_rcvar(name):
cmd = '{0} {1} rcvar'.format(_cmd(), name)
for line in __salt__['cmd.run_stdout'](cmd).splitlines():
for line in __salt__['cmd.run_stdout'](cmd, python_path=False).splitlines():
if '_enable="' not in line:
continue
rcvar, _ = line.split('=', 1)
@ -229,7 +229,7 @@ def enabled(name, **kwargs):
cmd = '{0} {1} rcvar'.format(_cmd(), name)
for line in __salt__['cmd.run_stdout'](cmd).splitlines():
for line in __salt__['cmd.run_stdout'](cmd, python_shell=False).splitlines():
if '_enable="' not in line:
continue
_, state, _ = line.split('"', 2)
@ -309,7 +309,7 @@ def start(name):
salt '*' service.start <service name>
'''
cmd = '{0} {1} onestart'.format(_cmd(), name)
return not __salt__['cmd.retcode'](cmd)
return not __salt__['cmd.retcode'](cmd, python_shell=False)
def stop(name):
@ -323,7 +323,7 @@ def stop(name):
salt '*' service.stop <service name>
'''
cmd = '{0} {1} onestop'.format(_cmd(), name)
return not __salt__['cmd.retcode'](cmd)
return not __salt__['cmd.retcode'](cmd, python_shell=False)
def restart(name):
@ -337,7 +337,7 @@ def restart(name):
salt '*' service.restart <service name>
'''
cmd = '{0} {1} onerestart'.format(_cmd(), name)
return not __salt__['cmd.retcode'](cmd)
return not __salt__['cmd.retcode'](cmd, python_shell=False)
def reload_(name):
@ -351,7 +351,7 @@ def reload_(name):
salt '*' service.reload <service name>
'''
cmd = '{0} {1} onereload'.format(_cmd(), name)
return not __salt__['cmd.retcode'](cmd)
return not __salt__['cmd.retcode'](cmd, python_shell=False)
def status(name, sig=None):
@ -370,4 +370,4 @@ def status(name, sig=None):
if sig:
return bool(__salt__['status.pid'](sig))
cmd = '{0} {1} onestatus'.format(_cmd(), name)
return not __salt__['cmd.retcode'](cmd)
return not __salt__['cmd.retcode'](cmd, python_shell=False)

View file

@ -510,7 +510,9 @@ def install(pkgs=None, # pylint: disable=R0912,R0913,R0914
if pre_releases:
# Check the locally installed pip version
pip_version_cmd = '{0} --version'.format(_get_pip_bin(bin_env))
output = __salt__['cmd.run_all'](pip_version_cmd, use_vt=use_vt).get('stdout', '')
output = __salt__['cmd.run_all'](pip_version_cmd,
use_vt=use_vt,
python_shell=False).get('stdout', '')
pip_version = output.split()[1]
# From pip v1.4 the --pre flag is available
@ -590,7 +592,7 @@ def install(pkgs=None, # pylint: disable=R0912,R0913,R0914
cmd_kwargs = dict(runas=user, cwd=cwd, saltenv=saltenv, use_vt=use_vt)
if bin_env and os.path.isdir(bin_env):
cmd_kwargs['env'] = {'VIRTUAL_ENV': bin_env}
return __salt__['cmd.run_all'](' '.join(cmd), **cmd_kwargs)
return __salt__['cmd.run_all'](' '.join(cmd), python_shell=False, **cmd_kwargs)
finally:
for requirement in cleanup_requirements:
try:
@ -720,7 +722,7 @@ def uninstall(pkgs=None,
pass
cmd.extend(pkgs)
cmd_kwargs = dict(runas=user, cwd=cwd, saltenv=saltenv, use_vt=use_vt)
cmd_kwargs = dict(python_shell=False, runas=user, cwd=cwd, saltenv=saltenv, use_vt=use_vt)
if bin_env and os.path.isdir(bin_env):
cmd_kwargs['env'] = {'VIRTUAL_ENV': bin_env}
@ -768,7 +770,7 @@ def freeze(bin_env=None,
user = _get_user(user, runas)
cmd = [_get_pip_bin(bin_env), 'freeze']
cmd_kwargs = dict(runas=user, cwd=cwd, use_vt=use_vt)
cmd_kwargs = dict(runas=user, cwd=cwd, use_vt=use_vt, python_shell=False)
if bin_env and os.path.isdir(bin_env):
cmd_kwargs['env'] = {'VIRTUAL_ENV': bin_env}
result = __salt__['cmd.run_all'](' '.join(cmd), **cmd_kwargs)
@ -802,7 +804,7 @@ def list_(prefix=None,
user = _get_user(user, runas)
cmd_kwargs = dict(runas=user, cwd=cwd)
cmd_kwargs = dict(runas=user, cwd=cwd, python_shell=False)
if bin_env and os.path.isdir(bin_env):
cmd_kwargs['env'] = {'VIRTUAL_ENV': bin_env}
@ -858,7 +860,7 @@ def version(bin_env=None):
salt '*' pip.version
'''
output = __salt__['cmd.run']('{0} --version'.format(_get_pip_bin(bin_env)))
output = __salt__['cmd.run']('{0} --version'.format(_get_pip_bin(bin_env)), python_shell=False)
try:
return re.match(r'^pip (\S+)', output).group(1)
except AttributeError:

View file

@ -213,7 +213,8 @@ def refresh_db(jail=None, chroot=None, force=False):
if force:
opts += ' -f'
return __salt__['cmd.retcode'](
'{0} update{1}'.format(_pkg(jail, chroot), opts)) == 0
'{0} update{1}'.format(_pkg(jail, chroot), opts),
python_shell=False) == 0
# Support pkg.update to refresh the db, since this is the CLI usage
@ -251,7 +252,7 @@ def latest_version(*names, **kwargs):
cmd = '{0} search {1}'.format(_pkg(jail, chroot), name)
pkgver = _get_version(
name,
__salt__['cmd.run'](cmd, output_loglevel='trace')
__salt__['cmd.run'](cmd, python_shell=False, output_loglevel='trace')
)
if pkgver is not None:
installed = pkgs.get(name, [])
@ -331,7 +332,10 @@ def list_pkgs(versions_as_list=False,
ret = {}
origins = {}
cmd = '{0} info -ao'.format(_pkg(jail, chroot))
out = __salt__['cmd.run_stdout'](cmd, output_loglevel='trace')
out = __salt__['cmd.run_stdout'](
cmd,
python_shell=False,
output_loglevel='trace')
for line in out.splitlines():
if not line:
continue
@ -439,6 +443,7 @@ def stats(local=False, remote=False, jail=None, chroot=None):
res = __salt__['cmd.run'](
'{0} stats {1}'.format(_pkg(jail, chroot), opts),
python_shell=False,
output_loglevel='trace'
)
res = [x.strip("\t") for x in res.split("\n")]
@ -480,6 +485,7 @@ def backup(file_name, jail=None, chroot=None):
'''
res = __salt__['cmd.run'](
'{0} backup -d {1!r}'.format(_pkg(jail, chroot), file_name),
python_shell=False,
output_loglevel='trace'
)
return res.split('...')[1]
@ -520,6 +526,7 @@ def restore(file_name, jail=None, chroot=None):
'''
return __salt__['cmd.run'](
'{0} backup -r {1!r}'.format(_pkg(jail, chroot), file_name),
python_shell=False,
output_loglevel='trace'
)
@ -555,6 +562,7 @@ def audit(jail=None, chroot=None):
'''
return __salt__['cmd.run'](
'{0} audit -F'.format(_pkg(jail, chroot)),
python_shell=False,
output_loglevel='trace'
)
@ -755,7 +763,7 @@ def install(name=None,
cmd = '{0} {1} {2} {3} {4}'.format(
_pkg(jail, chroot), pkg_cmd, repo_opts, opts, ' '.join(targets)
)
__salt__['cmd.run'](cmd, output_loglevel='trace')
__salt__['cmd.run'](cmd, python_shell=False, output_loglevel='trace')
__context__.pop(_contextkey(jail, chroot), None)
__context__.pop(_contextkey(jail, chroot, prefix='pkg.origin'), None)
new = list_pkgs(jail=jail, chroot=chroot)
@ -897,7 +905,7 @@ def remove(name=None,
cmd = '{0} delete {1} {2}'.format(
_pkg(jail, chroot), opts, ' '.join(targets)
)
__salt__['cmd.run'](cmd, output_loglevel='trace')
__salt__['cmd.run'](cmd, python_shell=False, output_loglevel='trace')
__context__.pop(_contextkey(jail, chroot), None)
__context__.pop(_contextkey(jail, chroot, prefix='pkg.origin'), None)
new = list_pkgs(jail=jail, chroot=chroot)
@ -992,6 +1000,7 @@ def upgrade(jail=None, chroot=None, force=False, local=False, dryrun=False):
old = list_pkgs()
call = __salt__['cmd.run_all'](
'{0} upgrade {1}'.format(_pkg(jail, chroot), opts),
python_shell=False,
output_loglevel='trace'
)
if call['retcode'] != 0:
@ -1021,6 +1030,7 @@ def clean(jail=None, chroot=None):
'''
return __salt__['cmd.run'](
'{0} clean'.format(_pkg(jail, chroot)),
python_shell=False,
output_loglevel='trace'
)
@ -1052,6 +1062,7 @@ def autoremove(jail=None, chroot=None, dryrun=False):
opts = '-' + opts
return __salt__['cmd.run'](
'{0} autoremove {1}'.format(_pkg(jail, chroot), opts),
python_shell=False,
output_loglevel='trace'
)
@ -1128,6 +1139,7 @@ def check(jail=None,
return __salt__['cmd.run'](
'{0} check {1}'.format(_pkg(jail, chroot), opts),
python_shell=False,
output_loglevel='trace'
)
@ -1189,6 +1201,7 @@ def which(path, jail=None, chroot=None, origin=False, quiet=False):
opts = '-' + opts
return __salt__['cmd.run'](
'{0} which {1} {2}'.format(_pkg(jail, chroot), opts, path),
python_shell=False,
output_loglevel='trace'
)
@ -1376,6 +1389,7 @@ def search(name,
return __salt__['cmd.run'](
'{0} search {1} {2}'.format(_pkg(jail, chroot), opts, name),
python_shell=False,
output_loglevel='trace'
)
@ -1520,6 +1534,7 @@ def fetch(name,
'{0} fetch -y {1} {2} {3}'.format(
_pkg(jail, chroot), opts, repo_opts, name
),
python_shell=False,
output_loglevel='trace'
)
@ -1586,5 +1601,6 @@ def updating(name,
return __salt__['cmd.run'](
'{0} updating {1} {2}'.format(_pkg(jail, chroot), opts, name),
python_shell=False,
output_loglevel='trace'
)

View file

@ -71,7 +71,7 @@ def __virtual__():
def _run_psql(cmd, runas=None, password=None, host=None, port=None, user=None,
run_cmd="cmd.run_all"):
run_cmd='cmd.run_all'):
'''
Helper function to call psql, because the password requirement
makes this too much code to be repeated in each function below
@ -111,7 +111,7 @@ def _run_psql(cmd, runas=None, password=None, host=None, port=None, user=None,
__salt__['file.chown'](pgpassfile, runas, '')
kwargs['env'] = {'PGPASSFILE': pgpassfile}
ret = __salt__[run_cmd](cmd, **kwargs)
ret = __salt__[run_cmd](cmd, python_shell=False, **kwargs)
if ret.get('retcode', 0) != 0:
log.error('Error connecting to Postgresql server')

View file

@ -85,7 +85,7 @@ def add_license(key):
return result
cmd = '/sbin/emcpreg -add {0}'.format(key)
ret = __salt__['cmd.run_all'](cmd)
ret = __salt__['cmd.run_all'](cmd, python_shell=True)
result['retcode'] = ret['retcode']
@ -113,7 +113,7 @@ def remove_license(key):
return result
cmd = '/sbin/emcpreg -remove {0}'.format(key)
ret = __salt__['cmd.run_all'](cmd)
ret = __salt__['cmd.run_all'](cmd, python_shell=True)
result['retcode'] = ret['retcode']

View file

@ -610,18 +610,3 @@ def get_users():
'started': started, 'host': rec[5]})
except ImportError:
return False
# This is a possible last ditch method
# result = []
# w = __salt__['cmd.run'](
# 'who', env='{"LC_ALL": "en_US.UTF-8"}').splitlines()
# for u in w:
# u = u.split()
# started = __salt__['cmd.run'](
# 'date --d "{0} {1}" +%s'.format(u[2], u[3])).strip()
# rec = {'name': u[0], 'terminal': u[1],
# 'started': started, 'host': None}
# if len(u) > 4:
# rec['host'] = u[4][1:-1]
# result.append(rec)
# return result

View file

@ -168,7 +168,7 @@ def run(*args, **kwargs):
puppet.kwargs.update(salt.utils.clean_kwargs(**kwargs))
return __salt__['cmd.run_all'](repr(puppet))
return __salt__['cmd.run_all'](repr(puppet), python_shell=False)
def noop(*args, **kwargs):
@ -379,7 +379,9 @@ def fact(name, puppet=False):
_check_facter()
opt_puppet = '--puppet' if puppet else ''
ret = __salt__['cmd.run']('facter {0} {1}'.format(opt_puppet, name))
ret = __salt__['cmd.run'](
'facter {0} {1}'.format(opt_puppet, name),
python_shell=False)
if not ret:
return ''
return ret

View file

@ -50,7 +50,7 @@ def add(name, gid=None, **kwargs):
if gid:
cmd += '-g {0} '.format(gid)
cmd = '{0} -n {1}'.format(cmd, name)
ret = __salt__['cmd.run_all'](cmd)
ret = __salt__['cmd.run_all'](cmd, python_shell=False)
return not ret['retcode']
@ -65,7 +65,7 @@ def delete(name):
salt '*' group.delete foo
'''
ret = __salt__['cmd.run_all']('pw groupdel {0}'.format(name))
ret = __salt__['cmd.run_all']('pw groupdel {0}'.format(name), python_shell=False)
return not ret['retcode']
@ -125,7 +125,7 @@ def chgid(name, gid):
if gid == pre_gid:
return True
cmd = 'pw groupmod {0} -g {1}'.format(name, gid)
__salt__['cmd.run'](cmd)
__salt__['cmd.run'](cmd, python_shell=False)
post_gid = __salt__['file.group_to_gid'](name)
if post_gid != pre_gid:
return post_gid == gid

View file

@ -108,7 +108,7 @@ def add(name,
homephone)
cmd += '-c "{0}" '.format(gecos_field)
cmd += '-n {0}'.format(name)
ret = __salt__['cmd.run_all'](cmd)
ret = __salt__['cmd.run_all'](cmd, python_shell=False)
return not ret['retcode']
@ -131,7 +131,7 @@ def delete(name, remove=False, force=False):
cmd += '-r '
cmd += '-n ' + name
ret = __salt__['cmd.run_all'](cmd)
ret = __salt__['cmd.run_all'](cmd, python_shell=False)
return not ret['retcode']
@ -170,7 +170,7 @@ def chuid(name, uid):
if uid == pre_info['uid']:
return True
cmd = 'pw usermod -u {0} -n {1}'.format(uid, name)
__salt__['cmd.run'](cmd)
__salt__['cmd.run'](cmd, python_shell=False)
post_info = info(name)
if post_info['uid'] != pre_info['uid']:
return post_info['uid'] == uid
@ -191,7 +191,7 @@ def chgid(name, gid):
if gid == pre_info['gid']:
return True
cmd = 'pw usermod -g {0} -n {1}'.format(gid, name)
__salt__['cmd.run'](cmd)
__salt__['cmd.run'](cmd, python_shell=False)
post_info = info(name)
if post_info['gid'] != pre_info['gid']:
return post_info['gid'] == gid
@ -212,7 +212,7 @@ def chshell(name, shell):
if shell == pre_info['shell']:
return True
cmd = 'pw usermod -s {0} -n {1}'.format(shell, name)
__salt__['cmd.run'](cmd)
__salt__['cmd.run'](cmd, python_shell=False)
post_info = info(name)
if post_info['shell'] != pre_info['shell']:
return post_info['shell'] == shell
@ -236,7 +236,7 @@ def chhome(name, home, persist=False):
cmd = 'pw usermod {0} -d {1}'.format(name, home)
if persist:
cmd += ' -m '
__salt__['cmd.run'](cmd)
__salt__['cmd.run'](cmd, python_shell=False)
post_info = info(name)
if post_info['home'] != pre_info['home']:
return post_info['home'] == home
@ -262,7 +262,7 @@ def chgroups(name, groups, append=False):
if append:
groups += ugrps
cmd = 'pw usermod -G {0} -n {1}'.format(','.join(groups), name)
return not __salt__['cmd.retcode'](cmd)
return not __salt__['cmd.retcode'](cmd, python_shell=False)
def chfullname(name, fullname):
@ -284,7 +284,7 @@ def chfullname(name, fullname):
gecos_field = copy.deepcopy(pre_info)
gecos_field['fullname'] = fullname
cmd = 'pw usermod {0} -c "{1}"'.format(name, _build_gecos(gecos_field))
__salt__['cmd.run'](cmd)
__salt__['cmd.run'](cmd, python_shell=False)
post_info = info(name)
if post_info['fullname'] != pre_info['fullname']:
return post_info['fullname'] == fullname
@ -310,7 +310,7 @@ def chroomnumber(name, roomnumber):
gecos_field = copy.deepcopy(pre_info)
gecos_field['roomnumber'] = roomnumber
cmd = 'pw usermod {0} -c "{1}"'.format(name, _build_gecos(gecos_field))
__salt__['cmd.run'](cmd)
__salt__['cmd.run'](cmd, python_shell=False)
post_info = info(name)
if post_info['roomnumber'] != pre_info['roomnumber']:
return post_info['roomnumber'] == roomnumber
@ -336,7 +336,7 @@ def chworkphone(name, workphone):
gecos_field = copy.deepcopy(pre_info)
gecos_field['workphone'] = workphone
cmd = 'pw usermod {0} -c "{1}"'.format(name, _build_gecos(gecos_field))
__salt__['cmd.run'](cmd)
__salt__['cmd.run'](cmd, python_shell=False)
post_info = info(name)
if post_info['workphone'] != pre_info['workphone']:
return post_info['workphone'] == workphone
@ -362,7 +362,7 @@ def chhomephone(name, homephone):
gecos_field = copy.deepcopy(pre_info)
gecos_field['homephone'] = homephone
cmd = 'pw usermod {0} -c "{1}"'.format(name, _build_gecos(gecos_field))
__salt__['cmd.run'](cmd)
__salt__['cmd.run'](cmd, python_shell=False)
post_info = info(name)
if post_info['homephone'] != pre_info['homephone']:
return post_info['homephone'] == homephone

View file

@ -57,7 +57,8 @@ def connect(image):
while True:
# Sometimes nbd does not "take hold", loop until we can verify
__salt__['cmd.run'](
'qemu-nbd -c {0} {1}'.format(nbd, image)
'qemu-nbd -c {0} {1}'.format(nbd, image),
python_shell=False,
)
if not __salt__['cmd.retcode']('{0} {1}'.format(fdisk, nbd)):
break
@ -79,7 +80,8 @@ def mount(nbd):
salt '*' qemu_nbd.mount /dev/nbd0
'''
__salt__['cmd.run'](
'partprobe {0}'.format(nbd)
'partprobe {0}'.format(nbd),
python_shell=False,
)
ret = {}
for part in glob.glob('{0}p*'.format(nbd)):
@ -135,5 +137,5 @@ def clear(mnt):
if ret:
return ret
for nbd in nbds:
__salt__['cmd.run']('qemu-nbd -d {0}'.format(nbd))
__salt__['cmd.run']('qemu-nbd -d {0}'.format(nbd), python_shell=False)
return ret

View file

@ -50,7 +50,7 @@ def _parse_quota(mount, opts):
Parse the output from repquota. Requires that -u -g are passed in
'''
cmd = 'repquota -vp {0} {1}'.format(opts, mount)
out = __salt__['cmd.run'](cmd).splitlines()
out = __salt__['cmd.run'](cmd, python_shell=False).splitlines()
mode = 'header'
if '-u' in opts:
@ -142,7 +142,7 @@ def set_(device, **kwargs):
current['file-hard-limit'],
device)
result = __salt__['cmd.run_all'](cmd)
result = __salt__['cmd.run_all'](cmd, python_shell=False)
if result['retcode'] != 0:
raise CommandExecutionError(
'Unable to set desired quota. Error follows: \n{0}'
@ -197,7 +197,7 @@ def on(device):
salt '*' quota.on
'''
cmd = 'quotaon {0}'.format(device)
__salt__['cmd.run'](cmd)
__salt__['cmd.run'](cmd, python_shell=False)
return True
@ -212,7 +212,7 @@ def off(device):
salt '*' quota.off
'''
cmd = 'quotaoff {0}'.format(device)
__salt__['cmd.run'](cmd)
__salt__['cmd.run'](cmd, python_shell=False)
return True
@ -228,7 +228,7 @@ def get_mode(device):
'''
ret = {}
cmd = 'quotaon -p {0}'.format(device)
out = __salt__['cmd.run'](cmd)
out = __salt__['cmd.run'](cmd, python_shell=False)
for line in out.splitlines():
comps = line.strip().split()
if comps[3] not in ret:

View file

@ -72,7 +72,7 @@ def _run_svn(cmd, cwd, user, username, password, opts, **kwargs):
if retcode == 0:
return result['stdout']
raise exceptions.CommandExecutionError(result['stderr'] + '\n\n' + cmd)
raise exceptions.CommandExecutionError(result['stderr'] + '\n\n' + ' '.join(cmd))
def info(cwd,

View file

@ -166,6 +166,7 @@ class Pillar(object):
saltenv = env
opts = dict(opts_in)
opts['file_roots'] = opts['pillar_roots']
opts['__pillar'] = True
opts['file_client'] = 'local'
if not grains:
opts['grains'] = {}

View file

@ -213,14 +213,14 @@ def export(name,
ret,
('{0} doesn\'t exist and is set to be checked out.').format(target))
svn_cmd = 'svn.list'
opts += ('-r', 'HEAD')
rev = 'HEAD'
out = __salt__[svn_cmd](cwd, target, user, username, password, *opts)
return _neutral_test(
ret,
('{0}').format(out))
if rev:
opts += ('-r', str(rev))
if not rev:
rev = 'HEAD'
if force:
opts += ('--force',)
@ -231,7 +231,7 @@ def export(name,
if trust:
opts += ('--trust-server-cert',)
out = __salt__[svn_cmd](cwd, name, basename, user, username, password, *opts)
out = __salt__[svn_cmd](cwd, name, basename, user, username, password, rev, *opts)
ret['changes'] = name + ' was Exported to ' + target
return ret

View file

@ -65,7 +65,10 @@ class SaltCacheLoader(BaseLoader):
self.opts = opts
self.saltenv = saltenv
self.encoding = encoding
self.searchpath = [path.join(opts['cachedir'], 'files', saltenv)]
if self.opts.get('__pillar', False):
self.searchpath = opts['file_roots'][saltenv]
else:
self.searchpath = [path.join(opts['cachedir'], 'files', saltenv)]
log.debug('Jinja search path: {0!r}'.format(self.searchpath))
self._file_client = None
self.cached = []

View file

@ -30,6 +30,7 @@ class DjangoModuleTest(integration.ModuleCase):
django.command('settings.py', 'runserver')
mock.assert_called_once_with(
'django-admin.py runserver --settings=settings.py',
python_shell=False,
env=None
)
@ -49,6 +50,7 @@ class DjangoModuleTest(integration.ModuleCase):
mock.assert_called_once_with(
'django-admin.py runserver --settings=settings.py '
'--noinput --somethingelse',
python_shell=False,
env=None
)
@ -66,6 +68,7 @@ class DjangoModuleTest(integration.ModuleCase):
mock.assert_called_once_with(
'django-admin.py runserver --settings=settings.py '
'--database=something',
python_shell=False,
env=None
)
@ -78,6 +81,7 @@ class DjangoModuleTest(integration.ModuleCase):
)
mock.assert_called_once_with(
'django-admin.py runserver --settings=settings.py',
python_shell=False,
env=None
)
@ -88,6 +92,7 @@ class DjangoModuleTest(integration.ModuleCase):
django.syncdb('settings.py')
mock.assert_called_once_with(
'django-admin.py syncdb --settings=settings.py --noinput',
python_shell=False,
env=None
)
@ -99,6 +104,7 @@ class DjangoModuleTest(integration.ModuleCase):
mock.assert_called_once_with(
'django-admin.py syncdb --settings=settings.py --migrate '
'--noinput',
python_shell=False,
env=None
)
@ -112,6 +118,7 @@ class DjangoModuleTest(integration.ModuleCase):
mock.assert_called_once_with(
'django-admin.py createsuperuser --settings=settings.py '
'--noinput --username=testuser --email=user@example.com',
python_shell=False,
env=None
)
@ -134,7 +141,9 @@ class DjangoModuleTest(integration.ModuleCase):
mock.assert_called_once_with(
'django-admin.py collectstatic --settings=settings.py '
'--noinput --no-post-process --dry-run --clear --link '
'--no-default-ignore --ignore=something', env=None
'--no-default-ignore --ignore=something',
python_shell=False,
env=None
)

View file

@ -46,16 +46,13 @@ class ArchiveTestCase(TestCase):
'zcvf', 'foo.tar',
['/tmp/something-to-compress-1',
'/tmp/something-to-compress-2'],
cwd=None,
template=None
)
self.assertEqual(['salt'], ret)
mock.assert_called_once_with(
'tar -zcvf foo.tar /tmp/something-to-compress-1 '
'/tmp/something-to-compress-2',
cwd=None,
runas=None,
template=None
['tar', '-zcvf', 'foo.tar', '/tmp/something-to-compress-1',
'/tmp/something-to-compress-2'],
runas=None, python_shell=False, template=None, cwd=None
)
mock = MagicMock(return_value='salt')
@ -63,16 +60,13 @@ class ArchiveTestCase(TestCase):
ret = archive.tar(
'zcvf', 'foo.tar',
'/tmp/something-to-compress-1,/tmp/something-to-compress-2',
cwd=None,
template=None
)
self.assertEqual(['salt'], ret)
mock.assert_called_once_with(
'tar -zcvf foo.tar /tmp/something-to-compress-1 '
'/tmp/something-to-compress-2',
cwd=None,
runas=None,
template=None
['tar', '-zcvf', 'foo.tar', '/tmp/something-to-compress-1',
'/tmp/something-to-compress-2'],
runas=None, python_shell=False, template=None, cwd=None
)
@patch('salt.utils.which', lambda exe: None)
@ -95,9 +89,8 @@ class ArchiveTestCase(TestCase):
ret = archive.gzip('/tmp/something-to-compress')
self.assertEqual(['salt'], ret)
mock.assert_called_once_with(
'gzip /tmp/something-to-compress',
runas=None,
template=None
['gzip', '/tmp/something-to-compress'],
runas=None, python_shell=False, template=None
)
@patch('salt.utils.which', lambda exe: None)
@ -117,9 +110,8 @@ class ArchiveTestCase(TestCase):
ret = archive.gunzip('/tmp/something-to-decompress.tar.gz')
self.assertEqual(['salt'], ret)
mock.assert_called_once_with(
'gunzip /tmp/something-to-decompress.tar.gz',
runas=None,
template=None
['gunzip', '/tmp/something-to-decompress.tar.gz'],
runas=None, python_shell=False, template=None
)
@patch('salt.utils.which', lambda exe: None)
@ -144,10 +136,9 @@ class ArchiveTestCase(TestCase):
)
self.assertEqual(['salt'], ret)
mock.assert_called_once_with(
'zip /tmp/salt.{{grains.id}}.zip '
'/tmp/tmpePe8yO /tmp/tmpLeSw1A',
runas=None,
template='jinja'
['zip', '/tmp/salt.{{grains.id}}.zip',
'/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
runas=None, python_shell=False, template='jinja', cwd=None
)
mock = MagicMock(return_value='salt')
@ -155,15 +146,13 @@ class ArchiveTestCase(TestCase):
ret = archive.cmd_zip_(
'/tmp/salt.{{grains.id}}.zip',
['/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
template='jinja',
runas=None
template='jinja'
)
self.assertEqual(['salt'], ret)
mock.assert_called_once_with(
'zip /tmp/salt.{{grains.id}}.zip '
'/tmp/tmpePe8yO /tmp/tmpLeSw1A',
runas=None,
template='jinja'
['zip', '/tmp/salt.{{grains.id}}.zip',
'/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
runas=None, python_shell=False, template='jinja', cwd=None
)
@patch('os.path.exists', MagicMock(return_value=True))
@ -198,15 +187,13 @@ class ArchiveTestCase(TestCase):
'/tmp/salt.{{grains.id}}.zip',
'/tmp/dest',
excludes='/tmp/tmpePe8yO,/tmp/tmpLeSw1A',
template='jinja',
runas=None
runas=None, template='jinja'
)
self.assertEqual(['salt'], ret)
mock.assert_called_once_with(
'unzip /tmp/salt.{{grains.id}}.zip -d /tmp/dest '
'-x /tmp/tmpePe8yO /tmp/tmpLeSw1A',
runas=None,
template='jinja'
['unzip', '/tmp/salt.{{grains.id}}.zip', '-d', '/tmp/dest',
'-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
python_shell=False, template='jinja'
)
mock = MagicMock(return_value='salt')
@ -219,10 +206,9 @@ class ArchiveTestCase(TestCase):
)
self.assertEqual(['salt'], ret)
mock.assert_called_once_with(
'unzip /tmp/salt.{{grains.id}}.zip -d /tmp/dest '
'-x /tmp/tmpePe8yO /tmp/tmpLeSw1A',
runas=None,
template='jinja'
['unzip', '/tmp/salt.{{grains.id}}.zip', '-d', '/tmp/dest',
'-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
python_shell=False, template='jinja'
)
mock = MagicMock(return_value='salt')
@ -236,10 +222,9 @@ class ArchiveTestCase(TestCase):
)
self.assertEqual(['salt'], ret)
mock.assert_called_once_with(
'unzip -fo /tmp/salt.{{grains.id}}.zip -d /tmp/dest '
'-x /tmp/tmpePe8yO /tmp/tmpLeSw1A',
runas=None,
template='jinja',
['unzip', '-fo', '/tmp/salt.{{grains.id}}.zip', '-d',
'/tmp/dest', '-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
python_shell=False, template='jinja'
)
mock = MagicMock(return_value='salt')
@ -253,10 +238,9 @@ class ArchiveTestCase(TestCase):
)
self.assertEqual(['salt'], ret)
mock.assert_called_once_with(
'unzip -fo /tmp/salt.{{grains.id}}.zip -d /tmp/dest '
'-x /tmp/tmpePe8yO /tmp/tmpLeSw1A',
runas=None,
template='jinja'
['unzip', '-fo', '/tmp/salt.{{grains.id}}.zip', '-d',
'/tmp/dest', '-x', '/tmp/tmpePe8yO', '/tmp/tmpLeSw1A'],
python_shell=False, template='jinja'
)
def test_unzip(self):
@ -294,10 +278,9 @@ class ArchiveTestCase(TestCase):
)
self.assertEqual(['salt'], ret)
mock.assert_called_once_with(
'rar a -idp /tmp/rarfile.rar '
'/tmp/sourcefile1 /tmp/sourcefile2',
runas=None,
template=None
['rar', 'a', '-idp', '/tmp/rarfile.rar',
'/tmp/sourcefile1', '/tmp/sourcefile2'],
runas=None, python_shell=False, template=None, cwd=None
)
mock = MagicMock(return_value='salt')
@ -308,10 +291,9 @@ class ArchiveTestCase(TestCase):
)
self.assertEqual(['salt'], ret)
mock.assert_called_once_with(
'rar a -idp /tmp/rarfile.rar '
'/tmp/sourcefile1 /tmp/sourcefile2',
runas=None,
template=None
['rar', 'a', '-idp', '/tmp/rarfile.rar',
'/tmp/sourcefile1', '/tmp/sourcefile2'],
runas=None, python_shell=False, template=None, cwd=None
)
@patch('salt.utils.which', lambda exe: None)
@ -338,10 +320,9 @@ class ArchiveTestCase(TestCase):
)
self.assertEqual(['salt'], ret)
mock.assert_called_once_with(
'unrar x -idp /tmp/rarfile.rar '
'-x file_1 -x file_2 /home/strongbad/',
runas=None,
template=None
['unrar', 'x', '-idp', '/tmp/rarfile.rar',
'-x', 'file_1', '-x', 'file_2', '/home/strongbad/'],
runas=None, python_shell=False, template=None
)
mock = MagicMock(return_value='salt')
@ -353,10 +334,9 @@ class ArchiveTestCase(TestCase):
)
self.assertEqual(['salt'], ret)
mock.assert_called_once_with(
'unrar x -idp /tmp/rarfile.rar '
'-x file_1 -x file_2 /home/strongbad/',
runas=None,
template=None
['unrar', 'x', '-idp', '/tmp/rarfile.rar',
'-x', 'file_1', '-x', 'file_2', '/home/strongbad/'],
runas=None, python_shell=False, template=None
)
@patch('salt.utils.which_bin', lambda exe: None)

View file

@ -24,7 +24,8 @@ class TestBlockdevModule(TestCase):
mock.assert_called_once_with(
'blockdev --getro --getsz --getss --getpbsz --getiomin '
'--getioopt --getalignoff --getmaxsect --getsize '
'--getsize64 --getra --getfra /dev/sda'
'--getsize64 --getra --getfra /dev/sda',
python_shell=False
)
def test_wipe(self):
@ -32,7 +33,8 @@ class TestBlockdevModule(TestCase):
with patch.dict(blockdev.__salt__, {'cmd.run_all': mock}):
blockdev.wipe('/dev/sda')
mock.assert_called_once_with(
'wipefs /dev/sda'
'wipefs /dev/sda',
python_shell=False
)
def test_tune(self):
@ -43,7 +45,8 @@ class TestBlockdevModule(TestCase):
kwargs = {'read-ahead': 512, 'filesystem-read-ahead': 512}
blockdev.tune('/dev/sda', **kwargs)
mock.assert_called_once_with(
'blockdev --setra 512 --setfra 512 /dev/sda'
'blockdev --setra 512 --setfra 512 /dev/sda',
python_shell=False
)

View file

@ -29,7 +29,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
def test_install_editable_withough_egg_fails(self):
@ -59,7 +60,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
# Passing editables as a comma separated list
@ -73,7 +75,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
def test_install_multiple_pkgs_and_editables(self):
@ -98,7 +101,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
# Passing editables as a comma separated list
@ -112,7 +116,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
# As a single string
@ -125,7 +130,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
def test_issue5940_install_multiple_pip_mirrors(self):
@ -147,7 +153,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
# Passing mirrors as a comma separated list
@ -162,7 +169,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
# As a single string
@ -175,7 +183,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
def test_install_with_multiple_find_links(self):
@ -197,7 +206,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
# Passing mirrors as a comma separated list
@ -212,7 +222,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
# Passing mirrors as a single string entry
@ -224,7 +235,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
# Invalid proto raises exception
@ -255,7 +267,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
def test_install_no_index_with_index_url_or_extra_index_url_raises(self):
@ -294,7 +307,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
@patch('os.path')
@ -315,7 +329,9 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False)
use_vt=False,
python_shell=False,
)
@patch('os.path')
def test_install_log_argument_in_resulting_command(self, mock_path):
@ -327,7 +343,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
# Let's fake a non-writable log file
@ -351,7 +368,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
# Passing an int as a string
@ -363,7 +381,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
# Passing a non-int to timeout
@ -385,7 +404,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
def test_install_extra_index_url_argument_in_resulting_command(self):
@ -397,7 +417,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
def test_install_no_index_argument_in_resulting_command(self):
@ -409,7 +430,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
def test_install_build_argument_in_resulting_command(self):
@ -421,7 +443,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
def test_install_target_argument_in_resulting_command(self):
@ -433,7 +456,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
def test_install_download_argument_in_resulting_command(self):
@ -445,7 +469,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
def test_install_no_download_argument_in_resulting_command(self):
@ -457,7 +482,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
def test_install_download_cache_argument_in_resulting_command(self):
@ -469,7 +495,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
def test_install_source_argument_in_resulting_command(self):
@ -481,7 +508,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
def test_install_exists_action_argument_in_resulting_command(self):
@ -494,7 +522,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
# Test for invalid action
@ -524,7 +553,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
# Passing mirrors as a comma separated list
@ -538,7 +568,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
# Passing mirrors as a single string entry
@ -551,7 +582,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
def test_install_global_options_argument_in_resulting_command(self):
@ -571,7 +603,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
# Passing mirrors as a comma separated list
@ -585,7 +618,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
# Passing mirrors as a single string entry
@ -597,7 +631,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
def test_install_upgrade_argument_in_resulting_command(self):
@ -609,7 +644,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
def test_install_force_reinstall_argument_in_resulting_command(self):
@ -621,7 +657,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
def test_install_ignore_installed_argument_in_resulting_command(self):
@ -633,7 +670,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
def test_install_no_deps_argument_in_resulting_command(self):
@ -645,7 +683,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
def test_install_no_install_argument_in_resulting_command(self):
@ -657,7 +696,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
def test_install_proxy_argument_in_resulting_command(self):
@ -670,7 +710,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
@patch('salt.modules.pip._get_cached_requirements')
@ -693,7 +734,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
# Passing option as a comma separated list
@ -710,7 +752,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
# Passing option as a single string entry
@ -723,7 +766,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
@patch('salt.modules.pip._get_cached_requirements')
@ -746,7 +790,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
# Passing option as a comma separated list
@ -763,7 +808,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
# Passing option as a single string entry
@ -776,7 +822,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
def test_uninstall_proxy_argument_in_resulting_command(self):
@ -791,7 +838,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
@patch('os.path')
@ -804,7 +852,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
# Let's fake a non-writable log file
@ -828,7 +877,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
# Passing an int as a string
@ -840,7 +890,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
# Passing a non-int to timeout
@ -873,7 +924,8 @@ class PipTestCase(TestCase):
'pip freeze',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
self.assertEqual(ret, eggs)
@ -904,7 +956,8 @@ class PipTestCase(TestCase):
mock.assert_called_with(
'pip freeze',
runas=None,
cwd=None
cwd=None,
python_shell=False,
)
self.assertEqual(
ret, {
@ -944,7 +997,8 @@ class PipTestCase(TestCase):
mock.assert_called_with(
'pip freeze',
runas=None,
cwd=None
cwd=None,
python_shell=False,
)
self.assertEqual(
ret, {
@ -969,7 +1023,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
mock = MagicMock(side_effect=[
@ -985,7 +1040,8 @@ class PipTestCase(TestCase):
saltenv='base',
runas=None,
cwd=None,
use_vt=False
use_vt=False,
python_shell=False,
)
def test_install_deprecated_runas_triggers_warning(self):
@ -1056,7 +1112,7 @@ class PipTestCase(TestCase):
pip.install,
'pep8',
user='Me!',
runas='Not Me!'
runas='Not Me!',
)
def test_uninstall_user_and_runas_raises_exception(self):
@ -1067,7 +1123,7 @@ class PipTestCase(TestCase):
pip.uninstall,
'pep8',
user='Me!',
runas='Not Me!'
runas='Not Me!',
)
def test_freeze_user_and_runas_raises_exception(self):
@ -1078,7 +1134,7 @@ class PipTestCase(TestCase):
pip.freeze,
'/tmp/pip-env',
user='Me!',
runas='Not Me!'
runas='Not Me!',
)
def test_list_user_and_runas_raises_exception(self):
@ -1089,7 +1145,7 @@ class PipTestCase(TestCase):
pip.list_,
'pep8',
user='Me!',
runas='Not Me!'
runas='Not Me!',
)