From 6bb41e786cb3487e3c0064d5952c1a34584c9e14 Mon Sep 17 00:00:00 2001 From: mprahl Date: Fri, 15 Mar 2019 12:10:41 -0400 Subject: [PATCH] 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. --- module_build_service/utils/general.py | 37 ++++++++++++++++++++++----- tests/test_utils/test_utils.py | 17 ++++++++++++ 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/module_build_service/utils/general.py b/module_build_service/utils/general.py index a048272e..72c4dca7 100644 --- a/module_build_service/utils/general.py +++ b/module_build_service/utils/general.py @@ -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, ) diff --git a/tests/test_utils/test_utils.py b/tests/test_utils/test_utils.py index e428020d..ab9ad22f 100644 --- a/tests/test_utils/test_utils.py +++ b/tests/test_utils/test_utils.py @@ -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)