Merge "[MON] Fixes notifier bug during alarm triggering" v4.0 BUILD_v4.0.1_1 BUILD_v4.0.1_2
authorlavado <glavado@whitestack.com>
Fri, 6 Jul 2018 19:14:23 +0000 (21:14 +0200)
committerGerrit Code Review <root@osm.etsi.org>
Fri, 6 Jul 2018 19:14:23 +0000 (21:14 +0200)
1  2 
osm_mon/plugins/OpenStack/Aodh/notifier.py
osm_mon/test/OpenStack/unit/test_notifier.py

@@@ -72,11 -72,11 +72,11 @@@ class NotifierHandler(BaseHTTPRequestHa
              post_data = post_data.decode()
          except AttributeError:
              pass
-         log.info("This alarm was triggered: %s", json.dumps(post_data))
+         log.info("This alarm was triggered: %s", post_data)
  
          # Send alarm notification to message bus
          try:
-             self.notify_alarm(json.dumps(post_data))
+             self.notify_alarm(json.loads(post_data))
          except Exception:
              log.exception("Error notifying alarm")
  
              sev=values['severity'],
              date=a_date,
              state=values['current'])
 -        producer.notify_alarm(
 +        producer.publish_alarm_response(
              'notify_alarm', resp_message)
          log.info("Sent alarm notification: %s", resp_message)
  
@@@ -52,7 -52,7 +52,7 @@@ class Response(object)
  
  class RFile():
      def read(self, content_length):
-         return post_data
+         return json.dumps(post_data, sort_keys=True)
  
  
  class MockNotifierHandler(NotifierHandler):
@@@ -98,9 -98,9 +98,9 @@@ class TestNotifier(unittest.TestCase)
          self.handler.do_POST()
  
          set_head.assert_called_once()
-         notify.assert_called_with(json.dumps(post_data))
+         notify.assert_called_with(post_data)
  
 -    @mock.patch.object(KafkaProducer, "notify_alarm")
 +    @mock.patch.object(KafkaProducer, "publish_alarm_response")
      @mock.patch.object(DatabaseManager, "get_alarm")
      def test_notify_alarm_valid_alarm(
              self, get_alarm, notify):
  
          notify.assert_called_with("notify_alarm", mock.ANY)
  
 -    @mock.patch.object(KafkaProducer, "notify_alarm")
 +    @mock.patch.object(KafkaProducer, "publish_alarm_response")
      @mock.patch.object(DatabaseManager, "get_alarm")
      def test_notify_alarm_invalid_alarm(
              self, get_alarm, notify):