From 8415a1b79d07668cc5840cac2782656927f535f2 Mon Sep 17 00:00:00 2001 From: Julen Landa Alustiza Date: Aug 05 2020 10:00:25 +0000 Subject: Port fedocal to fedora-messaging and drop fedmsg support --- diff --git a/fedmsg.d/fedocal.py b/fedmsg.d/fedocal.py deleted file mode 100644 index fb77d29..0000000 --- a/fedmsg.d/fedocal.py +++ /dev/null @@ -1,20 +0,0 @@ -""" This is an example fedocal configuration for fedmsg. -By convention, it is normally installed as ``/etc/fedmsg.d/fedocal.py`` - -For Fedora Infrastructure, our own version of this file is kept in -``puppet/modules/fedmsg/templates/fedmsg.d/`` - -It needs to be globally available so remote consumers know how to find the -fedocal producer (wsgi process). -""" - -import socket -hostname = socket.gethostname().split('.')[0] - -config = dict( - endpoints={ - "fedocal.%s" % hostname: [ - "tcp://127.0.0.1:3025", - ], - }, -) diff --git a/fedocal/fedocallib/fedmsgshim.py b/fedocal/fedocallib/fedmsgshim.py index 9729095..87aabf5 100644 --- a/fedocal/fedocallib/fedmsgshim.py +++ b/fedocal/fedocallib/fedmsgshim.py @@ -1,18 +1,32 @@ -""" This is a temporary shim that allows fedmsg to be an optional dependency of -pkgdb. If fedmsg is installed, these function calls will try to actually send -messages. If it is not installed, it will return silently. +""" This is an utility module for sending notifications via fedora-messaging :Author: Ralph Bean + :Author: Pierre-Yves Chibon """ -from __future__ import unicode_literals, absolute_import, print_function +from __future__ import unicode_literals, absolute_import -import warnings +import logging +import fedora_messaging.api +from fedora_messaging.exceptions import PublishReturned, ConnectionException -def publish(*args, **kwargs): # pragma: no cover + +_log = logging.getLogger(__name__) + + +def publish(topic, msg): # pragma: no cover + _log.debug('Publishing a message for %r: %s', topic, msg) try: - import fedmsg - fedmsg.publish(*args, **kwargs) - except Exception as err: - warnings.warn(str(err)) + message = fedora_messaging.api.Message( + topic='fedocal.%s' % topic, + body=msg + ) + fedora_messaging.api.publish(message) + _log.debug("Sent to fedora_messaging") + except PublishReturned as e: + _log.exception( + 'Fedora Messaging broker rejected message %s: %s', + message.id, e) + except ConnectionException as e: + _log.exception('Error sending message %s: %s', message.id, e) \ No newline at end of file diff --git a/fedocal_cron.py b/fedocal_cron.py index 32f1421..f77ef43 100644 --- a/fedocal_cron.py +++ b/fedocal_cron.py @@ -26,55 +26,37 @@ This script is meant to be run as a cron job to send the reminders for each meeting that asked for it. """ - +from __future__ import unicode_literals, absolute_import import smtplib import warnings +import logging from email.mime.text import MIMEText import fedocal import fedocal.fedocallib as fedocallib +import fedocal.fedocallib.fedmsgshim as fedmsg - -def fedmsg_init(): - """ Instanciate fedmsg """ - try: - import fedmsg - import fedmsg.config - except ImportError: - warnings.warn("fedmsg ImportError") - return - - config = fedmsg.config.load_config() - config['active'] = True - config['name'] = 'relay_inbound' - config['cert_prefix'] = 'fedocal' - fedmsg.init(**config) - +_log = logging.getLogger(__name__) def fedmsg_publish(meeting, meeting_id): - """ Publish the meeting.reminder messages on fedmsg. + """ Publish the meeting.reminder messages on fedora-messaging. :arg meeting: a Meeting object from fedocallib.model :arg meeting_id: an int representing the meeting identifier in the database """ - try: - import fedmsg - except ImportError: - return + _log.debug('Publishing a message for %r: %s', topic, msg) + meeting_dict = meeting.to_json() meeting_dict['meeting_id'] = meeting_id - fedmsg.publish( - modname="fedocal", - topic="meeting.reminder", - msg=dict( - meeting=meeting_dict, - calendar=meeting.calendar.to_json() - ), + message = dict( + meeting=meeting_dict, + calendar=meeting.calendar.to_json() ) + fedmsg.publish('fedocal.reminder', message) def send_reminder_meeting(meeting, meeting_id): @@ -155,5 +137,4 @@ def send_reminder(): if __name__ == '__main__': - fedmsg_init() send_reminder() diff --git a/fedora-messaging.toml.example b/fedora-messaging.toml.example new file mode 100644 index 0000000..99cd11d --- /dev/null +++ b/fedora-messaging.toml.example @@ -0,0 +1,15 @@ +# Example configuraton for Fedora Messaging +# More information on how to use it or what to do with it at: +# https://fedora-messaging.readthedocs.io/en/stable/configuration.html + +# Broker address +amqp_url = "amqp://" + +# Authentication is TLS-based +[tls] +ca_cert = "/etc/pki/tls/certs/ca-bundle.crt" +keyfile = "/my/client/key.pem" +certfile = "/my/client/cert.pem" + +[client_properties] +app = "fedocal" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 7edf3e5..87ec29d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,3 +23,5 @@ flask_multistatic python-openid python-openid_cla python-openid_teams +fedora-messaging +