mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
yum: do not use get_exception() (#28826)
Python 2.4 support was dropped in Ansible 2.4.
This commit is contained in:
parent
503bfaf38b
commit
f31696f77f
1 changed files with 18 additions and 22 deletions
|
@ -268,7 +268,7 @@ except:
|
||||||
transaction_helpers = False
|
transaction_helpers = False
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.pycompat24 import get_exception
|
from ansible.module_utils._text import to_native
|
||||||
from ansible.module_utils.urls import fetch_url
|
from ansible.module_utils.urls import fetch_url
|
||||||
|
|
||||||
# 64k. Number of bytes to read at a time when manually downloading pkgs via a url
|
# 64k. Number of bytes to read at a time when manually downloading pkgs via a url
|
||||||
|
@ -329,10 +329,12 @@ def fetch_rpm_from_url(spec, module=None):
|
||||||
package_file.write(data)
|
package_file.write(data)
|
||||||
data = rsp.read(BUFSIZE)
|
data = rsp.read(BUFSIZE)
|
||||||
package_file.close()
|
package_file.close()
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = get_exception()
|
|
||||||
if module:
|
if module:
|
||||||
module.fail_json(msg="Failure downloading %s, %s" % (spec, e))
|
module.fail_json(msg="Failure downloading %s, %s" % (spec, to_native(e)))
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
|
|
||||||
return package_file.name
|
return package_file.name
|
||||||
|
|
||||||
def po_to_envra(po):
|
def po_to_envra(po):
|
||||||
|
@ -372,9 +374,8 @@ def is_installed(module, repoq, pkgspec, conf_file, qf=def_qf, en_repos=None, di
|
||||||
pkgs = e + m
|
pkgs = e + m
|
||||||
if not pkgs and not is_pkg:
|
if not pkgs and not is_pkg:
|
||||||
pkgs.extend(my.returnInstalledPackagesByDep(pkgspec))
|
pkgs.extend(my.returnInstalledPackagesByDep(pkgspec))
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = get_exception()
|
module.fail_json(msg="Failure talking to yum: %s" % to_native(e))
|
||||||
module.fail_json(msg="Failure talking to yum: %s" % e)
|
|
||||||
|
|
||||||
return [po_to_envra(p) for p in pkgs]
|
return [po_to_envra(p) for p in pkgs]
|
||||||
|
|
||||||
|
@ -433,9 +434,8 @@ def is_available(module, repoq, pkgspec, conf_file, qf=def_qf, en_repos=None, di
|
||||||
pkgs = e + m
|
pkgs = e + m
|
||||||
if not pkgs:
|
if not pkgs:
|
||||||
pkgs.extend(my.returnPackagesByDep(pkgspec))
|
pkgs.extend(my.returnPackagesByDep(pkgspec))
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = get_exception()
|
module.fail_json(msg="Failure talking to yum: %s" % to_native(e))
|
||||||
module.fail_json(msg="Failure talking to yum: %s" % e)
|
|
||||||
|
|
||||||
return [po_to_envra(p) for p in pkgs]
|
return [po_to_envra(p) for p in pkgs]
|
||||||
|
|
||||||
|
@ -481,9 +481,8 @@ def is_update(module, repoq, pkgspec, conf_file, qf=def_qf, en_repos=None, dis_r
|
||||||
e, m, u = my.pkgSack.matchPackageNames([pkgspec])
|
e, m, u = my.pkgSack.matchPackageNames([pkgspec])
|
||||||
pkgs = e + m
|
pkgs = e + m
|
||||||
updates = my.doPackageLists(pkgnarrow='updates').updates
|
updates = my.doPackageLists(pkgnarrow='updates').updates
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = get_exception()
|
module.fail_json(msg="Failure talking to yum: %s" % to_native(e))
|
||||||
module.fail_json(msg="Failure talking to yum: %s" % e)
|
|
||||||
|
|
||||||
for pkg in pkgs:
|
for pkg in pkgs:
|
||||||
if pkg in updates:
|
if pkg in updates:
|
||||||
|
@ -533,9 +532,8 @@ def what_provides(module, repoq, req_spec, conf_file, qf=def_qf, en_repos=None,
|
||||||
e, m, u = my.rpmdb.matchPackageNames([req_spec])
|
e, m, u = my.rpmdb.matchPackageNames([req_spec])
|
||||||
pkgs.extend(e)
|
pkgs.extend(e)
|
||||||
pkgs.extend(m)
|
pkgs.extend(m)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = get_exception()
|
module.fail_json(msg="Failure talking to yum: %s" % to_native(e))
|
||||||
module.fail_json(msg="Failure talking to yum: %s" % e)
|
|
||||||
|
|
||||||
return set([po_to_envra(p) for p in pkgs])
|
return set([po_to_envra(p) for p in pkgs])
|
||||||
|
|
||||||
|
@ -1209,12 +1207,10 @@ def ensure(module, state, pkgs, conf_file, enablerepo, disablerepo,
|
||||||
rid = my.repos.getRepo(i)
|
rid = my.repos.getRepo(i)
|
||||||
a = rid.repoXML.repoid # nopep8 - https://github.com/ansible/ansible/pull/21475#pullrequestreview-22404868
|
a = rid.repoXML.repoid # nopep8 - https://github.com/ansible/ansible/pull/21475#pullrequestreview-22404868
|
||||||
current_repos = new_repos
|
current_repos = new_repos
|
||||||
except yum.Errors.YumBaseError:
|
except yum.Errors.YumBaseError as e:
|
||||||
e = get_exception()
|
module.fail_json(msg="Error setting/accessing repos: %s" % to_native(e))
|
||||||
module.fail_json(msg="Error setting/accessing repos: %s" % (e))
|
except yum.Errors.YumBaseError as e:
|
||||||
except yum.Errors.YumBaseError:
|
module.fail_json(msg="Error accessing repos: %s" % to_native(e))
|
||||||
e = get_exception()
|
|
||||||
module.fail_json(msg="Error accessing repos: %s" % e)
|
|
||||||
if state in ['installed', 'present']:
|
if state in ['installed', 'present']:
|
||||||
if disable_gpg_check:
|
if disable_gpg_check:
|
||||||
yum_basecmd.append('--nogpgcheck')
|
yum_basecmd.append('--nogpgcheck')
|
||||||
|
|
Loading…
Reference in a new issue