From 2312efce4526d6a86a8bdf4fb96868b9b2a4680c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kadl=C4=8D=C3=ADk?= Date: Tue, 28 Feb 2017 16:10:00 +0100 Subject: [PATCH 1/8] Not use PDC for copr builder --- module_build_service/scheduler/handlers/modules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_build_service/scheduler/handlers/modules.py b/module_build_service/scheduler/handlers/modules.py index 7a2a46a6..eb0b15ff 100644 --- a/module_build_service/scheduler/handlers/modules.py +++ b/module_build_service/scheduler/handlers/modules.py @@ -154,7 +154,7 @@ def wait(config, session, msg): tag = None dependencies = [] - if conf.system == "mock": + if conf.system in ["mock", "copr"]: # In case of mock, we do not try to get anything from pdc, # just generate our own koji_tag to identify the module in messages. tag = '-'.join(['module', module_info['name'], From ba0c4eb9daf1a030eec113c2a773a2f92565e923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kadl=C4=8D=C3=ADk?= Date: Tue, 28 Feb 2017 16:14:24 +0100 Subject: [PATCH 2/8] Add missing build_id param to build_srpm method --- module_build_service/builder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module_build_service/builder.py b/module_build_service/builder.py index e9e74b28..a71358cd 100644 --- a/module_build_service/builder.py +++ b/module_build_service/builder.py @@ -1038,7 +1038,7 @@ class CoprModuleBuilder(GenericBuilder): else: return self.build_srpm(artifact_name, source) - def build_srpm(self, artifact_name, source): + def build_srpm(self, artifact_name, source, build_id=None): if not self.__prep: raise RuntimeError("Buildroot is not prep-ed") From a2af794bed8978e701353f501f31e71a5aab536d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kadl=C4=8D=C3=ADk?= Date: Mon, 6 Mar 2017 22:20:10 +0100 Subject: [PATCH 3/8] Stop assuming that copr build is already completed --- module_build_service/builder.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/module_build_service/builder.py b/module_build_service/builder.py index a71358cd..151e72ce 100644 --- a/module_build_service/builder.py +++ b/module_build_service/builder.py @@ -1047,9 +1047,7 @@ class CoprModuleBuilder(GenericBuilder): if response.output != "ok": log.error(response.error) - # Since we don't have implemented messaging support in copr yet, - # let's just assume that the build is finished by now - return response.data["ids"][0], koji.BUILD_STATES["COMPLETE"], response.message, None + return response.data["ids"][0], koji.BUILD_STATES["BUILDING"], response.message, None def _wait_until_all_builds_are_finished(self, module): while True: From e849c5da1631584deef94a21fca0d4d299d1b33b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kadl=C4=8D=C3=ADk?= Date: Mon, 6 Mar 2017 23:44:07 +0100 Subject: [PATCH 4/8] Test parsing buildsys.state.change message --- tests/test_messaging.py | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/test_messaging.py diff --git a/tests/test_messaging.py b/tests/test_messaging.py new file mode 100644 index 00000000..1a959173 --- /dev/null +++ b/tests/test_messaging.py @@ -0,0 +1,54 @@ +# Copyright (c) 2017 Red Hat, Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +# Written by Jakub Kadlcik + + +import unittest +from module_build_service import messaging + + +class TestFedmsgMessaging(unittest.TestCase): + + def test_buildsys_state_change(self): + # https://fedora-fedmsg.readthedocs.io/en/latest/topics.html#id134 + buildsys_state_change_msg = { + 'msg': { + 'attribute': 'state', + 'build_id': 614503, + 'instance': 'primary', + 'name': 'plasma-systemsettings', + 'new': 1, + 'old': 0, + 'owner': 'dvratil', + 'release': '1.fc23', + 'task_id': 9053697, + 'version': '5.2.1' + }, + 'msg_id': '2015-51be4c8e-8ab6-4dcb-ac0d-37b257765c71', + 'timestamp': 1424789698.0, + 'topic': 'org.fedoraproject.prod.buildsys.build.state.change' + } + + topic = 'org.fedoraproject.prod.buildsys.build.state.change' + msg = messaging.BaseMessage.from_fedmsg(topic, buildsys_state_change_msg) + + self.assertEqual(msg.build_id, 614503) + self.assertEqual(msg.build_new_state, 1) From 233042c34000868ef533b4693c6de5e6969ea346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kadl=C4=8D=C3=ADk?= Date: Mon, 6 Mar 2017 23:48:35 +0100 Subject: [PATCH 5/8] Process copr fedmsg messages --- module_build_service/messaging.py | 37 +++++++++++++++++++++++++++++-- tests/test_messaging.py | 35 +++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/module_build_service/messaging.py b/module_build_service/messaging.py index fad73253..86a98c4c 100644 --- a/module_build_service/messaging.py +++ b/module_build_service/messaging.py @@ -32,6 +32,7 @@ try: except ImportError: from funcsigs import signature +from rpmUtils.miscutils import splitFilename from module_build_service import log @@ -160,7 +161,7 @@ class BaseMessage(object): regex_pattern = re.compile( (r'(?P' + categories_re + r')(?:\.)' r'(?Pbuild|repo|module)(?:(?:\.)' - r'(?Pstate))?(?:\.)(?Pchange|done)$')) + r'(?Pstate|build))?(?:\.)(?Pchange|done|end)$')) regex_results = re.search(regex_pattern, topic) if regex_results: @@ -214,6 +215,13 @@ class BaseMessage(object): msg_obj = MBSModule( msg_id, msg_inner_msg.get('id'), msg_inner_msg.get('state')) + elif category == 'copr' and object == 'build': + build = msg_inner_msg.get('build') + status = msg_inner_msg.get('status') + pkg = msg_inner_msg.get('pkg') + what = msg_inner_msg.get('what') + msg_obj = CoprBuildEnd(msg_id, build, status, pkg, what) + # If the message matched the regex and is important to the app, # it will be returned if msg_obj: @@ -263,6 +271,31 @@ class KojiRepoChange(BaseMessage): self.repo_tag = repo_tag +class CoprBuildEnd(object): + """ A wrapper class that transforms copr message attributes + to a KojiBuildChange message object + :param msg_id: the id of the msg (e.g. 2016-SomeGUID) + :param build_id: the id of the build (e.g. 264382) + :param status: the new build state + (see http://copr-backend.readthedocs.io/package/constants.html#backend.constants.BuildStatus ) + :param pkg: the full name of what is being built + (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 __new__(cls, msg_id, build_id, status, pkg, what=None): + name, version, release, epoch, arch = splitFilename(pkg) + return KojiBuildChange( + msg_id=msg_id, + build_id=build_id, + task_id=build_id, + build_new_state=status, + build_name=name, + build_version=version, + build_release=".".join(s for s in [release, epoch, arch] if s), + state_reason=what, + ) + + class MBSModule(BaseMessage): """ A class that inherits from BaseMessage to provide a message object for a module event generated by module_build_service @@ -377,7 +410,7 @@ def _amq_publish(topic, msg, conf, service): _messaging_backends = { 'fedmsg': { 'publish': _fedmsg_publish, - 'services': ['buildsys', 'mbs'] + 'services': ['buildsys', 'mbs', 'copr'] }, 'amq': { 'publish': _amq_publish, diff --git a/tests/test_messaging.py b/tests/test_messaging.py index 1a959173..c02a9962 100644 --- a/tests/test_messaging.py +++ b/tests/test_messaging.py @@ -52,3 +52,38 @@ class TestFedmsgMessaging(unittest.TestCase): self.assertEqual(msg.build_id, 614503) self.assertEqual(msg.build_new_state, 1) + + def test_copr_build_end(self): + # http://fedora-fedmsg.readthedocs.io/en/latest/topics.html#copr-build-end + copr_build_end_msg = { + 'msg': { + 'build': 100, + 'chroot': 'fedora-20-x86_64', + 'copr': 'mutt-kz', + 'ip': '172.16.3.3', + 'pid': 12010, + 'pkg': 'mutt-kz-1.5.23.1-1.20150203.git.c8504a8a.fc21', + 'status': 1, + 'user': 'fatka', + 'version': '1.5.23.1-1.20150203.git.c8504a8a.fc21', + 'what': 'build end: user:fatka copr:mutt-kz build:100 ip:172.16.3.3 pid:12010 status:1', + 'who': 'worker-2' + }, + 'msg_id': '2013-b05a323d-37ee-4396-9635-7b5dfaf5441b', + 'timestamp': 1383956707.634, + 'topic': 'org.fedoraproject.prod.copr.build.end', + 'username': 'copr' + } + + topic = 'org.fedoraproject.prod.copr.build.end' + msg = messaging.BaseMessage.from_fedmsg(topic, copr_build_end_msg) + self.assertIsInstance(msg, messaging.KojiBuildChange) + self.assertEqual(msg.msg_id, '2013-b05a323d-37ee-4396-9635-7b5dfaf5441b') + self.assertEqual(msg.build_id, 100) + self.assertEqual(msg.task_id, 100) + self.assertEqual(msg.build_new_state, 1) + self.assertEqual(msg.build_name, 'mutt-kz') + self.assertEqual(msg.build_version, '1.5.23.1') + self.assertEqual(msg.build_release, '1.20150203.git.c8504a8a.fc21') + self.assertEqual(msg.state_reason, + 'build end: user:fatka copr:mutt-kz build:100 ip:172.16.3.3 pid:12010 status:1') From 17f94d0220330540e1921978a7a0e90a31ba910a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kadl=C4=8D=C3=ADk?= Date: Tue, 7 Mar 2017 15:52:15 +0100 Subject: [PATCH 6/8] Handle copr messages only when it is set as build system --- module_build_service/messaging.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module_build_service/messaging.py b/module_build_service/messaging.py index 86a98c4c..6e20b425 100644 --- a/module_build_service/messaging.py +++ b/module_build_service/messaging.py @@ -33,7 +33,7 @@ except ImportError: from funcsigs import signature from rpmUtils.miscutils import splitFilename -from module_build_service import log +from module_build_service import log, conf class BaseMessage(object): @@ -215,7 +215,7 @@ class BaseMessage(object): msg_obj = MBSModule( msg_id, msg_inner_msg.get('id'), msg_inner_msg.get('state')) - elif category == 'copr' and object == 'build': + elif conf.system == category == 'copr' and object == 'build': build = msg_inner_msg.get('build') status = msg_inner_msg.get('status') pkg = msg_inner_msg.get('pkg') From cdde6f5e20612dca7305959c9f190101121acecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kadl=C4=8D=C3=ADk?= Date: Tue, 7 Mar 2017 16:03:48 +0100 Subject: [PATCH 7/8] Use kobo.rpmlib instead of rpmUtils --- module_build_service/messaging.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/module_build_service/messaging.py b/module_build_service/messaging.py index 6e20b425..b7413ec5 100644 --- a/module_build_service/messaging.py +++ b/module_build_service/messaging.py @@ -27,12 +27,12 @@ import json import os import re +import kobo.rpmlib try: from inspect import signature except ImportError: from funcsigs import signature -from rpmUtils.miscutils import splitFilename from module_build_service import log, conf @@ -283,15 +283,15 @@ class CoprBuildEnd(object): :param state_reason: the optional reason as to why the state changed """ def __new__(cls, msg_id, build_id, status, pkg, what=None): - name, version, release, epoch, arch = splitFilename(pkg) + nvr = kobo.rpmlib.parse_nvra(pkg) return KojiBuildChange( msg_id=msg_id, build_id=build_id, task_id=build_id, build_new_state=status, - build_name=name, - build_version=version, - build_release=".".join(s for s in [release, epoch, arch] if s), + build_name=nvr["name"], + build_version=nvr["version"], + build_release=".".join(s for s in [nvr["release"], nvr["epoch"], nvr["arch"]] if s), state_reason=what, ) From b051ea2b4d0b83e20e5c384e5cf565826045f6b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kadl=C4=8D=C3=ADk?= Date: Thu, 9 Mar 2017 09:34:59 +0100 Subject: [PATCH 8/8] Set copr as build system for this test --- tests/test_messaging.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_messaging.py b/tests/test_messaging.py index c02a9962..b6e810b5 100644 --- a/tests/test_messaging.py +++ b/tests/test_messaging.py @@ -22,7 +22,7 @@ import unittest -from module_build_service import messaging +from module_build_service import messaging, conf class TestFedmsgMessaging(unittest.TestCase): @@ -75,6 +75,7 @@ class TestFedmsgMessaging(unittest.TestCase): 'username': 'copr' } + conf.set_item("system", "copr") topic = 'org.fedoraproject.prod.copr.build.end' msg = messaging.BaseMessage.from_fedmsg(topic, copr_build_end_msg) self.assertIsInstance(msg, messaging.KojiBuildChange)