From e4653eab6d7007a24c193bc3ae45ec57afd2d1b9 Mon Sep 17 00:00:00 2001 From: Clement Verna Date: Jan 23 2019 12:52:55 +0000 Subject: Drop support for fedmsg and replace by fedora-messaging Signed-off-by: Clement Verna --- diff --git a/Dockerfile b/Dockerfile index d00f5db..8fce400 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ LABEL maintainer "Clément Verna " EXPOSE 8080 -RUN dnf -y install python3-aiohttp python3-werkzeug python3-requests python3-sqlalchemy python3-fedmsg +RUN dnf -y install python3-aiohttp python3-werkzeug python3-requests python3-sqlalchemy python3-fedora-messaging USER 1001 ENV MDAPI_CONFIG=/etc/mdapi/mdapi.cfg diff --git a/fedmsg.d/mdapi.py b/fedmsg.d/mdapi.py deleted file mode 100644 index b002ff8..0000000 --- a/fedmsg.d/mdapi.py +++ /dev/null @@ -1,19 +0,0 @@ -""" This is an example mdapi configuration for fedmsg. -By convention, it is normally installed as ``/etc/fedmsg.d/mdapi.py`` - -For Fedora Infrastructure this file is not needed as we use dynamic -fedmsg endpoints. -""" - -import socket - - -hostname = socket.gethostname().split('.')[0] - -config = dict( - endpoints={ - "mdapi.%s" % hostname: [ - "tcp://127.0.0.1:3005", - ], - }, -) diff --git a/mdapi-get_repo_md b/mdapi-get_repo_md index 997035f..bfae17f 100755 --- a/mdapi-get_repo_md +++ b/mdapi-get_repo_md @@ -44,11 +44,14 @@ import tempfile import time import hashlib import xml.etree.ElementTree as ET +import sys + -import fedmsg import requests from sqlalchemy import text +from fedora_messaging.api import Message, publish +from fedora_messaging.exceptions import PublishReturned, ConnectionException import mdapi.lib as mdapilib import mdapi.file_lock as file_lock @@ -69,11 +72,6 @@ repomd_xml_namespace = { padding = 22 -fedmsg.init( - active=True, - cert_prefix='mdapi', -) - # Some queries to help us sort out what is in the repos relations_query = """ @@ -296,11 +294,11 @@ def compare_dbs(name, db1, db2, cache1, cache2): def publish_changes(name, packages, repomd_url): - print('%s Publishing differences to fedmsg:' % (name.ljust(padding))) + print('%s Publishing differences to fedora messaging:' % (name.ljust(padding))) change = bool(packages) if not change: - print('%s No real changes. Skipping fedmsg.' % (name.ljust(padding))) + print('%s No real changes. Skipping fedora messaging.' % (name.ljust(padding))) return # Just publish the suffix of the URL. The prefix is dl.fedoraproject.org @@ -311,15 +309,22 @@ def publish_changes(name, packages, repomd_url): url = '/'.join(repomd_url.split('/')[4:]) print("%s url %s" % (name.ljust(padding), url)) - fedmsg.publish( - modname='mdapi', - topic='repo.update', - msg=dict( - name=name, - packages=packages, - url=url, + try: + msg = Message( + topic="mdapi.repo.update.v1", + body=dict( + name=name, + packages=packages, + url=url, + ) ) - ) + publish(msg) + except PublishReturned as e: + print( + f"Fedora Messaging broker rejected message {msg.id}: {e}", file=sys.stderr + ) + except ConnectionException as e: + print(f"Error sending message {msg.id}: {e}", file=sys.stderr) def install_db(name, src, dest): diff --git a/requirements.txt b/requirements.txt index 1805848..2c713dd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ aiohttp -fedmsg[all] +fedora_messaging # this is a requirement of aiohttp but better safe than sorry -multidict +multidict requests sqlalchemy werkzeug