From 01dcee98d2fe65dee0ca29f10a05448154019181 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Thu, 8 Oct 2015 09:55:52 -0700 Subject: [PATCH] Fix for state=latest with wildcard or virtual provide package names --- packaging/os/yum.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/packaging/os/yum.py b/packaging/os/yum.py index b54df227973..bcf9b283a95 100644 --- a/packaging/os/yum.py +++ b/packaging/os/yum.py @@ -755,7 +755,11 @@ def latest(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos): if update_all: cmd = yum_basecmd + ['update'] + will_update = set(updates.keys()) + will_update_from_other_package = dict() else: + will_update = set() + will_update_from_other_package = dict() for spec in items: # some guess work involved with groups. update @ will install the group if missing if spec.startswith('@'): @@ -779,8 +783,19 @@ def latest(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos): nothing_to_do = False break - if spec in pkgs['update'] and spec in updates.keys(): - nothing_to_do = False + # this contains the full NVR and spec could contain wildcards + # 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: 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) 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 if module.check_mode: to_update = [] @@ -806,6 +815,9 @@ def latest(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos): if w.startswith('@'): to_update.append((w, None)) 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: to_update.append((w, '%s.%s from %s' % (updates[w]['version'], updates[w]['dist'], updates[w]['repo'])))