Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2016.3] Merge forward from 2015.8 to 2016.3 #34452

Merged
merged 11 commits into from
Jul 5, 2016
3 changes: 3 additions & 0 deletions salt/beacons/inotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
setting the `disable_during_state_run` flag to `True` in
the beacon configuration.

:note: The `inotify` beacon only works on OSes that have `inotify` kernel support.
Currently this excludes FreeBSD, Mac OS X, and Windows.

'''
# Import Python libs
from __future__ import absolute_import
Expand Down
76 changes: 66 additions & 10 deletions salt/modules/rpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,20 +590,76 @@ def version_cmp(ver1, ver2):
salt '*' pkg.version_cmp '0.2-001' '0.2.0.1-002'
'''
try:
cmp_func = None
if HAS_RPM:
cmp_func = rpm.labelCompare
elif HAS_RPMUTILS:
cmp_func = rpmUtils.miscutils.compareEVR
try:
cmp_func = rpm.labelCompare
except AttributeError:
# Catches corner case where someone has a module named "rpm" in
# their pythonpath.
log.debug(
'rpm module imported, but it does not have the '
'labelCompare function. Not using rpm.labelCompare for '
'version comparison.'
)
if cmp_func is None and HAS_RPMUTILS:
try:
cmp_func = rpmUtils.miscutils.compareEVR
except AttributeError:
log.debug('rpmUtils.miscutils.compareEVR is not available')

if cmp_func is None:
if salt.utils.which('rpmdev-vercmp'):
# rpmdev-vercmp always uses epochs, even when zero
def _ensure_epoch(ver):
def _prepend(ver):
return '0:{0}'.format(ver)

try:
if ':' not in ver:
return _prepend(ver)
except TypeError:
return _prepend(ver)
return ver

ver1 = _ensure_epoch(ver1)
ver2 = _ensure_epoch(ver2)
result = __salt__['cmd.run'](['rpmdev-vercmp', ver1, ver2],
python_shell=False,
ignore_retcode=True).strip()
if result.endswith('equal'):
return 0
elif 'is newer' in result:
newer_version = result.split()[0]
if newer_version == ver1:
return 1
elif newer_version == ver2:
return -1
log.warning(
'Failed to interpret results of rpmdev-vercmp output: %s',
result
)
else:
# We'll need to fall back to salt.utils.version_cmp()
log.warning(
'rpmdevtools is not installed, please install it for '
'more accurate version comparisons'
)
else:
cmp_func = None
cmp_result = cmp_func is None and 2 or cmp_func(salt.utils.str_version_to_evr(ver1),
salt.utils.str_version_to_evr(ver2))
if cmp_result not in (-1, 0, 1):
raise Exception("Comparison result '{0}' is invalid".format(cmp_result))
cmp_result = cmp_func(salt.utils.str_version_to_evr(ver1),
salt.utils.str_version_to_evr(ver2))
if cmp_result not in (-1, 0, 1):
raise CommandExecutionError(
'Comparison result \'{0}\' is invalid'.format(cmp_result)
)

return cmp_result

return cmp_result
except Exception as exc:
log.warning("Failed to compare version '{0}' to '{1}' using RPM: {2}".format(ver1, ver2, exc))
log.warning(
'Failed to compare version \'%s\' to \'%s\' using RPM: %s',
ver1, ver2, exc
)

return salt.utils.version_cmp(ver1, ver2)

Expand Down
4 changes: 4 additions & 0 deletions salt/states/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,10 @@ def mod_watch(name,
ret['comment'] = 'Service is set to be {0}'.format(past_participle)
return ret

if verb == 'start' and 'service.stop' in __salt__:
# stop service before start
__salt__['service.stop'](name)

result = func(name)
if init_delay:
time.sleep(init_delay)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1250,11 +1250,11 @@ def run_ssh(self, arg_str, with_retcode=False, catch_stderr=False):
arg_str = '-W -c {0} -i --priv {1} --roster-file {2} --out=json localhost {3}'.format(self.get_config_dir(), os.path.join(TMP_CONF_DIR, 'key_test'), os.path.join(TMP_CONF_DIR, 'roster'), arg_str)
return self.run_script('salt-ssh', arg_str, with_retcode=with_retcode, catch_stderr=catch_stderr, raw=True)

def run_run(self, arg_str, with_retcode=False, catch_stderr=False, async=False, timeout=60):
def run_run(self, arg_str, with_retcode=False, catch_stderr=False, async=False, timeout=60, config_dir=None):
'''
Execute salt-run
'''
arg_str = '-c {0}{async_flag} -t {timeout} {1}'.format(self.get_config_dir(),
arg_str = '-c {0}{async_flag} -t {timeout} {1}'.format(config_dir or self.get_config_dir(),
arg_str,
timeout=timeout,
async_flag=' --async' if async else '')
Expand Down