mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge branch '2015.8' into '2016.3'
No conflicts.
This commit is contained in:
commit
91120dba01
4 changed files with 76 additions and 13 deletions
|
@ -10,6 +10,9 @@ Watch files and translate the changes into salt events
|
|||
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
|
||||
|
|
|
@ -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
|
||||
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))
|
||||
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_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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1250,11 +1250,11 @@ class ShellCase(AdaptedConfigurationTestCaseMixIn, ShellTestCase):
|
|||
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 '')
|
||||
|
|
Loading…
Add table
Reference in a new issue