Tag the component to final tag in case it is built, but not tagged.

This commit is contained in:
Jan Kaluza
2017-06-05 13:48:36 +02:00
committed by Ralph Bean
parent af5460db80
commit 439767cbcf
3 changed files with 33 additions and 16 deletions

View File

@@ -65,6 +65,7 @@ class KojiModuleBuilder(GenericBuilder):
"""
self.owner = owner
self.module_str = module.name
self.mmd = module.mmd()
self.config = config
self.tag_name = tag_name
self.__prep = False
@@ -373,15 +374,15 @@ chmod 644 %buildroot/%_rpmconfigdir/macros.d/macros.modules
return get_result()
def _get_task_by_artifact(self, artifact_name):
def _get_build_by_artifact(self, artifact_name):
"""
:param artifact_name: e.g. bash
Searches for a tagged package inside module tag.
Searches for a complete build of artifact belonging to this module.
The returned build can be even untagged.
Returns task_id or None.
Returns koji_session.getBuild response or None.
TODO: handle builds with skip_tag (not tagged at all)
"""
# yaml file can hold only one reference to a package name, so
# I expect that we can have only one build of package within single module
@@ -402,6 +403,21 @@ chmod 644 %buildroot/%_rpmconfigdir/macros.d/macros.modules
assert len(tagged) == 1, "Expected exactly one item in list. Got %s" % tagged
return tagged[0]
# If the build cannot be found in tag, it may be untagged as a result
# of some earlier inconsistent situation. Let's find the task_info
# based on the list of untagged builds
release = module_build_service.utils.get_rpm_release_from_mmd(self.mmd)
opts = {'name': artifact_name}
untagged = self.koji_session.untaggedBuilds(**opts)
for build in untagged:
if build["release"].endswith(release):
build_info = self.koji_session.getBuild(build['id'])
if not build_info:
log.error("Cannot get build info of build %r", build['id'])
return None
self.tag_artifacts([build_info["nvr"]])
return build_info
return None
def build(self, artifact_name, source):
@@ -434,7 +450,7 @@ chmod 644 %buildroot/%_rpmconfigdir/macros.d/macros.modules
raise RuntimeError("Buildroot is not prep-ed")
# Skip existing builds
task_info = self._get_task_by_artifact(artifact_name)
task_info = self._get_build_by_artifact(artifact_name)
if task_info:
log.info("skipping build of %s. Build already exists (task_id=%s), via %s" % (
source, task_info['task_id'], self))

View File

@@ -29,13 +29,13 @@ import module_build_service.pdc
import module_build_service.utils
import module_build_service.messaging
from module_build_service.utils import (
start_next_batch_build, attempt_to_reuse_all_components)
start_next_batch_build, attempt_to_reuse_all_components,
get_rpm_release_from_mmd)
from module_build_service.builder.KojiContentGenerator import KojiContentGenerator
from requests.exceptions import ConnectionError
import koji
import hashlib
import logging
import os
@@ -43,15 +43,6 @@ import os
logging.basicConfig(level=logging.DEBUG)
def get_rpm_release_from_mmd(mmd):
"""
Returns the dist tag based on the modulemd metadata and MBS configuration.
"""
dist_str = '.'.join([mmd.name, mmd.stream, str(mmd.version)])
dist_hash = hashlib.sha1(dist_str).hexdigest()[:8]
return conf.default_dist_tag_prefix + dist_hash
def get_artifact_from_srpm(srpm_path):
return os.path.basename(srpm_path).replace(".src.rpm", "")

View File

@@ -34,6 +34,7 @@ import copy
import kobo.rpmlib
import inspect
from six import iteritems
import hashlib
import modulemd
@@ -1219,3 +1220,12 @@ def validate_koji_tag(tag_arg_names, pre='', post='-', dict_key='name'):
return wrapper
return validation_decorator
def get_rpm_release_from_mmd(mmd):
"""
Returns the dist tag based on the modulemd metadata and MBS configuration.
"""
dist_str = '.'.join([mmd.name, mmd.stream, str(mmd.version)])
dist_hash = hashlib.sha1(dist_str).hexdigest()[:8]
return conf.default_dist_tag_prefix + dist_hash