Merge #1760 use branch name as default component ref

This commit is contained in:
Mike McLean
2022-11-22 14:40:09 +00:00
3 changed files with 40 additions and 40 deletions

View File

@@ -247,7 +247,7 @@ def _scm_get_latest(data):
return {"pkg_name": data.rpm_component.get_name(), "pkg_ref": pkgref, "error": None}
def format_mmd(mmd, scmurl, module=None, db_session=None, srpm_overrides=None):
def format_mmd(mmd, scmurl, module=None, db_session=None, srpm_overrides=None, default_ref=None):
"""
Prepares the modulemd for the MBS. This does things such as replacing the
branches of components with commit hashes and adding metadata in the xmd
@@ -281,6 +281,9 @@ def format_mmd(mmd, scmurl, module=None, db_session=None, srpm_overrides=None):
xmd["mbs"]["commit"] = full_scm_hash
if default_ref is None:
default_ref = xmd["mbs"].get("branch") or conf.default_branch
if mmd.get_rpm_component_names() or mmd.get_module_component_names():
if "rpms" not in xmd["mbs"]:
xmd["mbs"]["rpms"] = {}
@@ -309,7 +312,7 @@ def format_mmd(mmd, scmurl, module=None, db_session=None, srpm_overrides=None):
if not pkg.get_cache():
pkg.set_cache(conf.rpms_default_cache + pkgname)
if not pkg.get_ref():
pkg.set_ref(conf.default_branch)
pkg.set_ref(default_ref)
if not pkg.get_arches():
for arch in conf.arches:
pkg.add_restricted_arch(arch)
@@ -325,7 +328,7 @@ def format_mmd(mmd, scmurl, module=None, db_session=None, srpm_overrides=None):
if not mod.get_repository():
mod.set_repository(conf.modules_default_repository + modname)
if not mod.get_ref():
mod.set_ref(conf.default_branch)
mod.set_ref(default_ref)
# It is possible to override the ref of RPM component using
# the rpm_component_ref_overrides.
@@ -508,6 +511,8 @@ def record_component_builds(
# planned for batch 2 and following.
batch = initial_batch
default_ref = mmd.get_xmd()["mbs"].get("branch")
for component in all_components:
# Increment the batch number when buildorder increases.
if previous_buildorder != component.get_buildorder():
@@ -523,7 +528,7 @@ def record_component_builds(
# It is OK to whitelist all URLs here, because the validity
# of every URL have been already checked in format_mmd(...).
included_mmd = fetch_mmd(full_url, whitelist_url=True)[0]
format_mmd(included_mmd, module.scmurl, module, db_session, srpm_overrides)
format_mmd(included_mmd, module.scmurl, module, db_session, srpm_overrides, default_ref)
batch = record_component_builds(
included_mmd, module, batch, previous_buildorder, main_mmd)
continue

View File

@@ -270,37 +270,24 @@ def _apply_dep_overrides(mmd, params):
)
def _apply_rpm_component_ref_overrides(mmd, params):
def _apply_xmd_params(mmd, params):
"""
If `rpm_component_ref_overrides` is given, note it in the xmd.
Note some parameters in the mbs section of the xmd.
:param Modulemd.ModuleStream mmd: the modulemd to apply the overrides on
:param dict params: the API parameters passed in by the user
"""
ref_overrides = params.get("rpm_component_ref_overrides", {})
if not ref_overrides:
# No changes needed.
xmd_updates = {}
for param in ("rpm_component_ref_overrides", "side_tag", "branch"):
value = params.get(param)
if value:
xmd_updates[param] = value
if not xmd_updates:
return
xmd = mmd.get_xmd()
xmd.setdefault("mbs", {})["rpm_component_ref_overrides"] = ref_overrides
mmd.set_xmd(xmd)
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
xmd.setdefault("mbs", {}).update(xmd_updates)
mmd.set_xmd(xmd)
@@ -617,8 +604,7 @@ def submit_module_build(db_session, username, stream_or_packager, params, module
for mmd in input_mmds:
validate_mmd(mmd)
_apply_dep_overrides(mmd, params)
_apply_side_tag(mmd, params)
_apply_rpm_component_ref_overrides(mmd, params)
_apply_xmd_params(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,

View File

@@ -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, _apply_side_tag,
process_module_context_configuration, _apply_xmd_params,
)
from tests import (
scheduler_init_data,
@@ -317,28 +317,34 @@ data:
"""
return load_mmd(yaml_str)
def test_apply_side_tag(self):
def test_apply_xmd_params(self):
"""
Test that the side tag option is correctly added into the xmd
Test that key params are correctly added into the xmd
"""
mmd = self.get_mmd()
side_tag = "SIDETAG"
_apply_side_tag(mmd, {"side_tag": side_tag})
params = {
"side_tag": "SIDETAG",
"rpm_component_ref_overrides": {"pkg": "f4836ea0"},
"branch": "f37",
}
_apply_xmd_params(mmd, params)
xmd = mmd.get_xmd()
assert xmd["mbs"]["side_tag"] == side_tag
for key in params:
assert xmd["mbs"][key] == params[key]
def test_apply_side_tag_no_option(self):
def test_apply_xmd_params_no_option(self):
"""
Test that the xmd is unchanged when option not given
Test that the xmd is unchanged when no relevant options are given
"""
mmd = self.get_mmd()
xmd_orig = mmd.get_xmd()
_apply_side_tag(mmd, {})
_apply_xmd_params(mmd, {})
xmd = mmd.get_xmd()
assert xmd == xmd_orig
assert "side_tag" not in xmd.get("mbs", {})
for key in ("side_tag", "rpm_component_ref_overrides", "branch"):
assert key not in xmd.get("mbs", {})
@pytest.mark.usefixtures("reuse_component_init_data")
@@ -460,4 +466,7 @@ class TestUtilsComponentReuse:
):
submit_module_build(db_session, "foo", mmd_copy, {"branch": "private-foo"}, version)
# re-copy because submit_module_build could modify xmd
mmd_copy = mmd.copy()
mmd_copy.set_xmd({})
submit_module_build(db_session, "foo", mmd_copy, {"branch": "otherbranch"}, version)