yum: use envra instead of nevra (#28284)

This commit is contained in:
Martin Krizek 2017-08-29 19:26:42 +02:00 committed by ansibot
parent aec1dfd1fa
commit e4ea999e6d

View file

@ -274,7 +274,7 @@ from ansible.module_utils.urls import fetch_url
# 64k. Number of bytes to read at a time when manually downloading pkgs via a url
BUFSIZE = 65536
def_qf = "%{name}-%{version}-%{release}.%{arch}"
def_qf = "%{epoch}:%{name}-%{version}-%{release}.%{arch}"
rpmbin = None
@ -335,12 +335,11 @@ def fetch_rpm_from_url(spec, module=None):
module.fail_json(msg="Failure downloading %s, %s" % (spec, e))
return package_file.name
def po_to_nevra(po):
if hasattr(po, 'ui_nevra'):
return po.ui_nevra
def po_to_envra(po):
if hasattr(po, 'ui_envra'):
return po.ui_envra
else:
return '%s-%s-%s.%s' % (po.name, po.version, po.release, po.arch)
return '%s:%s-%s-%s.%s' % (po.epoch, po.name, po.version, po.release, po.arch)
def is_group_installed(name):
@ -377,7 +376,7 @@ def is_installed(module, repoq, pkgspec, conf_file, qf=def_qf, en_repos=None, di
e = get_exception()
module.fail_json(msg="Failure talking to yum: %s" % e)
return [po_to_nevra(p) for p in pkgs]
return [po_to_envra(p) for p in pkgs]
else:
global rpmbin
@ -438,7 +437,7 @@ def is_available(module, repoq, pkgspec, conf_file, qf=def_qf, en_repos=None, di
e = get_exception()
module.fail_json(msg="Failure talking to yum: %s" % e)
return [po_to_nevra(p) for p in pkgs]
return [po_to_envra(p) for p in pkgs]
else:
myrepoq = list(repoq)
@ -490,7 +489,7 @@ def is_update(module, repoq, pkgspec, conf_file, qf=def_qf, en_repos=None, dis_r
if pkg in updates:
retpkgs.append(pkg)
return set([po_to_nevra(p) for p in retpkgs])
return set([po_to_envra(p) for p in retpkgs])
else:
myrepoq = list(repoq)
@ -538,7 +537,7 @@ def what_provides(module, repoq, req_spec, conf_file, qf=def_qf, en_repos=None,
e = get_exception()
module.fail_json(msg="Failure talking to yum: %s" % e)
return set([po_to_nevra(p) for p in pkgs])
return set([po_to_envra(p) for p in pkgs])
else:
myrepoq = list(repoq)
@ -602,8 +601,8 @@ def transaction_exists(pkglist):
break
return conflicts
def local_nvra(module, path):
"""return nvra of a local rpm passed in"""
def local_envra(module, path):
"""return envra of a local rpm passed in"""
ts = rpm.TransactionSet()
ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES)
@ -613,10 +612,11 @@ def local_nvra(module, path):
finally:
os.close(fd)
return '%s-%s-%s.%s' % (header[rpm.RPMTAG_NAME],
header[rpm.RPMTAG_VERSION],
header[rpm.RPMTAG_RELEASE],
header[rpm.RPMTAG_ARCH])
return '%s:%s-%s-%s.%s' % (header[rpm.RPMTAG_EPOCH],
header[rpm.RPMTAG_NAME],
header[rpm.RPMTAG_VERSION],
header[rpm.RPMTAG_RELEASE],
header[rpm.RPMTAG_ARCH])
def pkg_to_dict(pkgstr):
@ -632,7 +632,7 @@ def pkg_to_dict(pkgstr):
'release':r,
'version':v,
'repo':repo,
'nevra': '%s:%s-%s-%s.%s' % (e, n, v, r, a)
'envra': '%s:%s-%s-%s.%s' % (e, n, v, r, a)
}
if repo == 'installed':
@ -738,10 +738,10 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos, i
res['rc'] = 127 # Ensure the task fails in with-loop
module.fail_json(**res)
nvra = local_nvra(module, spec)
envra = local_envra(module, spec)
# look for them in the rpmdb
if is_installed(module, repoq, nvra, conf_file, en_repos=en_repos, dis_repos=dis_repos, installroot=installroot):
if is_installed(module, repoq, envra, conf_file, en_repos=en_repos, dis_repos=dis_repos, installroot=installroot):
# if they are there, skip it
continue
pkg = spec
@ -750,8 +750,8 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos, i
elif '://' in spec:
# download package so that we can check if it's already installed
package = fetch_rpm_from_url(spec, module=module)
nvra = local_nvra(module, package)
if is_installed(module, repoq, nvra, conf_file, en_repos=en_repos, dis_repos=dis_repos, installroot=installroot):
envra = local_envra(module, package)
if is_installed(module, repoq, envra, conf_file, en_repos=en_repos, dis_repos=dis_repos, installroot=installroot):
# if it's there, skip it
continue
pkg = package
@ -1008,11 +1008,11 @@ def latest(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos, in
res['rc'] = 127 # Ensure the task fails in with-loop
module.fail_json(**res)
# get the pkg name-v-r.arch
nvra = local_nvra(module, spec)
# get the pkg e:name-v-r.arch
envra = local_envra(module, spec)
# local rpm files can't be updated
if not is_installed(module, repoq, nvra, conf_file, en_repos=en_repos, dis_repos=dis_repos, installroot=installroot):
if not is_installed(module, repoq, envra, conf_file, en_repos=en_repos, dis_repos=dis_repos, installroot=installroot):
pkgs['install'].append(spec)
continue
@ -1020,10 +1020,10 @@ def latest(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos, in
elif '://' in spec:
# download package so that we can check if it's already installed
package = fetch_rpm_from_url(spec, module=module)
nvra = local_nvra(module, package)
envra = local_envra(module, package)
# local rpm files can't be updated
if not is_installed(module, repoq, nvra, conf_file, en_repos=en_repos, dis_repos=dis_repos, installroot=installroot):
if not is_installed(module, repoq, envra, conf_file, en_repos=en_repos, dis_repos=dis_repos, installroot=installroot):
pkgs['install'].append(package)
continue