From c45845cbdefe77a06b892a535063463b594861b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kone=C4=8Dn=C3=BD?= Date: Fri, 22 Jul 2022 11:54:07 +0200 Subject: [PATCH] Log the error to ticket on scm_request_processor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If any error happens during processing SCM requests log it as comment on the ticket. This will prevent the spamming loop from toddler and we will know that there is some error happening. Signed-off-by: Michal Konečný --- tests/plugins/test_scm_request_processor.py | 55 +++++++++++++++++++++ toddlers/plugins/scm_request_processor.py | 12 ++++- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/tests/plugins/test_scm_request_processor.py b/tests/plugins/test_scm_request_processor.py index 2d905d0..536e1fa 100644 --- a/tests/plugins/test_scm_request_processor.py +++ b/tests/plugins/test_scm_request_processor.py @@ -129,6 +129,61 @@ class TestProcess: pagure_user ) + @patch("toddlers.utils.pdc.set_pdc") + @patch("toddlers.utils.pagure.set_pagure") + @patch("toddlers.utils.fedora_account.set_fasjson") + @patch("toddlers.utils.bugzilla_system.set_bz") + def test_process_exception( + self, mock_bugzilla, mock_fasjson, mock_pagure, mock_pdc, toddler + ): + """ + Assert that message toddler will be initialized correctly, if message passes + initial processing. + """ + msg = IssueNewV1() + issue = {"id": 100, "status": "Open"} + msg.body = { + "project": {"fullname": scm_request_processor.PROJECT_NAMESPACE}, + "issue": issue, + "agent": "agent", + } + config = { + "branch_slas": {}, + "monitoring_choices": [], + "pagure_namespace_to_component": {}, + "pagure_namespace_to_product": {}, + "temp_dir": "", + "dist_git_url": "https://src.fedoraproject.org", + "dist_git_token": "Private API Key", + } + + mock_pagure_io = Mock() + mock_pagure.return_value = mock_pagure_io + + with patch( + "toddlers.plugins.scm_request_processor.SCMRequestProcessor.process_ticket" + ) as mock_process_ticket: + mock_process_ticket.side_effect = Exception("Exception") + toddler.process(config, msg) + + mock_process_ticket.assert_called_with(issue) + + mock_pdc.assert_called_with(config) + mock_pagure.assert_has_calls( + [ + call(config), + call( + { + "pagure_url": "https://src.fedoraproject.org", + "pagure_api_key": "Private API Key", + } + ), + ] + ) + mock_fasjson.assert_called_with(config) + mock_bugzilla.assert_called_with(config) + mock_pagure_io.add_comment_to_issue.assert_called_once() + @patch("toddlers.utils.pdc.set_pdc") @patch("toddlers.utils.pagure.set_pagure") @patch("toddlers.utils.fedora_account.set_fasjson") diff --git a/toddlers/plugins/scm_request_processor.py b/toddlers/plugins/scm_request_processor.py index 09cdec6..3e91dae 100644 --- a/toddlers/plugins/scm_request_processor.py +++ b/toddlers/plugins/scm_request_processor.py @@ -13,6 +13,7 @@ import logging import re import sys from tempfile import TemporaryDirectory +import traceback from typing import Optional import arrow @@ -192,7 +193,16 @@ class SCMRequestProcessor(ToddlerBase): _log.info("Setting up connection to Bugzilla") bugzilla_system.set_bz(config) - self.process_ticket(issue) + try: + self.process_ticket(issue) + except BaseException: + self.pagure_io.add_comment_to_issue( + issue["id"], + namespace=PROJECT_NAMESPACE, + comment="Error happened during processing:\n{0}".format( + traceback.print_exc + ), + ) def process_ticket(self, issue: dict): """