From 5b0c1d9d6bc96e9718949a03dd717bb4cbc04c10 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Sat, 21 Oct 2023 19:36:19 +0200 Subject: [PATCH 23/38] load all substitutions from etc On some distributions (like CentOS Stream and Oracle Linux), we need more substitutions to be able to load repositories properly. DNF has a helper for that: conf.substitutions.update_from_etc. On pure DNF distributions, calling this should be sufficient. On EL7, where the primary tool is YUM, DNF does not load vars from /etc/yum, only from /etc/dnf, so we have to help it a bit and explicitly try to load releasever from /etc/yum. (DNF since 4.2.15 *does* also load substitutions from /etc/yum, but EL7 ships with 4.0.x) --- .../system_upgrade/common/libraries/module.py | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/repos/system_upgrade/common/libraries/module.py b/repos/system_upgrade/common/libraries/module.py index abde69e7..7d4e8aa4 100644 --- a/repos/system_upgrade/common/libraries/module.py +++ b/repos/system_upgrade/common/libraries/module.py @@ -1,4 +1,3 @@ -import os import warnings from leapp.libraries.common.config.version import get_source_major_version @@ -23,14 +22,20 @@ def _create_or_get_dnf_base(base=None): # have repositories only for the exact system version (including the minor number). In a case when # /etc/yum/vars/releasever is present, read its contents so that we can access repositores on such systems. conf = dnf.conf.Conf() - pkg_manager = 'yum' if get_source_major_version() == '7' else 'dnf' - releasever_path = '/etc/{0}/vars/releasever'.format(pkg_manager) - if os.path.exists(releasever_path): - with open(releasever_path) as releasever_file: - releasever = releasever_file.read().strip() - conf.substitutions['releasever'] = releasever - else: - conf.substitutions['releasever'] = get_source_major_version() + + # preload releasever from what we know, this will be our fallback + conf.substitutions['releasever'] = get_source_major_version() + + # dnf on EL7 doesn't load vars from /etc/yum, so we need to help it a bit + if get_source_major_version() == '7': + try: + with open('/etc/yum/vars/releasever') as releasever_file: + conf.substitutions['releasever'] = releasever_file.read().strip() + except IOError: + pass + + # load all substitutions from etc + conf.substitutions.update_from_etc('/') base = dnf.Base(conf=conf) base.init_plugins() -- 2.41.0