Merge pull request #36609 from rallytime/merge-2016.3

[2016.3] Merge forward from 2015.8 to 2016.3
This commit is contained in:
Nicole Thomas 2016-09-27 12:34:22 -06:00 committed by GitHub
commit e23af98d97
2 changed files with 40 additions and 0 deletions

View File

@ -1725,3 +1725,35 @@ def updating(name,
output_loglevel='trace',
python_shell=False
)
def version_cmp(pkg1, pkg2, ignore_epoch=False):
'''
Do a cmp-style comparison on two packages. Return -1 if pkg1 < pkg2, 0 if
pkg1 == pkg2, and 1 if pkg1 > pkg2. Return None if there was a problem
making the comparison.
CLI Example:
.. code-block:: bash
salt '*' pkg.version_cmp '2.1.11' '2.1.12'
'''
# Don't worry about ignore_epoch since we're shelling out to pkg.
sym = {
'<': -1,
'>': 1,
'=': 0,
}
try:
cmd = ['pkg', 'version', '--test-version', pkg1, pkg2]
ret = __salt__['cmd.run_all'](cmd,
output_loglevel='trace',
python_shell=False,
ignore_retcode=True)
except Exception as exc:
log.error(exc)
if ret['stdout'] in sym:
return sym[ret['stdout']]
return None

View File

@ -165,6 +165,10 @@ def _fulfills_version_spec(versions, oper, desired_version,
otherwise returns False
'''
cmp_func = __salt__.get('pkg.version_cmp')
# stripping "with_origin" dict wrapper
if salt.utils.is_freebsd():
if isinstance(versions, dict) and 'version' in versions:
versions = versions['version']
for ver in versions:
if salt.utils.compare_versions(ver1=ver,
oper=oper,
@ -1265,10 +1269,14 @@ def installed(
not_modified_hold = None
failed_hold = None
if targets or to_reinstall:
force = False
if salt.utils.is_freebsd():
force = True # Downgrades need to be forced.
try:
pkg_ret = __salt__['pkg.install'](name,
refresh=refresh,
version=version,
force=force,
fromrepo=fromrepo,
skip_verify=skip_verify,
pkgs=pkgs,