#1595 Fix the handling of ignored messages
Merged 4 years ago by mprahl. Opened 4 years ago by mprahl.

@@ -128,11 +128,14 @@ 

              super(MBSConsumer, self).validate(message)

  

      def validate_event(self, event):

+         if event is None:

+             raise IgnoreMessage("Ignoring the message since it is null")

          # task_id is required for koji_build_change event

-         if event["event"] == "koji_build_change" and event["task_id"] is None:

+         if event["event"] == events.KOJI_BUILD_CHANGE and event["task_id"] is None:

              raise IgnoreMessage(

-                 "Ignore koji_build_change event from message {}, which has a null task_id".format(

-                     event["msg_id"])

+                 "Ignoring {} event from message {}, which has a null task_id".format(

+                     events.KOJI_BUILD_CHANGE, event["msg_id"]

+                 )

              )

  

      def consume(self, message):
@@ -180,10 +183,7 @@ 

      def get_abstracted_event_info(message):

          parser = default_messaging_backend.get("parser")

          if parser:

-             try:

-                 return parser.parse(message)

-             except IgnoreMessage:

-                 pass

+             return parser.parse(message)

          else:

              raise ValueError("{0} backend does not define a message parser".format(conf.messaging))

  

@@ -3,7 +3,6 @@ 

  from __future__ import absolute_import

  import re

  

- from module_build_service.common import log

  from module_build_service.common.errors import IgnoreMessage

  from module_build_service.scheduler import events

  
@@ -34,6 +33,7 @@ 

          :return: a mapping representing the corresponding event.

              If the topic isn't recognized, None is returned.

          :rtype: dict or None

+         :raises IgnoreMessage: if the message should be ignored

          """

  

          if "body" in msg:
@@ -59,22 +59,20 @@ 

  

              # If there isn't a msg dict in msg then this message can be skipped

              if not msg_inner_msg:

-                 log.debug(

-                     "Skipping message without any content with the " 'topic "{0}"'.format(topic))

-                 return None

+                 raise IgnoreMessage(

+                     "Ignoring message without any content with the " 'topic "{0}"'.format(topic))

  

              # Ignore all messages from the secondary koji instances.

              if category == "buildsys":

                  instance = msg_inner_msg.get("instance", "primary")

                  if instance != "primary":

-                     log.debug("Ignoring message from %r koji hub." % instance)

-                     return

+                     raise IgnoreMessage("Ignoring message from %r koji hub." % instance)

  

                  if object == "build" and subobject == "state" and event == "change":

                      task_id = msg_inner_msg.get("task_id")

                      if task_id is None:

                          raise IgnoreMessage(

-                             "Ignore message {}, with has a null task_id.".format(msg_id))

+                             "Ignoring message {}, with has a null task_id.".format(msg_id))

                      return {

                          "msg_id": msg_id,

                          "event": events.KOJI_BUILD_CHANGE,

@@ -3,7 +3,9 @@ 

  from __future__ import absolute_import

  

  from mock import patch, MagicMock

+ import pytest

  

+ from module_build_service.common.errors import IgnoreMessage

  from module_build_service.scheduler import events

  from module_build_service.scheduler.consumer import MBSConsumer

  
@@ -102,3 +104,9 @@ 

          consumer.get_abstracted_event_info.return_value = event

          consumer.consume({})

          assert process_message.call_count == 0

+ 

+     def test_validate_event_none_msg(self):

+         hub = MagicMock(config={})

+         consumer = MBSConsumer(hub)

+         with pytest.raises(IgnoreMessage):

+             consumer.validate_event(None)

file modified
+1 -2
@@ -2786,7 +2786,6 @@ 

          self.client = app.test_client()

          init_data(2)

          self.module_id = 2

-         self.component_id = 1

          self.module_build = ModuleBuild.get_by_id(db_session, self.module_id)

          self.module_build.log_message(db_session, "Build-1 msg")

          self.module_build.log_message(db_session, "Build-2 msg")
@@ -2806,7 +2805,7 @@ 

  

      def test_view_log_messages_for_component_builds(self):

          url = "/module-build-service/1/component-builds/{component_id}/messages".format(

-             component_id=self.component_id)

+             component_id=self.component_build.id)

          res = self.client.get(url)

  

          json_res = str(res.data)