mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-02-03 05:03:43 +08:00
Merge #1682 support side tags in mbs
This commit is contained in:
@@ -134,6 +134,10 @@ Options:
|
||||
not set, MBS will try to find a compatible module build to reuse components from.
|
||||
- ``scratch`` - a boolean indicating if a scratch module build should be performed.
|
||||
Only allowed to be ``True`` if the MBS setting ``MODULES_ALLOW_SCRATCH`` is ``True``.
|
||||
- ``side_tag`` - this string value instructs mbs to use a side tag for any required base modules.
|
||||
If a base module has ``koji_side_tag_format`` defined, then that format is evaluated with the
|
||||
value given here to determine the tag to use for that base module.
|
||||
If ``koji_side_tag_format`` is not defined for a base module, then this option has no effect.
|
||||
- ``srpms`` - an optional list of Koji upload URLs of SRPMs to include in a module scratch build.
|
||||
Only allowed if ``scratch`` is ``True``.
|
||||
- ``yaml`` - a string of the input file when submitting a YAML modulemd file directly in a
|
||||
|
||||
@@ -66,6 +66,9 @@ Custom fields in xmd:
|
||||
- ``koji_tag`` - this defines the Koji tag with the RPMs that are part of this module. For base
|
||||
modules this will likely be a tag representing a buildroot. If this is a metadata-only module,
|
||||
then this can be left unset.
|
||||
- ``koji_side_tag_format`` - this field is used instead of ``koji_tag`` when the ``side_tag``
|
||||
option is given for a build. In such a case, this field is treated as a python format string
|
||||
and expanded with given value for ``side_tag``.
|
||||
- ``koji_tag_with_modules`` - this defines the Koji tag with the module builds. These modules are
|
||||
later used to fulfill the build requirements of modules built on against this module. This
|
||||
option is used only when ``KojiResolver`` is enabled on the MBS server.
|
||||
|
||||
@@ -308,6 +308,7 @@ class DBResolver(GenericResolver):
|
||||
)
|
||||
|
||||
buildrequires = xmd_mbs["buildrequires"]
|
||||
side_tag = xmd_mbs.get("side_tag")
|
||||
for br_name, details in buildrequires.items():
|
||||
build = models.ModuleBuild.get_build_from_nsvc(
|
||||
self.db_session,
|
||||
@@ -321,12 +322,23 @@ class DBResolver(GenericResolver):
|
||||
raise RuntimeError(
|
||||
"Buildrequired module %s %r does not exist in MBS db" % (br_name, details))
|
||||
|
||||
koji_tag = build.koji_tag
|
||||
if side_tag and br_name in self.config.base_module_names:
|
||||
# see if base module has a side tag configuration
|
||||
side_tag_format = build.mmd().get_xmd().get("mbs", {}).get("koji_side_tag_format")
|
||||
if side_tag_format:
|
||||
koji_tag = side_tag_format.format(side_tag=side_tag)
|
||||
log.info("Using side tag for base module %s: %s", br_name, koji_tag)
|
||||
else:
|
||||
log.warning("Side tag requested, but base module %s lacks koji_side_tag_format"
|
||||
" value", br_name)
|
||||
|
||||
# If the buildrequire is a meta-data only module with no Koji tag set, then just
|
||||
# skip it
|
||||
if build.koji_tag is None:
|
||||
if koji_tag is None:
|
||||
continue
|
||||
module_tags.setdefault(build.koji_tag, [])
|
||||
module_tags[build.koji_tag].append(build.mmd())
|
||||
module_tags.setdefault(koji_tag, [])
|
||||
module_tags[koji_tag].append(build.mmd())
|
||||
|
||||
return module_tags
|
||||
|
||||
|
||||
@@ -257,6 +257,23 @@ def _apply_dep_overrides(mmd, params):
|
||||
)
|
||||
|
||||
|
||||
def _apply_side_tag(mmd, params):
|
||||
"""
|
||||
If a side tag identifier is given, note it in the xmd
|
||||
|
||||
:param Modulemd.ModuleStream mmd: the modulemd to apply the overrides on
|
||||
:param dict params: the API parameters passed in by the user
|
||||
"""
|
||||
side_tag = params.get('side_tag')
|
||||
if not side_tag:
|
||||
# no changes needed
|
||||
return
|
||||
|
||||
xmd = mmd.get_xmd()
|
||||
xmd.setdefault("mbs", {})["side_tag"] = side_tag
|
||||
mmd.set_xmd(xmd)
|
||||
|
||||
|
||||
def _modify_buildtime_streams(db_session, mmd, new_streams_func):
|
||||
"""
|
||||
Modify buildtime streams using the input new_streams_func.
|
||||
@@ -562,6 +579,7 @@ def submit_module_build(db_session, username, mmd, params, module_stream_version
|
||||
for mmd in input_mmds:
|
||||
validate_mmd(mmd)
|
||||
_apply_dep_overrides(mmd, params)
|
||||
_apply_side_tag(mmd, params)
|
||||
_modify_buildtime_streams(db_session, mmd, resolve_base_module_virtual_streams)
|
||||
_process_support_streams(db_session, mmd, params)
|
||||
mmds += generate_expanded_mmds(db_session, mmd, raise_if_stream_ambigous,
|
||||
|
||||
@@ -24,3 +24,4 @@ data:
|
||||
requires: {}
|
||||
mse: true
|
||||
koji_tag: module-f28-build
|
||||
koji_side_tag_format: module-f28-{side_tag}-build
|
||||
|
||||
@@ -99,6 +99,33 @@ class TestDBModule:
|
||||
"testmodule", "master", "20170109091357", "78e4a6fd").keys()
|
||||
assert set(result) == expected
|
||||
|
||||
@pytest.mark.parametrize("missing_format", [False, True])
|
||||
def test_get_module_build_dependencies_side_tag(
|
||||
self, missing_format, reuse_component_init_data):
|
||||
"""
|
||||
Test that we get the correct base module tag when a side tag is specified
|
||||
"""
|
||||
platform = models.ModuleBuild.get_by_id(db_session, 1)
|
||||
module = models.ModuleBuild.get_by_id(db_session, 2)
|
||||
mmd = module.mmd()
|
||||
xmd = mmd.get_xmd()
|
||||
side_tag = "SIDETAG"
|
||||
expected = {"module-f28-SIDETAG-build"}
|
||||
xmd["mbs"]["side_tag"] = side_tag
|
||||
mmd.set_xmd(xmd)
|
||||
if missing_format:
|
||||
# remove koji_tag_format from our platform
|
||||
platform_mmd = platform.mmd()
|
||||
platform_xmd = platform_mmd.get_xmd()
|
||||
del platform_xmd["mbs"]["koji_side_tag_format"]
|
||||
platform_mmd.set_xmd(platform_xmd)
|
||||
platform.modulemd = mmd_to_str(mmd)
|
||||
db_session.commit()
|
||||
expected = {"module-f28-build"}
|
||||
resolver = mbs_resolver.GenericResolver.create(db_session, conf, backend="db")
|
||||
result = resolver.get_module_build_dependencies(mmd=mmd).keys()
|
||||
assert set(result) == expected
|
||||
|
||||
def test_get_module_build_dependencies_recursive(self, reuse_component_init_data):
|
||||
"""
|
||||
Tests that the buildrequires are returned when it is two layers deep
|
||||
|
||||
@@ -17,7 +17,7 @@ from module_build_service.common.utils import (mmd_to_str, load_mmd,
|
||||
from module_build_service.scheduler.db_session import db_session
|
||||
from module_build_service.web.submit import (
|
||||
get_prefixed_version, submit_module_build, submit_module_build_from_yaml,
|
||||
process_module_context_configuration
|
||||
process_module_context_configuration, _apply_side_tag,
|
||||
)
|
||||
from tests import (
|
||||
scheduler_init_data,
|
||||
@@ -218,6 +218,53 @@ class TestProcessModuleContextConfiguration:
|
||||
assert stream.is_static_context()
|
||||
|
||||
|
||||
class TestApplySideTag:
|
||||
def get_mmd(self):
|
||||
yaml_str = """
|
||||
document: modulemd
|
||||
version: 2
|
||||
data:
|
||||
name: app
|
||||
stream: test
|
||||
summary: "A test module"
|
||||
description: >
|
||||
"A test module stream"
|
||||
license:
|
||||
module: [ MIT ]
|
||||
dependencies:
|
||||
- buildrequires:
|
||||
platform: []
|
||||
gtk: []
|
||||
requires:
|
||||
platform: []
|
||||
gtk: []
|
||||
"""
|
||||
return load_mmd(yaml_str)
|
||||
|
||||
def test_apply_side_tag(self):
|
||||
"""
|
||||
Test that the side tag option is correctly added into the xmd
|
||||
"""
|
||||
mmd = self.get_mmd()
|
||||
side_tag = "SIDETAG"
|
||||
_apply_side_tag(mmd, {"side_tag": side_tag})
|
||||
|
||||
xmd = mmd.get_xmd()
|
||||
assert xmd["mbs"]["side_tag"] == side_tag
|
||||
|
||||
def test_apply_side_tag_no_option(self):
|
||||
"""
|
||||
Test that the xmd is unchanged when option not given
|
||||
"""
|
||||
mmd = self.get_mmd()
|
||||
xmd_orig = mmd.get_xmd()
|
||||
_apply_side_tag(mmd, {})
|
||||
|
||||
xmd = mmd.get_xmd()
|
||||
assert xmd == xmd_orig
|
||||
assert "side_tag" not in xmd.get("mbs", {})
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("reuse_component_init_data")
|
||||
class TestUtilsComponentReuse:
|
||||
@mock.patch("module_build_service.web.submit.submit_module_build")
|
||||
|
||||
Reference in New Issue
Block a user