lorax: Update how the release package is chosen

Previously the release package was chosen by picking the first package
that provides 'system-release' that isn't named generic. This can cause
branding issues with repos containing multiple system-release packages.

This patch changes _install_branding so that it will give preference to
a system-release package that ends with lowercase --variant name. If
there isn't one it will fall back to the previous behavior.

Resolves: rhbz#1472622
This commit is contained in:
Brian C. Lane 2020-03-03 17:10:31 -08:00
parent 970a39f296
commit bebec0cf58

View File

@ -86,18 +86,28 @@ class RuntimeBuilder(object):
self._runner.defaults = self.vars
def _install_branding(self):
"""Select the branding from the available 'system-release' packages
The *best* way to control this is to have a single package in the repo provide 'system-release'
When there are more than 1 package it will:
- Make a list of the available packages
- If variant is set look for a package ending with lower(variant) and use that
- If there are one or more non-generic packages, use the first one after sorting
"""
release = None
for pkg in self.yum.whatProvides('/etc/system-release', None, None):
if pkg.name.startswith('generic'):
continue
else:
release = pkg.name
break
if not release:
logger.error('could not get the release')
pkgs = sorted([p.name for p in self.yum.whatProvides('/etc/system-release', None, None)
if not p.name.startswith("generic")])
if not pkgs:
logger.error("No system-release packages found, could not get the release")
return
logger.debug("system-release packages: %s", pkgs)
if self.vars.product.variant:
variant = [p for p in pkgs if p.endswith("-"+self.vars.product.variant.lower())]
if variant:
release = variant[0]
if not release:
release = pkgs[0]
# release
logger.info('got release: %s', release)
self._runner.installpkg(release)