Skip to content

Commit

Permalink
Fix dnf module crash for non-existent url (ansible#81801)
Browse files Browse the repository at this point in the history
* ci_complete ci_coverage
  • Loading branch information
s-hertel committed Oct 3, 2023
1 parent 116766a commit b3408ab
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelogs/fragments/fix-dnf-install-missing-url.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- Fix handling missing urls in ansible.module_utils.urls.fetch_file for Python 3.
2 changes: 1 addition & 1 deletion lib/ansible/module_utils/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2058,7 +2058,7 @@ def fetch_file(module, url, data=None, headers=None, method=None,
try:
rsp, info = fetch_url(module, url, data, headers, method, use_proxy, force, last_mod_time, timeout,
unredirected_headers=unredirected_headers, decompress=decompress, ciphers=ciphers)
if not rsp:
if not rsp or (rsp.code and rsp.code >= 400):
module.fail_json(msg="Failure downloading %s, %s" % (url, info['msg']))
data = rsp.read(bufsize)
while data:
Expand Down
1 change: 1 addition & 0 deletions test/integration/targets/dnf/tasks/dnf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@
that:
- "dnf_result is failed"
- "not dnf_result.changed"
- "'Failure downloading' in dnf_result.msg or 'Failed to download' in dnf_result.msg"

- name: verify dnf module outputs
assert:
Expand Down

0 comments on commit b3408ab

Please sign in to comment.