Skip to content

Commit

Permalink
Add SignedHandler which marked builds as signed once they get tagged …
Browse files Browse the repository at this point in the history
…in koji

Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com>
  • Loading branch information
puiterwijk committed Oct 7, 2016
1 parent f915aaa commit b66dafb
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
88 changes: 88 additions & 0 deletions bodhi/server/consumers/signed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
The "signed handler".
This module is responsible for marking builds as "signed" when they get moved
from the pending-signing to pending-updates-testing tag by RoboSignatory.
"""

import pprint

import fedmsg.consumers

from pyramid.paster import get_appsettings
from sqlalchemy import engine_from_config

from bodhi.server.util import transactional_session_maker
from bodhi.server.models import Base, Build, Release

import logging
log = logging.getLogger('bodhi')


class SignedHandler(fedmsg.consumers.FedmsgConsumer):
"""The Bodhi Signed Handler.
A fedmsg listener waiting for messages from koji about builds being tagged.
"""
config_key = 'signed_handler'

def __init__(self, hub, db_factory=None, *args, **kwargs):
if not db_factory:
config_uri = '/etc/bodhi/production.ini'
self.settings = get_appsettings(config_uri)
engine = engine_from_config(self.settings, 'sqlalchemy.')
Base.metadata.create_all(engine)
self.db_factory = transactional_session_maker(engine)
else:
self.db_factory = db_factory

prefix = hub.config.get('topic_prefix')
env = hub.config.get('environment')
self.topic = [
prefix + '.' + env + '.buildsys.tag'
]

log.info('Bodhi signed handler listening on:\n'
'%s' % pprint.pformat(self.topic))

def consume(self, message):
msg = message['body']['msg']
topic = message['topic']

log.info("Signed Handler handling %s, %s" % (alias, topic))

build_nvr = '%(name)s-%(version)s-%(release)s' % msg
tag = msg['tag']

log.info("%s tagged into %s" % (build_nvr, tag))

with self.db_factory() as session:
build = Build.get(build_nvr, session)
if not build:
log.info("Build was not submitted, skipping")
return

if build.release.pending_testing_tag != tag:
log.info("Tag is not pending_testing tag, skipping")
return

# This build was moved into the pending_testing tag for the applicable release, which
# is done by RoboSignatory to indicate that the build has been correctly signed and
# written out. Mark it as such.
log.info("Build has been signed, marking")
build.signed = True
log.info("Build %s has been marked as signed" % build_nvr)
3 changes: 3 additions & 0 deletions fedmsg.d/signed_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
config = dict(
signed_handler=True,
)
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
[moksha.consumer]
masher = bodhi.server.consumers.masher:Masher
updates = bodhi.server.consumers.updates:UpdatesHandler
signed = bodhi.server.consumers.signed:SignedHandler
""",
paster_plugins=['pyramid'],
)

0 comments on commit b66dafb

Please sign in to comment.