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)
|
fd = os.open(path, os.O_RDONLY)
|
||||||
try:
|
try:
|
||||||
header = ts.hdrFromFdno(fd)
|
header = ts.hdrFromFdno(fd)
|
||||||
|
except rpm.error as e:
|
||||||
|
return None
|
||||||
finally:
|
finally:
|
||||||
os.close(fd)
|
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
|
# most common case is the pkg is already installed
|
||||||
envra = local_envra(package)
|
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)
|
installed_pkgs = is_installed(module, repoq, envra, conf_file, en_repos=en_repos, dis_repos=dis_repos, installroot=installroot)
|
||||||
if installed_pkgs:
|
if installed_pkgs:
|
||||||
res['results'].append('%s providing %s is already installed' % (installed_pkgs[0], package))
|
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
|
# get the pkg e:name-v-r.arch
|
||||||
envra = local_envra(spec)
|
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
|
# 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):
|
if not is_installed(module, repoq, envra, conf_file, en_repos=en_repos, dis_repos=dis_repos, installroot=installroot):
|
||||||
pkgs['install'].append(spec)
|
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)
|
package = fetch_rpm_from_url(spec, module=module)
|
||||||
envra = local_envra(package)
|
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
|
# 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):
|
if not is_installed(module, repoq, envra, conf_file, en_repos=en_repos, dis_repos=dis_repos, installroot=installroot):
|
||||||
pkgs['install'].append(package)
|
pkgs['install'].append(package)
|
||||||
|
|
|
@ -557,3 +557,27 @@
|
||||||
- "'msg' in yum_result"
|
- "'msg' in yum_result"
|
||||||
- "'rc' in yum_result"
|
- "'rc' in yum_result"
|
||||||
- "'results' in yum_result"
|
- "'results' in yum_result"
|
||||||
|
|
||||||
|
- name: Create a temp RPM file which does not contain nevra information
|
||||||
|
file:
|
||||||
|
name: "/tmp/non_existent_pkg.rpm"
|
||||||
|
state: touch
|
||||||
|
|
||||||
|
- name: Try installing RPM file which does not contain nevra information
|
||||||
|
yum:
|
||||||
|
name: "/tmp/non_existent_pkg.rpm"
|
||||||
|
state: present
|
||||||
|
register: no_nevra_info_result
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: Verify RPM failed to install
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "'changed' in no_nevra_info_result"
|
||||||
|
- "'msg' in no_nevra_info_result"
|
||||||
|
- "'Failed to get nevra information from RPM package' in no_nevra_info_result.msg"
|
||||||
|
|
||||||
|
- name: Delete a temp RPM file
|
||||||
|
file:
|
||||||
|
name: "/tmp/non_existent_pkg.rpm"
|
||||||
|
state: absent
|
||||||
|
|
Loading…
Add table
Reference in a new issue