From 483491f9e956b5c9d59537362644880b069eafe4 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 29 2019 13:36:19 +0000 Subject: Port elections to fedora-messaging and off fedmsg Signed-off-by: Pierre-Yves Chibon --- diff --git a/fedmsg.d/elections.py b/fedmsg.d/elections.py deleted file mode 100644 index 385697b..0000000 --- a/fedmsg.d/elections.py +++ /dev/null @@ -1,20 +0,0 @@ -""" This is an example pkgdb configuration for fedmsg. -By convention, it is normally installed as ``/etc/fedmsg.d/pkgdb.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 -pkgdb producer (wsgi process). -""" - -import socket -hostname = socket.gethostname().split('.')[0] - -config = dict( - endpoints={ - "fedora_elections.%s" % hostname: [ - "tcp://127.0.0.1:3005", - ], - }, -) diff --git a/fedora-messaging.toml.example b/fedora-messaging.toml.example new file mode 100644 index 0000000..db2839f --- /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 = "elections" diff --git a/fedora_elections/fedmsgshim.py b/fedora_elections/fedmsgshim.py index 47daf17..6eb365c 100644 --- a/fedora_elections/fedmsgshim.py +++ b/fedora_elections/fedmsgshim.py @@ -1,17 +1,31 @@ -""" This is a temporary shim that allows fedmsg to be an optional dependency of -elections. 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 """ import warnings +import logging +from fedora_messaging.api import Message, publish +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 e: - warnings.warn(str(e)) + message = Message( + topic='fedora_elections.%s' % topic, + body=msg + ) + publish(message) + 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) diff --git a/requirements.txt b/requirements.txt index e70a503..78dffb3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ Flask>=0.10 flask-oidc Flask-wtf +fedora-messaging kitchen python-fedora SQLAlchemy