Fix for state=latest with wildcard or virtual provide package names

This commit is contained in:
Toshio Kuratomi 2015-10-08 09:55:52 -07:00
parent 5f1f1b2904
commit 01dcee98d2

View file

@ -755,7 +755,11 @@ def latest(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos):
if update_all: if update_all:
cmd = yum_basecmd + ['update'] cmd = yum_basecmd + ['update']
will_update = set(updates.keys())
will_update_from_other_package = dict()
else: else:
will_update = set()
will_update_from_other_package = dict()
for spec in items: for spec in items:
# some guess work involved with groups. update @<group> will install the group if missing # some guess work involved with groups. update @<group> will install the group if missing
if spec.startswith('@'): if spec.startswith('@'):
@ -779,8 +783,19 @@ def latest(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos):
nothing_to_do = False nothing_to_do = False
break break
if spec in pkgs['update'] and spec in updates.keys(): # this contains the full NVR and spec could contain wildcards
nothing_to_do = False # or virtual provides (like "python-*" or "smtp-daemon") while
# updates contains name only.
this_name_only = '-'.join(this.split('-')[:-2])
if spec in pkgs['update'] and this_name_only in updates.keys():
nothing_to_do = False
will_update.add(spec)
# Massage the updates list
if spec != this_name_only:
# For reporting what packages would be updated more
# succinctly
will_update_from_other_package[spec] = this_name_only
break
if nothing_to_do: if nothing_to_do:
res['results'].append("All packages providing %s are up to date" % spec) res['results'].append("All packages providing %s are up to date" % spec)
@ -793,12 +808,6 @@ def latest(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos):
res['msg'] += "The following packages have pending transactions: %s" % ", ".join(conflicts) res['msg'] += "The following packages have pending transactions: %s" % ", ".join(conflicts)
module.fail_json(**res) module.fail_json(**res)
# list of package updates
if update_all:
will_update = updates.keys()
else:
will_update = [u for u in pkgs['update'] if u in updates.keys() or u.startswith('@')]
# check_mode output # check_mode output
if module.check_mode: if module.check_mode:
to_update = [] to_update = []
@ -806,6 +815,9 @@ def latest(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos):
if w.startswith('@'): if w.startswith('@'):
to_update.append((w, None)) to_update.append((w, None))
msg = '%s will be updated' % w msg = '%s will be updated' % w
elif w not in updates:
other_pkg = will_update_from_other_package[w]
to_update.append((w, 'because of (at least) %s-%s.%s from %s' % (other_pkg, updates[other_pkg]['version'], updates[other_pkg]['dist'], updates[other_pkg]['repo'])))
else: else:
to_update.append((w, '%s.%s from %s' % (updates[w]['version'], updates[w]['dist'], updates[w]['repo']))) to_update.append((w, '%s.%s from %s' % (updates[w]['version'], updates[w]['dist'], updates[w]['repo'])))