Bug 1862970

Summary: python3-dnf does not respect cacheonly
Product: Red Hat Enterprise Linux 8 Reporter: Michael Mráka <mmraka>
Component: dnfAssignee: Jaroslav Rohel <jrohel>
Status: CLOSED ERRATA QA Contact: Tomáš Bajer <tbajer>
Severity: unspecified Docs Contact:
Priority: high    
Version: 8.2CC: james.antill, jdostal, jrohel, lmiksik, pkratoch, smcdowel, tbajer, tlestach
Target Milestone: rcKeywords: Triaged
Target Release: 8.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: dnf-4.7.0-5.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 2026849 (view as bug list) Environment:
Last Closed: 2022-05-10 15:23:43 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 Michael Mráka 2020-08-03 11:02:42 UTC
Description of problem:
python3-dnf downloads metadata even if cacheonly is set.

Version-Release number of selected component (if applicable):
dnf-4.2.17-7.el8_2.noarch
(and dnf-4.2.23-1.git.9175.126d861.el8.noarch)

How reproducible:
always

Steps to Reproduce:
1. cat >cacheonly.py <<EOF
import dnf
import os
import sys

cacheonly = True if len(sys.argv) > 1 else False
CENTOS='http://mirror.centos.org/centos-8/8/BaseOS/x86_64/os/'

with dnf.base.Base() as base:
    base.conf.module_platform_id = 'platform:el8'
    base.conf.installroot = os.path.abspath('./instalroot')
    base.conf.cachedir = os.path.abspath('./instalroot/var/cache/dnf')
    base.conf.cacheonly = cacheonly
    repo = base.repos.add_new_repo('baseos', base.conf, baseurl=[CENTOS], skip_if_unavailable=True)
    base.fill_sack(load_system_repo=False)
    print("Cacheonly:", base.conf.cacheonly)
    print("Loaded repos:", len(base.repos))
    print("Loaded packages:", len(base.sack.query()))
EOF
2. python3 ./cacheonly.py
3. ls -l instalroot/var/cache/dnf/
4. rm -rf instalroot/var/cache/dnf/*
4. python3 ./cacheonly.py cacheonly
5. ls -ll instalroot/var/cache/dnf/

Actual results:

Cacheonly: False
Loaded repos: 1
Loaded packages: 1675
drwxr-xr-x. 3 michael michael      22 Aug  3 12:56 baseos-7ce9369cf52b8f9b
-rw-rw-r--. 1 michael michael 1299280 Aug  3 12:56 baseos-filenames.solvx
-rw-rw-r--. 1 michael michael 1372757 Aug  3 12:56 baseos.solv

Cacheonly: True
Loaded repos: 1
Loaded packages: 1675
drwxr-xr-x. 3 michael michael      22 Aug  3 12:59 baseos-7ce9369cf52b8f9b
-rw-rw-r--. 1 michael michael 1299280 Aug  3 12:59 baseos-filenames.solvx
-rw-rw-r--. 1 michael michael 1372757 Aug  3 12:59 baseos.solv


Expected results:
Dnf doesn't download metadata in the second case and thus fails to load it.

Additional info:

Comment 7 Jaroslav Rohel 2021-11-05 09:39:54 UTC
PR https://github.com/rpm-software-management/dnf/pull/1792

Comment 16 errata-xmlrpc 2022-05-10 15:23:43 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (dnf bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2022:2051