mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-21 00:19:09 -07:00
yum: handle exception in local_envra (#34400)
This fix adds rpm.error exception which is raised when API unable to get envra information from RPM package. Also, adds integration test for local_envra method. Fixes: #30074 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
9c7d987395
commit
b14c8b130f
2 changed files with 34 additions and 0 deletions
|
@ -614,6 +614,8 @@ def local_envra(path):
|
|||
fd = os.open(path, os.O_RDONLY)
|
||||
try:
|
||||
header = ts.hdrFromFdno(fd)
|
||||
except rpm.error as e:
|
||||
return None
|
||||
finally:
|
||||
os.close(fd)
|
||||
|
||||
|
@ -752,6 +754,8 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos, i
|
|||
|
||||
# most common case is the pkg is already installed
|
||||
envra = local_envra(package)
|
||||
if envra is None:
|
||||
module.fail_json(msg="Failed to get nevra information from RPM package: %s" % spec)
|
||||
installed_pkgs = is_installed(module, repoq, envra, conf_file, en_repos=en_repos, dis_repos=dis_repos, installroot=installroot)
|
||||
if installed_pkgs:
|
||||
res['results'].append('%s providing %s is already installed' % (installed_pkgs[0], package))
|
||||
|
@ -1046,6 +1050,9 @@ def latest(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos, up
|
|||
# get the pkg e:name-v-r.arch
|
||||
envra = local_envra(spec)
|
||||
|
||||
if envra is None:
|
||||
module.fail_json(msg="Failed to get nevra information from RPM package: %s" % spec)
|
||||
|
||||
# local rpm files can't be updated
|
||||
if not is_installed(module, repoq, envra, conf_file, en_repos=en_repos, dis_repos=dis_repos, installroot=installroot):
|
||||
pkgs['install'].append(spec)
|
||||
|
@ -1057,6 +1064,9 @@ def latest(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos, up
|
|||
package = fetch_rpm_from_url(spec, module=module)
|
||||
envra = local_envra(package)
|
||||
|
||||
if envra is None:
|
||||
module.fail_json(msg="Failed to get nevra information from RPM package: %s" % spec)
|
||||
|
||||
# local rpm files can't be updated
|
||||
if not is_installed(module, repoq, envra, conf_file, en_repos=en_repos, dis_repos=dis_repos, installroot=installroot):
|
||||
pkgs['install'].append(package)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue