Log the error to ticket on scm_request_processor

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ý <mkonecny@redhat.com>
This commit is contained in:
Michal Konečný 2022-07-22 11:54:07 +02:00
parent 19f48a0b52
commit c45845cbde
2 changed files with 66 additions and 1 deletions

View file

@ -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")

View file

@ -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):
"""