From c9c1146cc825886463dcf95ef2648858e9ca8bb9 Mon Sep 17 00:00:00 2001 From: Chris Holland <41524756+ChrisAHolland@users.noreply.github.com> Date: Wed, 8 Apr 2020 11:36:28 -0700 Subject: [PATCH] dnf: remove un-needed function (#68482) --- .../68482-remove-function-update-calls.yaml | 2 ++ lib/ansible/modules/packaging/os/dnf.py | 36 ++----------------- 2 files changed, 4 insertions(+), 34 deletions(-) create mode 100644 changelogs/fragments/68482-remove-function-update-calls.yaml diff --git a/changelogs/fragments/68482-remove-function-update-calls.yaml b/changelogs/fragments/68482-remove-function-update-calls.yaml new file mode 100644 index 00000000000..b58a9be71d2 --- /dev/null +++ b/changelogs/fragments/68482-remove-function-update-calls.yaml @@ -0,0 +1,2 @@ +bugfixes: +- dnf - remove custom ``fetch_rpm_from_url`` method in favor of more general ``ansible.module_utils.urls.fetch_file``. diff --git a/lib/ansible/modules/packaging/os/dnf.py b/lib/ansible/modules/packaging/os/dnf.py index b44ce695f93..e955ec4c821 100644 --- a/lib/ansible/modules/packaging/os/dnf.py +++ b/lib/ansible/modules/packaging/os/dnf.py @@ -286,7 +286,6 @@ EXAMPLES = ''' import os import re import sys -import tempfile try: import dnf @@ -300,16 +299,13 @@ except ImportError: HAS_DNF = False from ansible.module_utils._text import to_native, to_text -from ansible.module_utils.urls import fetch_url +from ansible.module_utils.urls import fetch_file from ansible.module_utils.six import PY2, text_type from distutils.version import LooseVersion from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.yumdnf import YumDnf, yumdnf_argument_spec -# 64k. Number of bytes to read at a time when manually downloading pkgs via a url -BUFSIZE = 65536 - class DnfModule(YumDnf): """ @@ -465,34 +461,6 @@ class DnfModule(YumDnf): # print '%s, %s, %s vs %s, %s, %s = %s' % (e1, v1, r1, e2, v2, r2, rc) return rc - def fetch_rpm_from_url(self, spec): - # FIXME: Remove this once this PR is merged: - # https://github.com/ansible/ansible/pull/19172 - - # download package so that we can query it - package_name, dummy = os.path.splitext(str(spec.rsplit('/', 1)[1])) - package_file = tempfile.NamedTemporaryFile(dir=self.module.tmpdir, prefix=package_name, suffix='.rpm', delete=False) - self.module.add_cleanup_file(package_file.name) - try: - rsp, info = fetch_url(self.module, spec) - if not rsp: - self.module.fail_json( - msg="Failure downloading %s, %s" % (spec, info['msg']), - results=[], - ) - data = rsp.read(BUFSIZE) - while data: - package_file.write(data) - data = rsp.read(BUFSIZE) - package_file.close() - except Exception as e: - self.module.fail_json( - msg="Failure downloading %s, %s" % (spec, to_native(e)), - results=[], - ) - - return package_file.name - def _ensure_dnf(self): if not HAS_DNF: if PY2: @@ -792,7 +760,7 @@ class DnfModule(YumDnf): for name in self.names: if '://' in name: - name = self.fetch_rpm_from_url(name) + name = fetch_file(self.module, name) filenames.append(name) elif name.endswith(".rpm"): filenames.append(name)