Allow whitelisted buildrequires with xmd.mbs.disttag_marking set to influnece the disttag

This commit is contained in:
mprahl
2019-04-03 19:31:47 -04:00
parent e2b2da7708
commit 9512a49631
9 changed files with 120 additions and 30 deletions

View File

@@ -541,7 +541,14 @@ class Config(object):
'desc': 'The Greenwave decision context that whose messages should '
'be handled by MBS. By default, MBS handles Greenwave '
'messages for OSCI.',
}
},
'allowed_disttag_marking_module_names': {
'type': list,
'default': [],
'desc': ('List of modules that are allowed to influence the RPM disttag when '
'buildrequired. These modules can set xmd.mbs.disttag_marking to do so. MBS '
'will use this list order to determine which modules take precedence.')
},
}
def __init__(self, conf_section_obj):

View File

@@ -262,13 +262,14 @@ class MMDResolver(object):
:return: Dict with module name as a key and new stream as a value.
"""
overrides = {}
if "mbs" in mmd.get_xmd().keys():
xmd = mmd.get_xmd()
if "mbs" in xmd.keys() and "buildrequires" in xmd["mbs"].keys():
for base_module_name in conf.base_module_names:
if base_module_name not in mmd.get_xmd()["mbs"]["buildrequires"].keys():
if base_module_name not in xmd["mbs"]["buildrequires"].keys():
continue
if "stream" not in mmd.get_xmd()["mbs"]["buildrequires"][base_module_name].keys():
if "stream" not in xmd["mbs"]["buildrequires"][base_module_name].keys():
continue
stream = mmd.get_xmd()["mbs"]["buildrequires"][base_module_name]["stream"]
stream = xmd["mbs"]["buildrequires"][base_module_name]["stream"]
overrides[base_module_name] = stream
return overrides

View File

@@ -240,36 +240,39 @@ def get_rpm_release(module_build):
.format(module_build.id))
buildrequires = None
# Determine which base module is buildrequired and its marking in the disttag
base_module_marking = ''
# Determine which buildrequired module will influence the disttag
br_module_marking = ''
# If the buildrequires are recorded in the xmd then we can try to find the base module that
# is buildrequired
if buildrequires:
# Looping through all the base modules in conf.base_module_names instead of looping through
# all the buildrequires guarantees the order in conf.base_module_names is preserved for
# which base module is used as the marking
for base_module in conf.base_module_names:
bm_in_xmd = buildrequires.get(base_module)
# Looping through all the non-base modules that are allowed to set the disttag_marking
# and the base modules to see what the disttag marking should be. Doing it this way
# preserves the order in the configurations.
for module in conf.allowed_disttag_marking_module_names + conf.base_module_names:
module_in_xmd = buildrequires.get(module)
if not bm_in_xmd:
if not module_in_xmd:
continue
with models.make_session(conf) as session:
base_module_obj = models.ModuleBuild.get_build_from_nsvc(
session, base_module, bm_in_xmd['stream'], bm_in_xmd['version'],
bm_in_xmd['context'])
if not base_module_obj:
module_obj = models.ModuleBuild.get_build_from_nsvc(
session, module, module_in_xmd['stream'], module_in_xmd['version'],
module_in_xmd['context'])
if not module_obj:
continue
# Default to using the base module's stream, but if the base module has
# disttag_marking set in the xmd, use that instead
try:
marking = base_module_obj.mmd().get_xmd()['mbs']['disttag_marking']
marking = module_obj.mmd().get_xmd()['mbs']['disttag_marking']
# We must check for a KeyError because a Variant object doesn't support the `get`
# method
except KeyError:
marking = base_module_obj.stream
base_module_marking = marking + '+'
if module not in conf.base_module_names:
continue
# If we've made it past all the modules in
# conf.allowed_disttag_marking_module_names, and the base module doesn't have
# the disttag_marking set, then default to the stream of the first base module
marking = module_obj.stream
br_module_marking = marking + '+'
break
else:
log.warning('Module build {0} does not buildrequire a base module ({1})'
@@ -280,7 +283,7 @@ def get_rpm_release(module_build):
return '{prefix}{base_module_marking}{index}+{dist_hash}'.format(
prefix=prefix,
base_module_marking=base_module_marking,
base_module_marking=br_module_marking,
index=index,
dist_hash=dist_hash,
)

View File

@@ -299,12 +299,16 @@ def validate_mmd(mmd):
"Custom module repositories aren't allowed. "
"%r bears repository %r" % (modname, mod.get_repository()))
if 'mbs' in mmd.get_xmd():
raise ValidationError('The "mbs" xmd field is reserved for MBS')
name = mmd.get_name()
xmd = mmd.get_xmd()
if 'mbs' in xmd:
allowed_to_mark_disttag = name in conf.allowed_disttag_marking_module_names
if not (xmd['mbs'].keys() == ['disttag_marking'] and allowed_to_mark_disttag):
raise ValidationError('The "mbs" xmd field is reserved for MBS')
if mmd.get_name() in conf.base_module_names:
if name in conf.base_module_names:
raise ValidationError(
'You cannot build a module named "{}" since it is a base module'.format(mmd.get_name()))
'You cannot build a module named "{}" since it is a base module'.format(name))
def merge_included_mmd(mmd, included_mmd):