Skip to content

Commit

Permalink
fix(yum_updates): releasever and basearch (#3835)
Browse files Browse the repository at this point in the history
Take releasever and basearch from dnf config substitutions after loading
them from variables.  It utilizes dnf.cli to load vars correctly.

RHINENG-985

Signed-off-by: Viliam Krizan <[email protected]>
(cherry picked from commit fc90752)
  • Loading branch information
vkrizan authored and xiangce committed Jul 5, 2023
1 parent 4b96f7e commit 3bc33d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 10 additions & 1 deletion insights/specs/datasources/yum_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class DnfManager:
""" Performs package resolution on dnf based systems """
def __init__(self):
self.base = dnf.base.Base()
# releasever and basearchs are correctly set after calling load()
self.releasever = dnf.rpm.detect_releasever("/")
self.basearch = dnf.rpm.basearch(hawkey.detect_arch())
self.packages = []
Expand Down Expand Up @@ -51,7 +52,14 @@ def sorted_pkgs(self, pkgs):
return sorted_cmp([pkg for pkg in pkgs if pkg.reponame != "@System"], self.pkg_cmp)

def load(self):
self.base.conf.read()
cli = dnf.cli.Cli(self.base)
cli._read_conf_file()
subst = self.base.conf.substitutions
if subst.get("releasever"):
self.releasever = subst["releasever"]
if subst.get("basearch"):
self.basearch = subst["basearch"]

self.base.conf.cacheonly = True
self.base.read_all_repos()
self.packages = hawkey.Query(hawkey.Sack())
Expand Down Expand Up @@ -168,6 +176,7 @@ def last_update():
# Select which manager to use based on the available system libraries.
try:
import dnf
import dnf.cli
import hawkey
import rpm
UpdatesManager = DnfManager
Expand Down
2 changes: 2 additions & 0 deletions insights/tests/datasources/test_yum_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ def test_yum_updates_runs_correctly():
# setup dnf mock
with patch("insights.specs.datasources.yum_updates.UpdatesManager", yum_updates.DnfManager):
yum_updates.dnf = MagicMock()
yum_updates.dnf.cli = MagicMock()
yum_updates.hawkey = MagicMock()
yum_updates.dnf.VERSION = "4.7.0"
yum_updates.dnf.rpm.detect_releasever.return_value = "8"
yum_updates.dnf.rpm.basearch.return_value = "x86_64"
yum_updates.dnf.base.Base().conf.substitutions = {"releasever": "8"}
repo = MagicMock()
repo._repo.getTimestamp.return_value = 1609493985
yum_updates.dnf.base.Base().repos.iter_enabled.return_value = [repo]
Expand Down

0 comments on commit 3bc33d2

Please sign in to comment.