Add the ability to override the base module marking used in the RPM disttags

MBS uses the base module's stream that was buildrequired by the module
in the RPM disttags for that module build. The stream name may not be
ideal for all situations, so now this is customizable by setting the
xmd['mbs']['disttag_marking'] in the base module's modulemd.
This commit is contained in:
mprahl
2019-03-15 12:10:41 -04:00
parent 63c7a35e4b
commit 6bb41e786c
2 changed files with 47 additions and 7 deletions

View File

@@ -240,13 +240,36 @@ def get_rpm_release(module_build):
.format(module_build.id))
buildrequires = None
base_module_stream = ''
# Determine which base module is buildrequired and its marking in the disttag
base_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:
base_module_stream = buildrequires.get(base_module, {}).get('stream', '')
if base_module_stream:
base_module_stream += '+'
break
bm_in_xmd = buildrequires.get(base_module)
if not bm_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:
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']
# 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 + '+'
break
else:
log.warning('Module build {0} does not buildrequire a base module ({1})'
.format(module_build.id, ' or '.join(conf.base_module_names)))
@@ -254,9 +277,9 @@ def get_rpm_release(module_build):
# use alternate prefix for scratch module build components so they can be identified
prefix = ('scrmod+' if module_build.scratch else conf.default_dist_tag_prefix)
return '{prefix}{base_module_stream}{index}+{dist_hash}'.format(
return '{prefix}{base_module_marking}{index}+{dist_hash}'.format(
prefix=prefix,
base_module_stream=base_module_stream,
base_module_marking=base_module_marking,
index=index,
dist_hash=dist_hash,
)

View File

@@ -336,6 +336,23 @@ class TestUtils:
release = module_build_service.utils.get_rpm_release(build_one)
assert release == 'module+f28+2+814cfa39'
def test_get_rpm_release_platform_stream_override(self):
scheduler_init_data(1)
# Set the disttag_marking override on the platform
platform = models.ModuleBuild.query.filter_by(name='platform', stream='f28').first()
platform_mmd = platform.mmd()
platform_xmd = glib.from_variant_dict(platform_mmd.get_xmd())
platform_xmd['mbs']['disttag_marking'] = 'fedora28'
platform_mmd.set_xmd(glib.dict_values(platform_xmd))
platform.modulemd = to_text_type(platform_mmd.dumps())
db.session.add(platform)
db.session.commit()
build_one = models.ModuleBuild.query.get(2)
release = module_build_service.utils.get_rpm_release(build_one)
assert release == 'module+fedora28+2+814cfa39'
def test_get_rpm_release_mse_scratch(self):
init_data(contexts=True, scratch=True)
build_one = models.ModuleBuild.query.get(2)