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.
This commit is contained in:
mprahl
2019-03-15 13:00:12 -04:00
parent 6bb41e786c
commit 40e534ff9d
2 changed files with 43 additions and 0 deletions

View File

@@ -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 = []

View File

@@ -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)