Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/2015.8' into merge-forward-dev…
Browse files Browse the repository at this point in the history
…elop

Conflicts:
    salt/modules/git.py
    salt/renderers/gpg.py
    salt/utils/__init__.py
  • Loading branch information
basepi committed Nov 17, 2015
2 parents 4cb07cf + f172a0e commit d76d628
Show file tree
Hide file tree
Showing 18 changed files with 419 additions and 316 deletions.
2 changes: 1 addition & 1 deletion doc/topics/releases/2015.8.2.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
===========================
Salt 2015.8.1 Release Notes
Salt 2015.8.2 Release Notes
===========================

Extended changelog courtesy of Todd Stansell (https://github.com/tjstansell/salt-changelogs):
Expand Down
4 changes: 2 additions & 2 deletions doc/topics/windows/windows-package-manager.rst
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ of ``salt-run``:

.. code-block:: bash
salt-call win_repo.update_git_repos
salt-call win_repo.genrepo
salt-call winrepo.update_git_repos
salt-call winrepo.genrepo
salt-call pkg.refresh_db
After executing the previous commands the repository on the standalone system
Expand Down
2 changes: 1 addition & 1 deletion salt/client/ssh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ def run(self, jid=None):
self.cache_job(jid, host, ret[host], fun)
ret = self.key_deploy(host, ret)

if ret[host].get('stderr', '').startswith('ssh:'):
if isinstance(ret[host], dict) and ret[host].get('stderr', '').startswith('ssh:'):
ret[host] = ret[host]['stderr']

if not isinstance(ret[host], dict):
Expand Down
15 changes: 9 additions & 6 deletions salt/grains/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1214,12 +1214,15 @@ def os_data():
elif os.path.isfile('/etc/SuSE-release'):
grains['lsb_distrib_id'] = 'SUSE'
with salt.utils.fopen('/etc/SuSE-release') as fhr:
rel = re.sub("[^0-9]", "", fhr.read().split('\n')[1])
with salt.utils.fopen('/etc/SuSE-release') as fhr:
patch = re.sub("[^0-9]", "", fhr.read().split('\n')[2])
release = rel + " SP" + patch
grains['lsb_distrib_release'] = release
grains['lsb_distrib_codename'] = "n.a"
for line in fhr:
if 'enterprise' in line.lower():
grains['lsb_distrib_id'] = 'SLES'
elif 'version' in line.lower():
version = re.sub(r'[^0-9]', '', line)
elif 'patchlevel' in line.lower():
patch = re.sub(r'[^0-9]', '', line)
grains['lsb_distrib_release'] = version + ' SP' + patch
grains['lsb_distrib_codename'] = 'n.a'
elif os.path.isfile('/etc/altlinux-release'):
# ALT Linux
grains['lsb_distrib_id'] = 'altlinux'
Expand Down
13 changes: 12 additions & 1 deletion salt/log/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
import logging


class LoggingProfileMixIn(object):
'''
Simple mix-in class to add a trace method to python's logging.
'''

def profile(self, msg, *args, **kwargs):
self.log(getattr(logging, 'PROFILE', 15), msg, *args, **kwargs)


class LoggingTraceMixIn(object):
'''
Simple mix-in class to add a trace method to python's logging.
Expand Down Expand Up @@ -45,14 +54,16 @@ class LoggingMixInMeta(type):
the bases.
'''
def __new__(mcs, name, bases, attrs):
include_trace = include_garbage = True
include_profile = include_trace = include_garbage = True
bases = list(bases)
if name == 'SaltLoggingClass':
for base in bases:
if hasattr(base, 'trace'):
include_trace = False
if hasattr(base, 'garbage'):
include_garbage = False
if include_profile:
bases.append(LoggingProfileMixIn)
if include_trace:
bases.append(LoggingTraceMixIn)
if include_garbage:
Expand Down
5 changes: 5 additions & 0 deletions salt/log/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

# Let's define these custom logging levels before importing the salt.log.mixins
# since they will be used there
PROFILE = logging.PROFILE = 15
TRACE = logging.TRACE = 5
GARBAGE = logging.GARBAGE = 1
QUIET = logging.QUIET = 1000
Expand All @@ -54,6 +55,7 @@
'critical': logging.CRITICAL,
'garbage': GARBAGE,
'info': logging.INFO,
'profile': PROFILE,
'quiet': QUIET,
'trace': TRACE,
'warning': logging.WARNING,
Expand All @@ -67,6 +69,7 @@
'ERROR': TextFormat('bold', 'red'),
'WARNING': TextFormat('bold', 'yellow'),
'INFO': TextFormat('bold', 'green'),
'PROFILE': TextFormat('bold', 'cyan'),
'DEBUG': TextFormat('bold', 'cyan'),
'TRACE': TextFormat('bold', 'magenta'),
'GARBAGE': TextFormat('bold', 'blue'),
Expand All @@ -80,6 +83,7 @@
'ERROR': TextFormat('red'),
'WARNING': TextFormat('yellow'),
'INFO': TextFormat('green'),
'PROFILE': TextFormat('bold', 'cyan'),
'DEBUG': TextFormat('cyan'),
'TRACE': TextFormat('magenta'),
'GARBAGE': TextFormat('blue'),
Expand Down Expand Up @@ -366,6 +370,7 @@ def makeRecord(self, name, level, fn, lno, msg, args, exc_info,

logging.setLoggerClass(SaltLoggingClass)
logging.addLevelName(QUIET, 'QUIET')
logging.addLevelName(PROFILE, 'PROFILE')
logging.addLevelName(TRACE, 'TRACE')
logging.addLevelName(GARBAGE, 'GARBAGE')

Expand Down
11 changes: 11 additions & 0 deletions salt/modules/cmdmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,7 @@ def run_all(cmd,
ignore_retcode=False,
saltenv='base',
use_vt=False,
redirect_stderr=False,
**kwargs):
'''
Execute the passed command and return a dict of return data
Expand Down Expand Up @@ -1513,6 +1514,14 @@ def run_all(cmd,
Note that ``env`` represents the environment variables for the command, and
should be formatted as a dict, or a YAML string which resolves to a dict.
redirect_stderr : False
If set to ``True``, then stderr will be redirected to stdout. This is
helpful for cases where obtaining both the retcode and output is
desired, but it is not desired to have the output separated into both
stdout and stderr.
.. versionadded:: 2015.8.2
CLI Example:
.. code-block:: bash
Expand All @@ -1537,10 +1546,12 @@ def run_all(cmd,
'''
python_shell = _python_shell_default(python_shell,
kwargs.get('__pub_jid', ''))
stderr = subprocess.STDOUT if redirect_stderr else subprocess.PIPE
ret = _run(cmd,
runas=runas,
cwd=cwd,
stdin=stdin,
stderr=stderr,
shell=shell,
python_shell=python_shell,
env=env,
Expand Down
57 changes: 48 additions & 9 deletions salt/modules/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import errno
import logging
import os
import re
from distutils.version import LooseVersion as _LooseVersion

# Import salt libs
Expand Down Expand Up @@ -130,7 +131,8 @@ def _format_opts(opts):


def _git_run(command, cwd=None, runas=None, identity=None,
ignore_retcode=False, failhard=True, **kwargs):
ignore_retcode=False, failhard=True, redirect_stderr=False,
**kwargs):
'''
simple, throw an exception with the error message on an error return code.
Expand Down Expand Up @@ -204,6 +206,7 @@ def _git_run(command, cwd=None, runas=None, identity=None,
python_shell=False,
log_callback=salt.utils.url.redact_http_basic_auth,
ignore_retcode=ignore_retcode,
redirect_stderr=redirect_stderr,
**kwargs)
finally:
if not salt.utils.is_windows() and 'GIT_SSH' in env:
Expand Down Expand Up @@ -231,6 +234,7 @@ def _git_run(command, cwd=None, runas=None, identity=None,
python_shell=False,
log_callback=salt.utils.url.redact_http_basic_auth,
ignore_retcode=ignore_retcode,
redirect_stderr=redirect_stderr,
**kwargs)

if result['retcode'] == 0:
Expand Down Expand Up @@ -622,7 +626,8 @@ def checkout(cwd,
return _git_run(command,
cwd=cwd,
runas=user,
ignore_retcode=ignore_retcode)['stderr']
ignore_retcode=ignore_retcode,
redirect_stderr=True)['stdout']


def clone(cwd,
Expand Down Expand Up @@ -1324,6 +1329,10 @@ def fetch(cwd,
identity=None,
ignore_retcode=False):
'''
.. versionchanged:: 2015.8.2
Return data is now a dictionary containing information on branches and
tags that were added/updated
Interface to `git-fetch(1)`_
cwd
Expand Down Expand Up @@ -1398,7 +1407,9 @@ def fetch(cwd,
[x for x in _format_opts(opts) if x not in ('-f', '--force')]
)
if remote:
command.append(str(remote))
if not isinstance(remote, six.string_types):
remote = str(remote)
command.append(remote)
if refspecs is not None:
if isinstance(refspecs, (list, tuple)):
refspec_list = []
Expand All @@ -1412,11 +1423,38 @@ def fetch(cwd,
refspecs = str(refspecs)
refspec_list = refspecs.split(',')
command.extend(refspec_list)
return _git_run(command,
cwd=cwd,
runas=user,
identity=identity,
ignore_retcode=ignore_retcode)['stdout']
output = _git_run(command,
cwd=cwd,
runas=user,
identity=identity,
ignore_retcode=ignore_retcode,
redirect_stderr=True)['stdout']

update_re = re.compile(
r'[\s*]*(?:([0-9a-f]+)\.\.([0-9a-f]+)|'
r'\[(?:new (tag|branch)|tag update)\])\s+(.+)->'
)
ret = {}
for line in salt.utils.itertools.split(output, '\n'):
match = update_re.match(line)
if match:
old_sha, new_sha, new_ref_type, ref_name = \
match.groups()
ref_name = ref_name.rstrip()
if new_ref_type is not None:
# ref is a new tag/branch
ref_key = 'new tags' \
if new_ref_type == 'tag' \
else 'new branches'
ret.setdefault(ref_key, []).append(ref_name)
elif old_sha is not None:
# ref is a branch update
ret.setdefault('updated branches', {})[ref_name] = \
{'old': old_sha, 'new': new_sha}
else:
# ref is an updated tag
ret.setdefault('updated tags', []).append(ref_name)
return ret


def init(cwd,
Expand Down Expand Up @@ -3363,7 +3401,8 @@ def worktree_add(cwd,
return _git_run(command,
cwd=cwd,
runas=user,
ignore_retcode=ignore_retcode)['stderr']
ignore_retcode=ignore_retcode,
redirect_stderr=True)['stdout']


def worktree_prune(cwd,
Expand Down
26 changes: 14 additions & 12 deletions salt/modules/rh_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def __virtual__():
'''
# Enable on these platforms only.
enable = set((
'XenServer',
'RedHat',
'CentOS',
'ScientificLinux',
Expand All @@ -57,6 +58,8 @@ def __virtual__():
'McAfee OS Server'
))
if __grains__['os'] in enable:
if __grains__['os'] == 'XenServer':
return __virtualname__
if __grains__['os'] == 'SUSE':
if str(__grains__['osrelease']).startswith('11'):
return __virtualname__
Expand Down Expand Up @@ -153,23 +156,22 @@ def _sysv_is_enabled(name, runlevel=None):

def _chkconfig_is_enabled(name, runlevel=None):
'''
Return True if the service is enabled according to chkconfig; otherwise
return False. If `runlevel` is None, then use the current runlevel.
Return ``True`` if the service is enabled according to chkconfig; otherwise
return ``False``. If ``runlevel`` is ``None``, then use the current
runlevel.
'''
cmdline = '/sbin/chkconfig --list {0}'.format(name)
result = __salt__['cmd.run_all'](cmdline, python_shell=False)

if runlevel is None:
runlevel = _runlevel()
if result['retcode'] == 0:
cols = result['stdout'].splitlines()[0].split()
try:
if cols[0].strip(':') == name:
if runlevel is None:
runlevel = _runlevel()
if len(cols) > 3 and '{0}:on'.format(runlevel) in cols:
return True
elif len(cols) < 3 and cols[1] and cols[1] == 'on':
for row in result['stdout'].splitlines():
if '{0}:on'.format(runlevel) in row:
if row.split()[0] == name:
return True
except IndexError:
pass
elif row.split() == [name + ':', 'on']:
return True
return False


Expand Down
2 changes: 1 addition & 1 deletion salt/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ def _mod_aggregate(self, low, running, chunks):
Execute the aggregation systems to runtime modify the low chunk
'''
agg_opt = self.functions['config.option']('state_aggregate')
if low.get('aggregate') is True:
if 'aggregate' in low:
agg_opt = low['aggregate']
if agg_opt is True:
agg_opt = [low['state']]
Expand Down
Loading

0 comments on commit d76d628

Please sign in to comment.