Skip to content

Commit

Permalink
Use the new koschei-messages schema package
Browse files Browse the repository at this point in the history
This change will make use of the new schema package, which will let FMN
produce notifications for users.

Ref: fedora-infra/fmn#915

Signed-off-by: Aurélien Bompard <[email protected]>
  • Loading branch information
abompard committed Jun 5, 2023
1 parent 69d1fcd commit 91dfd5a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 23 deletions.
5 changes: 3 additions & 2 deletions .travis/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
FROM registry.fedoraproject.org/fedora:33
FROM registry.fedoraproject.org/fedora:35

WORKDIR /build

RUN echo -e "deltarpm=0\ninstall_weak_deps=0\ntsflags=nodocs" >> /etc/dnf/dnf.conf
RUN dnf -y update
RUN dnf -y install curl findutils postgresql-server python3-coverage python3-devel python3-dogpile-cache python3-fedora-messaging python3-flask python3-flask-sqlalchemy python3-flask-wtf python3-hawkey python3-humanize python3-jinja2 python3-markupsafe python3-koji python3-librepo python3-mock python3-nose python3-psycopg2 python3-requests python3-rpm python3-setuptools python3-sqlalchemy python3-vcrpy python3-wtforms systemd
RUN dnf -y install curl findutils postgresql-server python3-coverage python3-devel python3-dogpile-cache python3-fedora-messaging python3-flask python3-flask-sqlalchemy python3-flask-wtf python3-hawkey python3-humanize python3-jinja2 python3-markupsafe python3-koji python3-librepo python3-mock python3-nose python3-psycopg2 python3-requests python3-rpm python3-setuptools python3-sqlalchemy python3-vcrpy python3-wtforms systemd python3-pip
RUN pip-3 install koschei-messages

RUN useradd koschei

Expand Down
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ RUN : \
&& useradd koschei \
&& :

# Install koschei-messages from PyPI as it is not packaged yet
RUN : \
&& dnf -y install python3-pip \
&& pip-3 install koschei-messages==1.0.1 \
&& :

COPY bin/ /usr/bin/
COPY ./ /usr/share/koschei/

Expand Down
24 changes: 12 additions & 12 deletions koschei/plugins/fedmsg_plugin/backend/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# Author: Mikolaj Izdebski <[email protected]>

import fedora_messaging.api as fedmsg
from koschei_messages.package import PackageStateChange
from koschei_messages.collection import CollectionStateChange

from koschei.config import get_config
from koschei.plugin import listen_event
Expand All @@ -26,10 +28,6 @@
def publish_fedmsg(session, message):
if not get_config('fedmsg-publisher.enabled', False):
return
message = fedmsg.Message(
topic='{modname}.{topic}'.format(**message),
body=message['msg'],
)
session.log.info('Publishing fedmsg:\n' + str(message))
fedmsg.publish(message)

Expand All @@ -39,10 +37,11 @@ def emit_package_state_update(session, package, prev_state, new_state):
if prev_state == new_state:
return
group_names = [group.full_name for group in package.groups]
message = dict(
topic='package.state.change',
modname=get_config('fedmsg-publisher.modname'),
msg=dict(
message = PackageStateChange(
topic='{modname}.package.state.change'.format(
modname=get_config('fedmsg-publisher.modname')
),
body=dict(
name=package.name,
old=prev_state,
new=new_state,
Expand All @@ -60,10 +59,11 @@ def emit_package_state_update(session, package, prev_state, new_state):
def emit_collection_state_update(session, collection, prev_state, new_state):
if prev_state == new_state:
return
message = dict(
topic='collection.state.change',
modname=get_config('fedmsg-publisher.modname'),
msg=dict(
message = CollectionStateChange(
topic='{modname}.collection.state.change'.format(
modname=get_config('fedmsg-publisher.modname')
),
body=dict(
old=prev_state,
new=new_state,
koji_instance=get_config('fedmsg.instance'),
Expand Down
11 changes: 6 additions & 5 deletions test/fedmsg_publisher_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

from mock import patch
from test.common import DBTest
from fedora_messaging.api import Message
from koschei_messages.package import PackageStateChange
from koschei_messages.collection import CollectionStateChange
from koschei import plugin
from koschei.models import PackageGroup, PackageGroupRelation

Expand All @@ -36,7 +37,7 @@ def test_event(self):
plugin.dispatch_event('package_state_change', self.session, package=package,
prev_state='failed', new_state='ok')
publish.assert_called_once_with(
Message(
PackageStateChange(
topic='koschei.package.state.change',
body={'name': 'rnv',
'old': 'failed',
Expand All @@ -52,7 +53,7 @@ def test_event(self):
plugin.dispatch_event('collection_state_change', self.session, collection=package.collection,
prev_state='unresolved', new_state='ok')
publish.assert_called_once_with(
Message(
CollectionStateChange(
topic='koschei.collection.state.change',
body={'old': 'unresolved',
'new': 'ok',
Expand All @@ -71,8 +72,8 @@ def test_same_state(self):
with patch('fedora_messaging.api.publish') as publish:
plugin.dispatch_event('package_state_change', self.session, package=package,
prev_state='ok', new_state='ok')
self.assertFalse(publish.called)
publish.assert_not_called()
publish.reset_mock()
plugin.dispatch_event('collection_state_change', self.session, collection=package.collection,
prev_state='ok', new_state='ok')
self.assertFalse(publish.called)
publish.assert_not_called()
9 changes: 5 additions & 4 deletions test/resolver_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@

import hawkey
import koji
from fedora_messaging.api import Message
from contextlib import contextmanager
from mock import Mock, patch
from koschei_messages.collection import CollectionStateChange
from koschei_messages.package import PackageStateChange

from test.common import DBTest, RepoCacheMock, rpmvercmp
from koschei import plugin
Expand Down Expand Up @@ -107,7 +108,7 @@ def prepare_foo_build(self, repo_id=123, version='4'):

def assert_collection_fedmsg_emitted(self, fedmsg_mock, prev_state, new_state):
fedmsg_mock.assert_called_once_with(
Message(
CollectionStateChange(
topic='koschei.collection.state.change',
body={'old': prev_state,
'new': new_state,
Expand Down Expand Up @@ -316,7 +317,7 @@ def test_result_history(self):
self.assertFalse(result.resolved)
self.assertIn('nonexistent', ''.join(map(str, result.problems)))
fedmsg_mock.assert_called_once_with(
Message(
PackageStateChange(
topic='koschei.package.state.change',
body={'koji_instance': 'primary',
'repo': 'f25',
Expand Down Expand Up @@ -359,7 +360,7 @@ def test_result_history(self):
self.assertTrue(result.resolved)
self.assertEqual([], result.problems)
fedmsg_mock.assert_called_once_with(
Message(
PackageStateChange(
topic='koschei.package.state.change',
body={'koji_instance': 'primary',
'repo': 'f25',
Expand Down

0 comments on commit 91dfd5a

Please sign in to comment.