forked from fedora-infra/bodhi
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consumers: replace Greenwave with ResultsDB and WaiverDB (fedora-infr…
…a#4224) This replaces the consumer that listens for Greenwave 'decision change' messages with consumers that listen for ResultsDB and WaiverDB "new result" / "new waiver" messages and update gating decisions if the message may cause a change. The goal here is to make it possible to remove the "decision change" message code from Greenwave entirely, because in order to publish those messages, Greenwave has to duplicate a lot of Bodhi's knowledge about what kinds of decisions to ask for. This being in Greenwave is really against the intended design of the system, and means whenever anything changes about what kinds of decision Bodhi might request, we need to change both Bodhi and the Greenwave "decision change" publishing code. Signed-off-by: Adam Williamson <awilliam@redhat.com>
- Loading branch information
Showing
9 changed files
with
769 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Copyright Red Hat and others. | ||
# | ||
# This file is part of Bodhi. | ||
# | ||
# 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 "resultsdb handler". | ||
This module is responsible for listening for messages from ResultsDB. | ||
If a message seems like it might be a result change for an update or | ||
build from an update, we re-check the gating decision for that update. | ||
""" | ||
|
||
import logging | ||
|
||
import fedora_messaging | ||
|
||
from bodhi.server.consumers.util import update_from_db_message | ||
from bodhi.server.models import TestGatingStatus | ||
from bodhi.server.util import transactional_session_maker | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class ResultsdbHandler: | ||
""" | ||
The Bodhi ResultsDB Handler. | ||
A fedora-messaging listener waiting for messages from resultsdb that may | ||
affect gating status for an update. | ||
""" | ||
|
||
def __init__(self): | ||
"""Initialize the handler.""" | ||
self.db_factory = transactional_session_maker() | ||
|
||
def __call__(self, message: fedora_messaging.api.Message): | ||
"""Handle messages arriving with the configured topic.""" | ||
msg = message.body | ||
if not msg: | ||
log.debug("Ignoring message without body.") | ||
return | ||
|
||
passed = msg.get("outcome") in ("PASSED", "INFO") | ||
|
||
data = msg.get("data") | ||
if not data: | ||
log.error(f"Couldn't find data dict in ResultsDB message {message.id}") | ||
return | ||
|
||
with self.db_factory(): | ||
# find the update | ||
update = update_from_db_message(message.id, msg["data"]) | ||
if not update: | ||
# update_from_db_message will already have logged why | ||
return | ||
# update the gating status if there's a chance it changed | ||
status = update.test_gating_status | ||
if ( | ||
(passed and status == TestGatingStatus.passed) | ||
or (not passed and status == TestGatingStatus.failed) | ||
): | ||
log.debug("Not updating test_gating_status as no chance of a change") | ||
return | ||
log.info(f"Updating the test_gating_status for: {update.alias}") | ||
update.update_test_gating_status() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Copyright Red Hat and others. | ||
# | ||
# This file is part of Bodhi. | ||
# | ||
# 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. | ||
"""Utility functions for message consumers.""" | ||
|
||
import logging | ||
|
||
from bodhi.server.models import Build, Update | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
def update_from_db_message(msgid: str, itemdict: dict): | ||
"""Find and return the relevant Bodhi update for a waiverdb or | ||
resultsdb fedora_messaging message. Used by the resultsdb and | ||
waiverdb consumers. | ||
Args: | ||
msgid: the message ID (for logging purposes) | ||
itemdict: the relevant dict from the message. 'subject' dict | ||
for a waiverdb message, 'item' dict for resultsdb. | ||
Returns: | ||
bodhi.server.models.Update or None: the relevant update, if | ||
found. | ||
""" | ||
itemtype = itemdict.get("type") | ||
if not itemtype: | ||
log.error(f"Couldn't find item type in message {msgid}") | ||
return None | ||
if itemtype not in ("koji_build", "bodhi_update"): | ||
log.debug(f"Irrelevant item type {itemtype}") | ||
return None | ||
|
||
# find the update | ||
if itemtype == "bodhi_update": | ||
updateid = itemdict.get("item") | ||
if not updateid: | ||
log.error(f"Couldn't find update ID in message {msgid}") | ||
return None | ||
update = Update.get(updateid) | ||
if not update: | ||
log.error(f"Couldn't find update {updateid} in DB") | ||
return None | ||
else: | ||
nvr = itemdict.get("nvr", itemdict.get("item")) | ||
if not nvr: | ||
log.error(f"Couldn't find nvr in message {msgid}") | ||
return None | ||
build = Build.get(nvr) | ||
if not build: | ||
log.error(f"Couldn't find build {nvr} in DB") | ||
return None | ||
update = build.update | ||
|
||
return update |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Copyright Red Hat and others. | ||
# | ||
# This file is part of Bodhi. | ||
# | ||
# 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 "waiverdb handler". | ||
This module is responsible for listening for 'new waiver' messages from | ||
WaiverDB, and re-checking the gating decision for the relevant update. | ||
""" | ||
|
||
import logging | ||
|
||
import fedora_messaging | ||
|
||
from bodhi.server.consumers.util import update_from_db_message | ||
from bodhi.server.models import TestGatingStatus | ||
from bodhi.server.util import transactional_session_maker | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class WaiverdbHandler: | ||
""" | ||
The Bodhi WaiverDB Handler. | ||
A fedora-messaging listener waiting for messages from WaiverDB and | ||
updating gating status of the relevant update. | ||
""" | ||
|
||
def __init__(self): | ||
"""Initialize the handler.""" | ||
self.db_factory = transactional_session_maker() | ||
|
||
def __call__(self, message: fedora_messaging.api.Message): | ||
"""Handle messages arriving with the configured topic.""" | ||
msg = message.body | ||
if not msg: | ||
log.debug("Ignoring message without body.") | ||
return | ||
|
||
subject = msg.get("subject") | ||
if subject is None: | ||
log.error(f"Couldn't find subject in WaiverDB message {message.id}") | ||
return | ||
|
||
with self.db_factory(): | ||
# find the update | ||
update = update_from_db_message(message.id, subject) | ||
# update the gating status unless it's already "passed", a | ||
# waiver can't change it from passed to anything else | ||
if update and update.test_gating_status != TestGatingStatus.passed: | ||
log.info(f"Updating the test_gating_status for: {update.alias}") | ||
update.update_test_gating_status() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.