Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove un-needed function #68482

Merged
merged 14 commits into from Apr 8, 2020
2 changes: 2 additions & 0 deletions 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``.
36 changes: 2 additions & 34 deletions lib/ansible/modules/packaging/os/dnf.py
Expand Up @@ -286,7 +286,6 @@
import os
import re
import sys
import tempfile

try:
import dnf
Expand All @@ -300,16 +299,13 @@
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):
"""
Expand Down Expand Up @@ -465,34 +461,6 @@ def _compare_evr(self, e1, v1, r1, e2, v2, r2):
# 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:
Expand Down Expand Up @@ -792,7 +760,7 @@ def _parse_spec_group_file(self):

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)
Expand Down