Merge pull request #26133 from amontalban/fix-bug-25915

Fixed #25915 in salt/modules/pkgng.py and salt/states/pkg.py
This commit is contained in:
C. R. Oldham 2015-08-08 15:05:04 -06:00
commit 3eac28f0f9
2 changed files with 44 additions and 7 deletions

View File

@ -884,8 +884,17 @@ def remove(name=None,
except MinionError as exc: except MinionError as exc:
raise CommandExecutionError(exc) raise CommandExecutionError(exc)
old = list_pkgs(jail=jail, chroot=chroot) targets = []
targets = [x for x in pkg_params if x in old] old = list_pkgs(jail=jail, chroot=chroot, with_origin=True)
for pkg in pkg_params.items():
# FreeBSD pkg supports `openjdk` and `java/openjdk7` package names
if pkg[0].find("/") > 0:
origin = pkg[0]
pkg = [k for k, v in old.iteritems() if v['origin'] == origin][0]
if pkg[0] in old:
targets.append(pkg[0])
if not targets: if not targets:
return {} return {}
@ -915,7 +924,7 @@ def remove(name=None,
__salt__['cmd.run'](cmd, python_shell=False, output_loglevel='trace') __salt__['cmd.run'](cmd, python_shell=False, output_loglevel='trace')
__context__.pop(_contextkey(jail, chroot), None) __context__.pop(_contextkey(jail, chroot), None)
__context__.pop(_contextkey(jail, chroot, prefix='pkg.origin'), None) __context__.pop(_contextkey(jail, chroot, prefix='pkg.origin'), None)
new = list_pkgs(jail=jail, chroot=chroot) new = list_pkgs(jail=jail, chroot=chroot, with_origin=True)
return salt.utils.compare_dicts(old, new) return salt.utils.compare_dicts(old, new)
# Support pkg.delete to remove packages, since this is the CLI usage # Support pkg.delete to remove packages, since this is the CLI usage

View File

@ -129,6 +129,8 @@ def _find_remove_targets(name=None,
Inspect the arguments to pkg.removed and discover what packages need to Inspect the arguments to pkg.removed and discover what packages need to
be removed. Return a dict of packages to remove. be removed. Return a dict of packages to remove.
''' '''
if __grains__['os'] == 'FreeBSD':
kwargs['with_origin'] = True
cur_pkgs = __salt__['pkg.list_pkgs'](versions_as_list=True, **kwargs) cur_pkgs = __salt__['pkg.list_pkgs'](versions_as_list=True, **kwargs)
if pkgs: if pkgs:
to_remove = _repack_pkgs(pkgs) to_remove = _repack_pkgs(pkgs)
@ -149,8 +151,15 @@ def _find_remove_targets(name=None,
# Check current versions against specified versions # Check current versions against specified versions
targets = [] targets = []
problems = [] problems = []
for pkgname, pkgver in to_remove.items(): for pkgname, pkgver in six.iteritems(to_remove):
# FreeBSD pkg supports `openjdk` and `java/openjdk7` package names
origin = bool(re.search('/', pkgname))
if __grains__['os'] == 'FreeBSD' and origin:
cver = [k for k, v in six.iteritems(cur_pkgs) if v['origin'] == pkgname]
else:
cver = cur_pkgs.get(pkgname, []) cver = cur_pkgs.get(pkgname, [])
# Package not installed, no need to remove # Package not installed, no need to remove
if not cver: if not cver:
continue continue
@ -228,6 +237,9 @@ def _find_install_targets(name=None,
else: else:
ignore_types = [] ignore_types = []
if __grains__['os'] == 'FreeBSD':
kwargs['with_origin'] = True
cur_pkgs = __salt__['pkg.list_pkgs'](versions_as_list=True, **kwargs) cur_pkgs = __salt__['pkg.list_pkgs'](versions_as_list=True, **kwargs)
if any((pkgs, sources)): if any((pkgs, sources)):
if pkgs: if pkgs:
@ -264,7 +276,14 @@ def _find_install_targets(name=None,
to_unpurge = _find_unpurge_targets(desired) to_unpurge = _find_unpurge_targets(desired)
# FreeBSD pkg supports `openjdk` and `java/openjdk7` package names
origin = bool(re.search('/', name))
if __grains__['os'] == 'FreeBSD' and origin:
cver = [k for k, v in six.iteritems(cur_pkgs) if v['origin'] == name]
else:
cver = cur_pkgs.get(name, []) cver = cur_pkgs.get(name, [])
if name not in to_unpurge: if name not in to_unpurge:
if version and version in cver and not pkg_verify: if version and version in cver and not pkg_verify:
# The package is installed and is the correct version # The package is installed and is the correct version
@ -405,7 +424,14 @@ def _verify_install(desired, new_pkgs):
ok = [] ok = []
failed = [] failed = []
for pkgname, pkgver in desired.items(): for pkgname, pkgver in desired.items():
# FreeBSD pkg supports `openjdk` and `java/openjdk7` package names
origin = bool(re.search('/', pkgname))
if __grains__['os'] == 'FreeBSD' and origin:
cver = [k for k, v in six.iteritems(new_pkgs) if v['origin'] == pkgname]
else:
cver = new_pkgs.get(pkgname) cver = new_pkgs.get(pkgname)
if not cver: if not cver:
failed.append(pkgname) failed.append(pkgname)
continue continue
@ -1021,6 +1047,8 @@ def installed(
not_modified = [x for x in desired if x not in targets and x not in to_reinstall] not_modified = [x for x in desired if x not in targets and x not in to_reinstall]
failed = [x for x in targets if x not in modified] failed = [x for x in targets if x not in modified]
else: else:
if __grains__['os'] == 'FreeBSD':
kwargs['with_origin'] = True
ok, failed = \ ok, failed = \
_verify_install( _verify_install(
desired, __salt__['pkg.list_pkgs']( desired, __salt__['pkg.list_pkgs'](