mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-24 02:32:26 +08:00
Fix #670 - Tag Content Generator Koji build to special tag based on the base module stream
This commit is contained in:
@@ -359,6 +359,42 @@ class KojiContentGenerator(object):
|
||||
|
||||
return serverdir
|
||||
|
||||
def _tag_cg_build(self):
|
||||
"""
|
||||
Tags the Content Generator build to module.cg_build_koji_tag.
|
||||
"""
|
||||
session = KojiModuleBuilder.get_session(self.config, self.owner)
|
||||
|
||||
tag_name = self.module.cg_build_koji_tag
|
||||
if not tag_name:
|
||||
log.info("%r: Not tagging Content Generator build, no "
|
||||
"cg_build_koji_tag set", self.module)
|
||||
return
|
||||
|
||||
tag_names_to_try = [tag_name, self.config.koji_cg_default_build_tag]
|
||||
for tag in tag_names_to_try:
|
||||
log.info("Trying %s", tag)
|
||||
tag_info = session.getTag(tag)
|
||||
if tag_info:
|
||||
break
|
||||
|
||||
log.info("%r: Tag %s not found in Koji, trying next one.",
|
||||
self.module, tag)
|
||||
|
||||
if not tag_info:
|
||||
log.warn("%r:, Not tagging Content Generator build, no "
|
||||
"available tag found, tried %r", self.module,
|
||||
tag_names_to_try)
|
||||
return
|
||||
|
||||
build = self._get_build()
|
||||
nvr = "%s-%s-%s" % (build["name"], build["version"], build["release"])
|
||||
|
||||
log.info("Content generator build %s will be tagged as %s in "
|
||||
"Koji", nvr, tag)
|
||||
session.tagBuild(tag_info["id"], nvr)
|
||||
|
||||
|
||||
def koji_import(self):
|
||||
"""This method imports given module into the configured koji instance as
|
||||
a content generator based build
|
||||
@@ -371,6 +407,7 @@ class KojiContentGenerator(object):
|
||||
try:
|
||||
serverdir = self._upload_outputs(session, metadata, file_dir)
|
||||
build_info = session.CGImport(metadata, serverdir)
|
||||
self._tag_cg_build()
|
||||
log.info("Content generator import done.")
|
||||
log.debug(json.dumps(build_info, sort_keys=True, indent=4))
|
||||
|
||||
|
||||
@@ -389,7 +389,25 @@ class Config(object):
|
||||
'type': str,
|
||||
'default': '',
|
||||
'desc': ('The distinguished name of the container or organizational unit containing '
|
||||
'the groups in LDAP')}
|
||||
'the groups in LDAP')},
|
||||
'base_module_names': {
|
||||
'type': set,
|
||||
'default': set(['platform', 'bootstrap']),
|
||||
'desc': "Set of module names which defines the product version "
|
||||
"(by their stream) of modules depending on them."},
|
||||
'koji_cg_build_tag_template': {
|
||||
'type': str,
|
||||
'default': "{}-modular-updates-candidate",
|
||||
'desc': "Name of a Koji tag where the top-level Content Generator "
|
||||
"build is tagged to. The '{}' string is replaced by a "
|
||||
"stream name of a base module on top of which the "
|
||||
"module is built."},
|
||||
'koji_cg_default_build_tag': {
|
||||
'type': str,
|
||||
'default': "modular-updates-candidate",
|
||||
'desc': "The name of Koji tag which should be used as fallback "
|
||||
"when koji_cg_build_tag_template tag is not found in "
|
||||
"Koji."},
|
||||
}
|
||||
|
||||
def __init__(self, conf_section_obj):
|
||||
|
||||
22
module_build_service/migrations/versions/edb537dd1e8c_.py
Normal file
22
module_build_service/migrations/versions/edb537dd1e8c_.py
Normal file
@@ -0,0 +1,22 @@
|
||||
"""Add cg_build_koji_tag
|
||||
|
||||
Revision ID: edb537dd1e8c
|
||||
Revises: c11a3cfec2a9
|
||||
Create Date: 2017-09-22 13:50:41.433144
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'edb537dd1e8c'
|
||||
down_revision = 'c11a3cfec2a9'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.add_column('module_builds', sa.Column('cg_build_koji_tag', sa.String(), nullable=True))
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_column('module_builds', 'cg_build_koji_tag')
|
||||
@@ -148,6 +148,8 @@ class ModuleBuild(MBSBase):
|
||||
state_reason = db.Column(db.String)
|
||||
modulemd = db.Column(db.String, nullable=False)
|
||||
koji_tag = db.Column(db.String) # This gets set after 'wait'
|
||||
# Koji tag to which tag the Content Generator Koji build.
|
||||
cg_build_koji_tag = db.Column(db.String) # This gets set after wait
|
||||
copr_owner = db.Column(db.String)
|
||||
copr_project = db.Column(db.String)
|
||||
scmurl = db.Column(db.String)
|
||||
|
||||
@@ -389,7 +389,7 @@ def get_module_build_dependencies(session, module_info, strict=False):
|
||||
instance.
|
||||
:param strict: Normally this function returns None if no module can be
|
||||
found. If strict=True, then a ValueError is raised.
|
||||
:return final list of koji tags
|
||||
:return dict with koji_tag as a key and ModuleMetadata object as value.
|
||||
|
||||
Example minimal module_info:
|
||||
{
|
||||
@@ -402,7 +402,7 @@ def get_module_build_dependencies(session, module_info, strict=False):
|
||||
# XXX get definitive list of modules
|
||||
|
||||
# This is the set we're going to build up and return.
|
||||
module_tags = set()
|
||||
module_tags = {}
|
||||
|
||||
if not isinstance(module_info, modulemd.ModuleMetadata):
|
||||
queried_module = get_module(session, module_info, strict=strict)
|
||||
@@ -430,7 +430,10 @@ def get_module_build_dependencies(session, module_info, strict=False):
|
||||
modules = _get_recursively_required_modules(
|
||||
session, modified_dep, strict=strict)
|
||||
tags = [m["koji_tag"] for m in modules]
|
||||
module_tags = module_tags.union(set(tags))
|
||||
for m in modules:
|
||||
if m["koji_tag"] in module_tags:
|
||||
continue
|
||||
module_tags[m["koji_tag"]] = _extract_modulemd(m["modulemd"])
|
||||
|
||||
return module_tags
|
||||
|
||||
|
||||
@@ -172,13 +172,15 @@ def wait(config, session, msg):
|
||||
are going to build. We use private method here to allow "retry"
|
||||
on failure.
|
||||
"""
|
||||
cg_build_koji_tag = conf.koji_cg_default_build_tag
|
||||
|
||||
if conf.system != "koji":
|
||||
# In case of non-koji backend, we want to get the dependencies
|
||||
# of the local module build based on ModuleMetadata, because the
|
||||
# local build is not stored in PDC and therefore we cannot query
|
||||
# it using the `pdc_query` as for Koji below.
|
||||
dependencies = module_build_service.pdc.get_module_build_dependencies(
|
||||
pdc_session, build.mmd(), strict=True)
|
||||
pdc_session, build.mmd(), strict=True).keys()
|
||||
|
||||
# We also don't want to get the tag name from the PDC, but just
|
||||
# generate it locally instead.
|
||||
@@ -194,16 +196,28 @@ def wait(config, session, msg):
|
||||
'release': module_info['version'],
|
||||
}
|
||||
log.info("Getting %s deps from pdc (query %r)" % (module_info['name'], pdc_query))
|
||||
dependencies = module_build_service.pdc.get_module_build_dependencies(
|
||||
deps_dict = module_build_service.pdc.get_module_build_dependencies(
|
||||
pdc_session, pdc_query, strict=True)
|
||||
dependencies = set(deps_dict.keys())
|
||||
|
||||
# Find out the name of Koji tag to which the module's Content
|
||||
# Generator build should be tagged once the build finishes.
|
||||
module_names_streams = {mmd.name:mmd.stream
|
||||
for mmd in deps_dict.values()}
|
||||
for base_module_name in conf.base_module_names:
|
||||
if base_module_name in module_names_streams:
|
||||
cg_build_koji_tag = conf.koji_cg_build_tag_template.format(
|
||||
module_names_streams[base_module_name])
|
||||
break
|
||||
|
||||
log.info("Getting %s tag from pdc (query %r)" % (module_info['name'], pdc_query))
|
||||
tag = module_build_service.pdc.get_module_tag(
|
||||
pdc_session, pdc_query, strict=True)
|
||||
|
||||
return dependencies, tag
|
||||
return dependencies, tag, cg_build_koji_tag
|
||||
|
||||
try:
|
||||
dependencies, tag = _get_deps_and_tag()
|
||||
dependencies, tag, cg_build_koji_tag = _get_deps_and_tag()
|
||||
except ValueError:
|
||||
reason = "Failed to get module info from PDC. Max retries reached."
|
||||
log.exception(reason)
|
||||
@@ -219,6 +233,10 @@ def wait(config, session, msg):
|
||||
log.debug("Assigning koji tag=%s to module build" % tag)
|
||||
build.koji_tag = tag
|
||||
|
||||
log.debug("Assigning Content Generator build koji tag=%s to module "
|
||||
"build", cg_build_koji_tag)
|
||||
build.cg_build_koji_tag = cg_build_koji_tag
|
||||
|
||||
builder = module_build_service.builder.GenericBuilder.create_from_module(
|
||||
session, build, config)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user