From 40e534ff9d7c4290b1e7319f3ddd1b8083026146 Mon Sep 17 00:00:00 2001 From: mprahl Date: Fri, 15 Mar 2019 13:00:12 -0400 Subject: [PATCH] Don't allow a dash in the value that will be used for an RPM disttag When importing a base module, we must ensure the value that will be used in the RPM disttags doesn't contain a dash since a dash isn't allowed in the release field of the NVR. --- module_build_service/utils/general.py | 17 +++++++++++++++++ tests/test_utils/test_utils.py | 26 ++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/module_build_service/utils/general.py b/module_build_service/utils/general.py index 72c4dca7..b542e18e 100644 --- a/module_build_service/utils/general.py +++ b/module_build_service/utils/general.py @@ -335,6 +335,23 @@ def import_mmd(session, mmd): version = str(mmd.get_version()) context = mmd.get_context() + try: + disttag_marking = mmd.get_xmd()["mbs"]["disttag_marking"] + except (ValueError, KeyError): + disttag_marking = None + + # If it is a base module, then make sure the value that will be used in the RPM disttags + # doesn't contain a dash since a dash isn't allowed in the release field of the NVR + if name in conf.base_module_names: + if disttag_marking and "-" in disttag_marking: + msg = "The disttag_marking cannot contain a dash" + log.error(msg) + raise UnprocessableEntity(msg) + elif not disttag_marking and "-" in stream: + msg = "The stream cannot contain a dash unless disttag_marking is set" + log.error(msg) + raise UnprocessableEntity(msg) + # Log messages collected during import msgs = [] diff --git a/tests/test_utils/test_utils.py b/tests/test_utils/test_utils.py index ab9ad22f..0ecbcac2 100644 --- a/tests/test_utils/test_utils.py +++ b/tests/test_utils/test_utils.py @@ -321,6 +321,32 @@ class TestUtils: assert mmd_context == models.DEFAULT_MODULE_CONTEXT assert build.context == models.DEFAULT_MODULE_CONTEXT + @pytest.mark.parametrize('stream, disttag_marking, error_msg', ( + ('f28', None, None), + ('f28', 'fedora28', None), + ('f-28', 'f28', None), + ('f-28', None, 'The stream cannot contain a dash unless disttag_marking is set'), + ('f28', 'f-28', 'The disttag_marking cannot contain a dash'), + ('f-28', 'fedora-28', 'The disttag_marking cannot contain a dash') + )) + def test_import_mmd_base_module(self, stream, disttag_marking, error_msg): + clean_database(add_platform_module=False) + mmd = Modulemd.Module().new_from_file( + path.join(BASE_DIR, '..', 'staged_data', 'platform.yaml')) + mmd.upgrade() + mmd.set_stream(stream) + + if disttag_marking: + xmd = glib.from_variant_dict(mmd.get_xmd()) + xmd['mbs']['disttag_marking'] = disttag_marking + mmd.set_xmd(glib.dict_values(xmd)) + + if error_msg: + with pytest.raises(UnprocessableEntity, match=error_msg): + module_build_service.utils.import_mmd(db.session, mmd) + else: + module_build_service.utils.import_mmd(db.session, mmd) + def test_get_rpm_release_mse(self): init_data(contexts=True) build_one = models.ModuleBuild.query.get(2)