Merge #491 Copr builder improvements #3

This commit is contained in:
Jan Kaluža
2017-04-11 05:51:46 +00:00
3 changed files with 39 additions and 11 deletions

View File

@@ -65,8 +65,10 @@ class CoprModuleBuilder(GenericBuilder):
self.copr = None
self.client = CoprModuleBuilder._get_client(config)
self.client.username = self.owner
self.chroot = "custom-1-x86_64"
self.__prep = False
@classmethod
def _get_client(cls, config):
return CoprClient.create_from_file_config(config.copr_config)
@@ -81,6 +83,11 @@ class CoprModuleBuilder(GenericBuilder):
"""
self.copr = self._get_copr_safe()
self._create_module_safe()
# @FIXME Not able to use gcc-c++ in chroot (RhBug: 1440889)
packages = groups["build"] - {"gcc-c++"}
self._update_chroot(packages=list(packages))
if self.copr and self.copr.projectname and self.copr.username:
self.__prep = True
log.info("%r buildroot sucessfully connected." % self)
@@ -104,8 +111,7 @@ class CoprModuleBuilder(GenericBuilder):
return self.client.get_project_details(projectname, username=ownername).handle
def _create_copr(self, ownername, projectname):
# @TODO fix issues with custom-1-x86_64 and custom-1-i386 chroot and use it
return self.client.create_project(ownername, projectname, ["fedora-24-x86_64"])
return self.client.create_project(ownername, projectname, [self.chroot])
def _create_module_safe(self):
from copr.exceptions import CoprRequestException
@@ -159,6 +165,13 @@ class CoprModuleBuilder(GenericBuilder):
koji add-group-pkg $module-build-tag srpm-build bash
"""
# Install the module-build-macros into the buildroot
# We are using same hack as mock builder does
for artifact in artifacts:
if artifact and artifact.startswith("module-build-macros"):
self._update_chroot(packages=["module-build-macros"])
break
# Start of a new batch of builds is triggered by buildsys.repo.done message.
# However in Copr there is no such thing. Therefore we are going to fake
# the message when builds are finished
@@ -168,7 +181,22 @@ class CoprModuleBuilder(GenericBuilder):
log.info("%r adding deps on %r" % (self, dependencies))
# @TODO get architecture from some builder variable
repos = [self._dependency_repo(d, "x86_64") for d in dependencies]
self.client.modify_project(self.copr.projectname, username=self.copr.username, repos=repos)
self._update_chroot(repos=repos)
def _update_chroot(self, packages=None, repos=None):
request = self.client.get_chroot(self.copr.projectname, self.copr.username, self.chroot)
chroot = request.data["chroot"]
current_packages = (chroot["buildroot_pkgs"] or "").split()
current_repos = (chroot["repos"] or "").split()
def merge(current, new):
current, new = current or [], new or []
return " ".join(set(current + new))
self.client.edit_chroot(self.copr.projectname, self.chroot,
ownername=self.copr.username,
packages=merge(current_packages, packages),
repos=merge(current_repos, repos))
def _dependency_repo(self, module, arch, backend="copr"):
try:

View File

@@ -27,7 +27,6 @@
import json
import os
import re
import kobo.rpmlib
try:
from inspect import signature
except ImportError:
@@ -225,8 +224,9 @@ class BaseMessage(object):
build = msg_inner_msg.get('build')
status = msg_inner_msg.get('status')
pkg = msg_inner_msg.get('pkg')
version = msg_inner_msg.get('version')
what = msg_inner_msg.get('what')
msg_obj = CoprBuildEnd(msg_id, build, status, copr, pkg, what)
msg_obj = CoprBuildEnd(msg_id, build, status, copr, pkg, version, what)
# If the message matched the regex and is important to the app,
# it will be returned
@@ -305,16 +305,16 @@ class CoprBuildEnd(KojiBuildChange):
(e.g. mutt-kz-1.5.23.1-1.20150203.git.c8504a8a.fc21)
:param state_reason: the optional reason as to why the state changed
"""
def __init__(self, msg_id, build_id, status, copr, pkg, what=None):
nvr = kobo.rpmlib.parse_nvra(pkg)
def __init__(self, msg_id, build_id, status, copr, pkg, version, what=None):
ver, rel = version.split("-", 1)
super(CoprBuildEnd, self).__init__(
msg_id=msg_id,
build_id=build_id,
task_id=build_id,
build_new_state=status,
build_name=nvr["name"],
build_version=nvr["version"],
build_release=".".join(s for s in [nvr["release"], nvr["epoch"], nvr["arch"]] if s),
build_name=pkg,
build_version=ver,
build_release=rel,
state_reason=what,
)
self.copr = copr

View File

@@ -65,7 +65,7 @@ class TestFedmsgMessaging(unittest.TestCase):
'copr': 'mutt-kz',
'ip': '172.16.3.3',
'pid': 12010,
'pkg': 'mutt-kz-1.5.23.1-1.20150203.git.c8504a8a.fc21',
'pkg': 'mutt-kz', # Reality doesnt match the linked docs
'status': 1,
'user': 'fatka',
'version': '1.5.23.1-1.20150203.git.c8504a8a.fc21',