Skip to content

Commit 761e93f

Browse files
committed
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)
1 parent b6e409e commit 761e93f

File tree

1 file changed

+14
-8
lines changed
  • repos/system_upgrade/common/libraries

1 file changed

+14
-8
lines changed

repos/system_upgrade/common/libraries/module.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,20 @@ def _create_or_get_dnf_base(base=None):
2323
# have repositories only for the exact system version (including the minor number). In a case when
2424
# /etc/yum/vars/releasever is present, read its contents so that we can access repositores on such systems.
2525
conf = dnf.conf.Conf()
26-
pkg_manager = 'yum' if get_source_major_version() == '7' else 'dnf'
27-
releasever_path = '/etc/{0}/vars/releasever'.format(pkg_manager)
28-
if os.path.exists(releasever_path):
29-
with open(releasever_path) as releasever_file:
30-
releasever = releasever_file.read().strip()
31-
conf.substitutions['releasever'] = releasever
32-
else:
33-
conf.substitutions['releasever'] = get_source_major_version()
26+
27+
# preload releasever from what we know, this will be our fallback
28+
conf.substitutions['releasever'] = get_source_major_version()
29+
30+
# dnf on EL7 doesn't load vars from /etc/yum, so we need to help it a bit
31+
if get_source_major_version() == '7':
32+
try:
33+
with open('/etc/yum/vars/releasever') as releasever_file:
34+
conf.substitutions['releasever'] = releasever_file.read().strip()
35+
except:
36+
pass
37+
38+
# load all substitutions from etc
39+
conf.substitutions.update_from_etc('/')
3440

3541
base = dnf.Base(conf=conf)
3642
base.init_plugins()

0 commit comments

Comments
 (0)