From 3cfefd7e0b282806d6b3f21116d62b31856ad280 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Thu, 11 Apr 2019 06:45:53 +0200 Subject: [PATCH] Allow importing MMD without xmd["buildrequires"]. When importing modules for offline local builds from local repositories, the XMD section does not have to be set at all - it gets removed during the compose and is also MBS specific. We need to be able to import such MMDs using the `import_mmd` method in order to make --offline local builds working. This commit adds new `check_buildrequires` bool kwarg in `import_mmd` method to disable `xmd["buildrequires"]` checks to fix this. --- module_build_service/utils/general.py | 18 ++++++++++++------ tests/test_utils/test_utils.py | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/module_build_service/utils/general.py b/module_build_service/utils/general.py index ef01fc98..72f7b05a 100644 --- a/module_build_service/utils/general.py +++ b/module_build_service/utils/general.py @@ -318,7 +318,7 @@ def create_dogpile_key_generator_func(skip_first_n_args=0): return key_generator -def import_mmd(session, mmd): +def import_mmd(session, mmd, check_buildrequires=True): """ Imports new module build defined by `mmd` to MBS database using `session`. If it already exists, it is updated. @@ -328,6 +328,9 @@ def import_mmd(session, mmd): The ModuleBuild.rebuild_strategy is set to "all". The ModuleBuild.owner is set to "mbs_import". + :param bool check_buildrequires: When True, checks that the buildrequires defined in the MMD + have matching records in the `mmd["xmd"]["mbs"]["buildrequires"]` and also fills in + the `ModuleBuild.buildrequires` according to this data. :return: module build (ModuleBuild), log messages collected during import (list) :rtype: tuple @@ -376,7 +379,7 @@ def import_mmd(session, mmd): if "mbs" not in xmd: xmd["mbs"] = {"mse": True} - if mmd.get_dependencies(): + if check_buildrequires and mmd.get_dependencies(): brs = set(mmd.get_dependencies()[0].get_buildrequires().keys()) xmd_brs = set(xmd["mbs"].get("buildrequires", {}).keys()) if brs - xmd_brs: @@ -417,8 +420,9 @@ def import_mmd(session, mmd): build.stream_version = models.ModuleBuild.get_stream_version(stream) # Record the base modules this module buildrequires - for base_module in build.get_buildrequired_base_modules(): - build.buildrequires.append(base_module) + if check_buildrequires: + for base_module in build.get_buildrequired_base_modules(): + build.buildrequires.append(base_module) session.add(build) session.commit() @@ -472,7 +476,7 @@ def import_fake_base_module(nsvc): mmd.set_xmd(glib.dict_values(xmd)) with models.make_session(conf) as session: - import_mmd(session, mmd) + import_mmd(session, mmd, False) def get_local_releasever(): @@ -511,11 +515,13 @@ def import_builds_from_local_dnf_repos(): mmds = Modulemd.Module.new_all_from_string(mmd_data) for mmd in mmds: xmd = glib.from_variant_dict(mmd.get_xmd()) + xmd["mbs"] = {} xmd["mbs"]["koji_tag"] = "repofile://" + repo.repofile xmd["mbs"]["mse"] = True + xmd["mbs"]["commit"] = "unknown" mmd.set_xmd(glib.dict_values(xmd)) - import_mmd(session, mmd) + import_mmd(session, mmd, False) # Parse the /etc/os-release to find out the local platform:stream. platform_id = None diff --git a/tests/test_utils/test_utils.py b/tests/test_utils/test_utils.py index 620d7dea..b6a3c1e5 100644 --- a/tests/test_utils/test_utils.py +++ b/tests/test_utils/test_utils.py @@ -347,6 +347,20 @@ class TestUtils: module_build_service.utils.import_mmd(db.session, mmd) assert str(e.value) == expected_error + def test_import_mmd_minimal_xmd_from_local_repository(self): + mmd = Modulemd.Module().new_from_file( + path.join(BASE_DIR, '..', 'staged_data', 'formatted_testmodule.yaml')) + mmd.upgrade() + xmd = glib.from_variant_dict(mmd.get_xmd()) + xmd["mbs"] = {} + xmd["mbs"]["koji_tag"] = "repofile:///etc/yum.repos.d/fedora-modular.repo" + xmd["mbs"]["mse"] = True + xmd["mbs"]["commit"] = "unknown" + mmd.set_xmd(glib.dict_values(xmd)) + + build, msgs = module_build_service.utils.import_mmd(db.session, mmd, False) + assert build.name == mmd.get_name() + @pytest.mark.parametrize('stream, disttag_marking, error_msg', ( ('f28', None, None), ('f28', 'fedora28', None),