Bug 2026849

Summary: python3-dnf does not respect cacheonly
Product: Red Hat Enterprise Linux 9 Reporter: Tomáš Bajer <tbajer>
Component: dnfAssignee: Jaroslav Rohel <jrohel>
Status: CLOSED ERRATA QA Contact: Eva Mrakova <emrakova>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 9.0CC: james.antill, mbanas, pkratoch
Target Milestone: rcKeywords: AutoVerified, Triaged
Target Release: ---Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: dnf-4.10.0-2.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 1862970 Environment:
Last Closed: 2022-05-17 15:55:05 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 Tomáš Bajer 2021-11-26 08:33:17 UTC
This bug was initially created as a copy of Bug #1862970

I am copying this bug because: it behaves incorrectly in RHEL9 as well

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 9 errata-xmlrpc 2022-05-17 15:55:05 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 (new packages: dnf), 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:3957