From cd57fc015f7d3d29ae5313b4be1ffd06009719f0 Mon Sep 17 00:00:00 2001 From: Clement Verna Date: Mar 04 2019 15:15:06 +0000 Subject: Drop support for fedmsg and replace by fedora-messaging This commit replaces fedmsg by fedora-messaging a library that uses AMQP protocol. More details can be found here https://fedoraproject.org/wiki/Infrastructure_2020/Fedora_Messaging. Signed-off-by: Clement Verna --- diff --git a/conf/settings.py.example b/conf/settings.py.example index 466e2bc..164ac45 100644 --- a/conf/settings.py.example +++ b/conf/settings.py.example @@ -58,12 +58,6 @@ MESSAGE_BUS_PUBLISH = False # default, but you could create your own. # Supported values: 'dummy', 'stomp', 'fedmsg' MESSAGE_BUS_PLUGIN = 'fedmsg' -# You can pass extra arguments to your message bus plugin here. For instance, -# the fedmsg plugin expects an extra `modname` argument that can be used to -# configure the topic, like this: -# ... -# e.g. org.fedoraproject.prod.taskotron.result.new -MESSAGE_BUS_KWARGS = {'modname': 'resultsdb'} ## Alternatively, you could use the 'stomp' messaging plugin. #MESSAGE_BUS_PLUGIN = 'stomp' diff --git a/requirements.txt b/requirements.txt index 9f94996..ede39be 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ # A note for maintainers: Please keep this list in sync and in the same order # as the spec file. -fedmsg >= 0.16.2 +fedora-messaging alembic >= 0.8.3 Flask >= 0.10.1 # FIXME: Flask-RESTful 0.3.6 breaks tests, see https://phab.qa.fedoraproject.org/T961 diff --git a/resultsdb.spec b/resultsdb.spec index 6aa4d8c..6b6394c 100644 --- a/resultsdb.spec +++ b/resultsdb.spec @@ -11,8 +11,7 @@ Source0: https://qa.fedoraproject.org/releases/%{name}/%{name}-%{version} BuildArch: noarch %if 0%{?fedora} -Requires: fedmsg -Requires: python3-fedmsg +Requires: python3-fedora-messaging Requires: python3-alembic Requires: python3-flask Requires: python3-flask-restful @@ -21,7 +20,7 @@ Requires: python3-iso8601 Requires: python3-six Requires: python3-sqlalchemy %else -Requires: fedmsg >= 0.16.2 +Requires: python-fedora-messaging Requires: python-alembic >= 0.8.3 Requires: python-flask >= 0.10.1 Requires: python-flask-restful >= 0.2.11 diff --git a/resultsdb/messaging.py b/resultsdb/messaging.py index fc9127c..4b8d8c2 100644 --- a/resultsdb/messaging.py +++ b/resultsdb/messaging.py @@ -22,7 +22,8 @@ import json import pkg_resources -import fedmsg +from fedora_messaging.api import Message, publish +from fedora_messaging.exceptions import PublishReturned, ConnectionException from resultsdb import db from resultsdb.models.results import Result, ResultData @@ -83,7 +84,7 @@ def publish_taskotron_message(result, include_job_url=False): if datum.key in ('item', 'type',) ) task['name'] = result.testcase.name - msg = { + body = { 'task': task, 'result': { 'id': result.id, @@ -95,9 +96,18 @@ def publish_taskotron_message(result, include_job_url=False): } if include_job_url: # only in the v1 API - msg['result']['job_url'] = result.groups[0].ref_url if result.groups else None + body['result']['job_url'] = result.groups[0].ref_url if result.groups else None - fedmsg.publish(topic='result.new', modname='taskotron', msg=msg) + try: + msg = Message ( + topic='taskotron.result.new', + body=body + ) + publish(msg) + except PublishReturned as e: + log.error('Fedora Messaging broker rejected message {}: {}'.format(msg.id, e)) + except ConnectionException as e: + log.error('Error sending message {}: {}'.format(msg.id, e)) def create_message(result): @@ -138,7 +148,18 @@ class FedmsgPlugin(MessagingPlugin): """ A fedmsg plugin, used to publish to the fedmsg bus. """ def publish(self, message): - fedmsg.publish(topic='result.new', modname=self.modname, msg=message) + + try: + msg = Message( + topic='{}.result.new'.format(self.modname), + body=message + ) + publish(msg) + except PublishReturned as e: + log.error('Fedora Messaging broker rejected message {}: {}'.format(msg.id, e)) + except ConnectionException as e: + log.error('Error sending message {}: {}'.format(msg.id, e)) + class StompPlugin(MessagingPlugin):