From a80b25fcce1cd2d40052b20466df36b49d0b161e Mon Sep 17 00:00:00 2001
From: Isham Ibrahim <Isham.Ibrahim@rackspace.com>
Date: Tue, 30 May 2017 15:56:57 +0530
Subject: [PATCH] VIRT-2996: Handling malformed notifications sent by Nova to
 stacktach. Before:- Stacktack threw an exception and was unable to log the
 message. It later tries to process the same erroneous notification
 repeatedly. After: Stacktach catched the malformed notification and logs the
 message. It later acknowledges RabbiMQ so that the message is removed from
 queue.

Change-Id: I7a33816a7ce4660513b047a7e54c3223a63c8cb3
---
 worker/worker.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/worker/worker.py b/worker/worker.py
index 73079f5..ada6bef 100644
--- a/worker/worker.py
+++ b/worker/worker.py
@@ -143,9 +143,14 @@ class Consumer(kombu.mixins.ConsumerMixin):
     def on_nova(self, body, message):
         try:
             self._process(message)
+        except ValueError, e:
+            _get_child_logger().error("Error: %s\nMalformed message body found : \n%s" %
+                                      (e, str(message.body)))
+            # Mark message as read to avoid re-reading the malformed message.
+            message.ack()
         except Exception, e:
-            _get_child_logger().debug("Problem: %s\nFailed message body:\n%s" %
-                      (e, json.loads(str(message.body))))
+            _get_child_logger().error("Problem: %s\nFailed message body:\n%s" %
+                      (e, str(message.body)))
             raise
 
     def _shutdown(self, signal, stackframe = False):