From cc3526a33cf8d403ee09c5fc89fe6f886d774df9 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 04 2019 09:37:24 +0000 Subject: [PATCH 1/4] Initial porting of the koji plugin to fedora-messaging We're also initializing a log handler so we can log some things. Signed-off-by: Pierre-Yves Chibon --- diff --git a/fedmsg-koji-plugin.py b/fedmsg-koji-plugin.py index 6d7b3aa..a833adc 100644 --- a/fedmsg-koji-plugin.py +++ b/fedmsg-koji-plugin.py @@ -5,21 +5,22 @@ # Ralph Bean # Mike Bonnet +import logging + from koji.context import context from koji.plugin import callbacks from koji.plugin import callback from koji.plugin import ignore_error - -import fedmsg +import fedora_messaging.api +import fedora_messaging.exceptions import kojihub import re import pprint -# Talk to the fedmsg-relay -fedmsg.init(name='relay_inbound', cert_prefix='koji', active=True) MAX_KEY_LENGTH = 255 +log = logging.getLogger(__name__) def camel_to_dots(name): @@ -174,7 +175,7 @@ def queue_message(cbtype, *args, **kws): # We need this to distinguish between messages from primary koji # and the secondary hubs off for s390 and ppc. - body['instance'] = '{{ fedmsg_koji_instance }}' + body['instance'] = 'primary' # Don't publish these uninformative rpm.sign messages if there's no actual # sigkey present. Koji apparently adds a dummy sig value when rpms are @@ -201,7 +202,7 @@ def queue_message(cbtype, *args, **kws): # Queue the message for later. # It will only get sent after postCommit is called. messages = getattr(context, 'fedmsg_plugin_messages', []) - messages.append(dict(topic=topic, msg=body, modname='buildsys')) + messages.append(dict(topic=topic, msg=body)) context.fedmsg_plugin_messages = messages @@ -211,4 +212,17 @@ def queue_message(cbtype, *args, **kws): def send_messages(cbtype, *args, **kws): messages = getattr(context, 'fedmsg_plugin_messages', []) for message in messages: - fedmsg.publish(**message) + try: + msg = fedora_messaging.api.Message( + topic="buildsys.{}".format(message['topic']), + body=message['body'] + ) + fedora_messaging.api.publish(msg) + except fedora_messaging.exceptions.PublishReturned as e: + log.warning( + "Fedora Messaging broker rejected message %s: %s", msg.id, e + ) + except fedora_messaging.exceptions.ConnectionException as e: + log.warning("Error sending message %s: %s", msg.id, e) + except Exception: + log.exception("Un-expected error sending fedora-messaging message") From 59e30512ba0b74620fd2a3a4ed8ac29b2334e0c8 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 04 2019 09:37:24 +0000 Subject: [PATCH 2/4] Run flake8 on the file and re-order the imports Signed-off-by: Pierre-Yves Chibon --- diff --git a/fedmsg-koji-plugin.py b/fedmsg-koji-plugin.py index a833adc..5417567 100644 --- a/fedmsg-koji-plugin.py +++ b/fedmsg-koji-plugin.py @@ -6,6 +6,7 @@ # Mike Bonnet import logging +import re from koji.context import context from koji.plugin import callbacks @@ -14,9 +15,6 @@ from koji.plugin import ignore_error import fedora_messaging.api import fedora_messaging.exceptions import kojihub -import re - -import pprint MAX_KEY_LENGTH = 255 @@ -143,7 +141,7 @@ def get_message_body(topic, *args, **kws): @callback(*[ c for c in callbacks.keys() if c.startswith('post') and c not in [ - 'postImport', # This is kind of useless; also noisy. + 'postImport', # This is kind of useless; also noisy. # This one is special, and is called every time, so ignore it. # Added here https://pagure.io/koji/pull-request/148 'postCommit', @@ -188,12 +186,15 @@ def queue_message(cbtype, *args, **kws): # These fields are floating points which get json-encoded differently on # rhel and fedora. problem_fields = ['weight', 'start_ts', 'create_ts', 'completion_ts'] + def scrub(obj): if isinstance(obj, list): return [scrub(item) for item in obj] if isinstance(obj, dict): return dict([ - (k, scrub(v)) for k, v in obj.items() if k not in problem_fields + (k, scrub(v)) + for k, v in obj.items() + if k not in problem_fields ]) return obj @@ -211,6 +212,7 @@ def queue_message(cbtype, *args, **kws): @ignore_error def send_messages(cbtype, *args, **kws): messages = getattr(context, 'fedmsg_plugin_messages', []) + for message in messages: try: msg = fedora_messaging.api.Message( From d9deb16b75893937631f44f04ec995690a824c07 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 04 2019 09:44:52 +0000 Subject: [PATCH 3/4] Add a comment indicating where the upstream sources are Signed-off-by: Pierre-Yves Chibon --- diff --git a/fedmsg-koji-plugin.py b/fedmsg-koji-plugin.py index 5417567..b4e0d5d 100644 --- a/fedmsg-koji-plugin.py +++ b/fedmsg-koji-plugin.py @@ -1,5 +1,7 @@ -# Koji callback for sending notifications about events to the fedmsg messagebus -# Copyright (c) 2009-2012 Red Hat, Inc. +# Koji callback for sending notifications about events to the fedmsg message bus +# Copyright (c) 2009-2019 Red Hat, Inc. +# +# Source: https://pagure.io/koji-fedmsg-plugin/ # # Authors: # Ralph Bean From 86412572c3e1a69bc0765d976e50ad597121e267 Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Mar 04 2019 09:52:15 +0000 Subject: [PATCH 4/4] Add configuration file Signed-off-by: Aurélien Bompard --- diff --git a/config.toml.example b/config.toml.example new file mode 100644 index 0000000..eee7f09 --- /dev/null +++ b/config.toml.example @@ -0,0 +1,18 @@ +# A sample configuration for fedora-messaging. This file is in the TOML format. +# For complete details on all configuration options, see the documentation. + +amqp_url = "amqp://" + +publish_exchange = "amq.topic" + +# The topic_prefix configuration value will add a prefix to the topics of every sent message. +# This is used for migrating from fedmsg, and should not be used afterwards. +topic_prefix = "" + +[tls] +ca_cert = "/etc/pki/tls/certs/ca-bundle.crt" +keyfile = "/my/client/key.pem" +certfile = "/my/client/cert.pem" + +[client_properties] +app = "Koji"