summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Holland <41524756+ChrisAHolland@users.noreply.github.com>2020-04-08 11:36:28 -0700
committerGitHub <noreply@github.com>2020-04-08 20:36:28 +0200
commitc9c1146cc825886463dcf95ef2648858e9ca8bb9 (patch)
tree6cd33dcf6107ca1e8b90b1a61a19dc8092086a30
parentba87c225cd13343c35075fe7fc15b4cf1343fed6 (diff)
downloadansible-c9c1146cc825886463dcf95ef2648858e9ca8bb9.tar.gz
dnf: remove un-needed function (#68482)
-rw-r--r--changelogs/fragments/68482-remove-function-update-calls.yaml2
-rw-r--r--lib/ansible/modules/packaging/os/dnf.py36
2 files changed, 4 insertions, 34 deletions
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 0000000000..b58a9be71d
--- /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 b44ce695f9..e955ec4c82 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)