Skip to content

Commit

Permalink
Do not mute KeyErrors in chm subscriber (#3007)
Browse files Browse the repository at this point in the history
  • Loading branch information
romcheg authored and mkurek committed Apr 6, 2017
1 parent dccd426 commit 4c7a1a7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/ralph/operations/changemanagement/exceptions.py
@@ -0,0 +1,2 @@
class IgnoreOperation(Exception):
message = 'Ignoring the opertaion.'
3 changes: 2 additions & 1 deletion src/ralph/operations/changemanagement/jira.py
Expand Up @@ -4,6 +4,7 @@
from dateutil.parser import parse as parse_datetime
from django.conf import settings

from ralph.operations.changemanagement.exceptions import IgnoreOperation
from ralph.operations.models import OperationStatus


Expand Down Expand Up @@ -42,7 +43,7 @@ def get_operation_status(event_data):
'Received an operation with unexpected '
'status: {}. Please check the settings.'.format(status_str)
)
raise
raise IgnoreOperation()


def get_operation_name(event_data):
Expand Down
6 changes: 3 additions & 3 deletions src/ralph/operations/changemanagement/subscribtions.py
Expand Up @@ -7,6 +7,7 @@
from django.db import transaction

from ralph.assets.models import BaseObject
from ralph.operations.changemanagement.exceptions import IgnoreOperation
from ralph.operations.models import Operation, OperationType


Expand Down Expand Up @@ -107,9 +108,8 @@ def receive_chm_event(event_data):
if base_object_loader is not None else None
)
)
except KeyError:
# Silence already logged errors.
pass
except IgnoreOperation as e:
logger.warning(e.message)
except Exception as e:
logger.exception(
'Encountered an unexpected failure while handling a change '
Expand Down
10 changes: 10 additions & 0 deletions src/ralph/operations/tests/test_event_receiver.py
@@ -1,6 +1,8 @@
import json
from os import path
from unittest import mock

from ralph.operations.changemanagement.exceptions import IgnoreOperation
from ralph.operations.changemanagement.subscribtions import receive_chm_event
from ralph.operations.models import Operation, OperationStatus
from ralph.tests import RalphTestCase
Expand Down Expand Up @@ -49,6 +51,14 @@ def test_no_record_created_unknown_operation_type(self):
with self.assertRaises(Operation.DoesNotExist):
Operation.objects.get(ticket_id='SOMEPROJ-42')

@mock.patch('ralph.operations.changemanagement.jira.get_ticket_id',
side_effect=IgnoreOperation())
def test_no_record_created_when_IgnoreOperation_is_rised(self, m_get):
receive_chm_event(self.jira_event)

with self.assertRaises(Operation.DoesNotExist):
Operation.objects.get(ticket_id='SOMEPROJ-42')

def test_no_record_created_unknown_operation_status(self):
self.jira_event['issue']['fields']['status']['name'] = 'DEADBEEF'

Expand Down
5 changes: 3 additions & 2 deletions src/ralph/operations/tests/test_jira_processor.py
Expand Up @@ -3,6 +3,7 @@
from os import path

from ralph.operations.changemanagement import jira
from ralph.operations.changemanagement.exceptions import IgnoreOperation
from ralph.operations.models import OperationStatus
from ralph.tests import RalphTestCase

Expand Down Expand Up @@ -74,8 +75,8 @@ def test_get_operation_status(self):
jira.get_operation_status(self.jira_event)
)

def test_get_operation_status_bad_status_raises_KeyError(self):
def test_get_operation_status_bad_status_raises_IgnoreOperation(self):
self.jira_event['issue']['fields']['status']['name'] = 'DEADBEEF'

with self.assertRaises(KeyError):
with self.assertRaises(IgnoreOperation):
jira.get_operation_status(self.jira_event)

0 comments on commit 4c7a1a7

Please sign in to comment.