Bug 1457507

Summary: [api] Explicitly set metalink is not substituted
Product: [Fedora] Fedora Reporter: Miro Hrončok <mhroncok>
Component: dnfAssignee: Jaroslav Mracek <jmracek>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 26CC: dmach, jmracek, packaging-team-maint, rpm-software-management, vmukhame
Target Milestone: ---Keywords: Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: dnf-2.6.3-1.fc26 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-08-09 16:00:19 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Miro Hrončok 2017-05-31 20:18:52 UTC
Given the following code:

    >>> import dnf
    >>> base = dnf.Base()
    >>> base.conf.substitutions['releasever'] = '26'
    >>> repo = dnf.repo.Repo('fedora', parent_conf=base.conf)
    >>> repo.metalink = 'https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=$basearch'
    >>> base.repos.add(repo)
    >>> repo.skip_if_unavailable = False
    >>> repo.enable()
    >>> repo.load()

It fails with:

    Traceback (most recent call last):
      File "/usr/lib/python3.6/site-packages/dnf/repo.py", line 229, in _perform
        return super(_Handle, self).perform(result)
      File "/usr/lib64/python3.6/site-packages/librepo/__init__.py", line 1517, in perform
        _librepo.Handle.perform(self, result)
    librepo.LibrepoException: (15, 'Cannot prepare internal mirrorlist: file "repomd.xml" was not found in metalink', 'Bad mirrorlist or metalink file')
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/usr/lib/python3.6/site-packages/dnf/repo.py", line 910, in load
        self._handle_load(handle)
      File "/usr/lib/python3.6/site-packages/dnf/repo.py", line 657, in _handle_load
        return self._handle_load_core(handle)
      File "/usr/lib/python3.6/site-packages/dnf/repo.py", line 670, in _handle_load_core
        result = handle._perform()
      File "/usr/lib/python3.6/site-packages/dnf/repo.py", line 233, in _perform
        raise _DetailedLibrepoError(exc, source)
    dnf.repo._DetailedLibrepoError
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python3.6/site-packages/dnf/repo.py", line 922, in load
        raise dnf.exceptions.RepoError(msg)
    dnf.exceptions.RepoError: Failed to synchronize cache for repo 'fedora'


I've realized the problem is in the matalink that is not substituted:

    >>> repo.metalink
    'https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=$basearch'

    >>> repo.metalink = dnf.conf.parser.substitute(repo.metalink, base.conf.substitutions)
    >>> repo.metalink
    'https://mirrors.fedoraproject.org/metalink?repo=fedora-26&arch=x86_64'

Reading the documentation didn't give me any idea I have to do this manually.

I believe this might be fixed with one of the following:

  1) Make metalink (and possibly baseurl as well) a property and do the substitution on setting it.

  2) Make .load() do the substitution.

  3) Document the current behavior in [1] - say "When setting the matalink, no substitution will happen, you need to manually call dnf.conf.parser.substitute() if you want the substitution of variables like $releasever to happen."

[1] http://dnf.readthedocs.io/en/latest/api_repos.html#dnf.repo.Repo.metalink

Version-Release number of selected component (if applicable):
dnf-2.5.0-2.fc26.noarch

Comment 1 Igor Gnatenko 2017-06-07 09:41:00 UTC
IMO completely valid request.

Comment 2 Jaroslav Mracek 2017-06-14 17:32:07 UTC
I created a patch (https://github.com/rpm-software-management/dnf/pull/842) that provide requested functionality. Please if you will provide a feedback it will be nice.

Comment 3 Fedora Update System 2017-08-07 12:51:26 UTC
dnf-2.6.3-1.fc26 dnf-plugins-extras-2.0.2-1.fc26 has been submitted as an update to Fedora 26. https://bodhi.fedoraproject.org/updates/FEDORA-2017-4813633f96

Comment 4 Fedora Update System 2017-08-08 01:24:52 UTC
dnf-2.6.3-1.fc26, dnf-plugins-extras-2.0.2-1.fc26 has been pushed to the Fedora 26 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-4813633f96

Comment 5 Fedora Update System 2017-08-09 16:00:19 UTC
dnf-2.6.3-1.fc26, dnf-plugins-extras-2.0.2-1.fc26 has been pushed to the Fedora 26 stable repository. If problems still persist, please make note of it in this bug report.