From 642c8406ca0a8219b997d8731db1389da9d5aeba Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Mon, 28 Jan 2019 12:16:07 +0100 Subject: [PATCH] Allow setting context in the imported MMD file. We always set the "context" to DEFAULT_MODULE_CONTEXT from the historical reasons - the context was not stored in the database before and we stored just the build_context/runtime_context. But this is no longer true for some time. In this commit, the context is respected and stored in the database when importing module using the `import_mmd` method. If the context is not set in the imported MMD, the DEFAULT_MODULE_CONTEXT is used. --- module_build_service/utils/general.py | 9 ++------- tests/test_utils/test_utils.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/module_build_service/utils/general.py b/module_build_service/utils/general.py index 19860cca..1555697a 100644 --- a/module_build_service/utils/general.py +++ b/module_build_service/utils/general.py @@ -277,17 +277,12 @@ def import_mmd(session, mmd): The ModuleBuild.rebuild_strategy is set to "all". The ModuleBuild.owner is set to "mbs_import". - TODO: The "context" is not stored directly in database. We only store - build_context and runtime_context and compute context, but when importing - the module, we have no idea what build_context or runtime_context is - we only - know the resulting "context", but there is no way to store it into do DB. - By now, we just ignore mmd.get_context() and use default 00000000 context instead. - :return: module build (ModuleBuild), log messages collected during import (list) :rtype: tuple """ - mmd.set_context(models.DEFAULT_MODULE_CONTEXT) + if not mmd.get_context(): + mmd.set_context(models.DEFAULT_MODULE_CONTEXT) name = mmd.get_name() stream = mmd.get_stream() version = str(mmd.get_version()) diff --git a/tests/test_utils/test_utils.py b/tests/test_utils/test_utils.py index f4cf34b8..dc034a54 100644 --- a/tests/test_utils/test_utils.py +++ b/tests/test_utils/test_utils.py @@ -298,6 +298,27 @@ class TestUtils: def teardown_method(self, test_method): clean_database() + @pytest.mark.parametrize('context', ["c1", None]) + def test_import_mmd_contexts(self, context): + mmd = Modulemd.Module().new_from_file( + path.join(BASE_DIR, '..', 'staged_data', 'formatted_testmodule.yaml')) + mmd.upgrade() + mmd.set_context(context) + + xmd = glib.from_variant_dict(mmd.get_xmd()) + xmd['mbs']['koji_tag'] = 'foo' + mmd.set_xmd(glib.dict_values(xmd)) + + build, msgs = module_build_service.utils.import_mmd(db.session, mmd) + + mmd_context = build.mmd().get_context() + if context: + assert mmd_context == context + assert build.context == context + else: + assert mmd_context == models.DEFAULT_MODULE_CONTEXT + assert build.context == models.DEFAULT_MODULE_CONTEXT + def test_get_rpm_release_mse(self): init_data(contexts=True) build_one = models.ModuleBuild.query.get(2)