From 3515078cad61c9ecf87d4641c48e56f41a8f36e0 Mon Sep 17 00:00:00 2001 From: Andrew Melton Date: Thu, 24 Oct 2013 13:38:04 -0400 Subject: [PATCH] Using new exist object in callback --- tests/unit/test_glance_verifier.py | 5 +++++ tests/unit/test_nova_verifier.py | 4 ++++ verifier/base_verifier.py | 14 +++++++++----- verifier/glance_verifier.py | 7 ++++++- verifier/nova_verifier.py | 7 ++++++- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/tests/unit/test_glance_verifier.py b/tests/unit/test_glance_verifier.py index 0bc4e1f..99e3e14 100644 --- a/tests/unit/test_glance_verifier.py +++ b/tests/unit/test_glance_verifier.py @@ -53,6 +53,7 @@ class GlanceVerifierTestCase(StacktachBaseTestCase): models.ImageDeletes.objects = self.mox.CreateMockAnything() self.mox.StubOutWithMock(models, 'ImageExists', use_mock_anything=True) + models.ImageExists.objects = self.mox.CreateMockAnything() def tearDown(self): self.mox.UnsetStubs() @@ -493,6 +494,7 @@ class GlanceVerifierTestCase(StacktachBaseTestCase): connection = self.mox.CreateMockAnything() exchange = self.mox.CreateMockAnything() exist = self.mox.CreateMockAnything() + exist.id = 1 exist.raw = self.mox.CreateMockAnything() exist_dict = [ 'monitor.info', @@ -507,6 +509,7 @@ class GlanceVerifierTestCase(StacktachBaseTestCase): uuid.uuid4().AndReturn('some_other_uuid') self.mox.StubOutWithMock(kombu.pools, 'producers') self.mox.StubOutWithMock(kombu.common, 'maybe_declare') + models.ImageExists.objects.get(id=exist.id).AndReturn(exist) routing_keys = ['notifications.info', 'monitor.info'] for key in routing_keys: producer = self.mox.CreateMockAnything() @@ -530,6 +533,7 @@ class GlanceVerifierTestCase(StacktachBaseTestCase): connection = self.mox.CreateMockAnything() exchange = self.mox.CreateMockAnything() exist = self.mox.CreateMockAnything() + exist.id = 1 exist.raw = self.mox.CreateMockAnything() exist_dict = [ 'monitor.info', @@ -542,6 +546,7 @@ class GlanceVerifierTestCase(StacktachBaseTestCase): exist.raw.json = exist_str self.mox.StubOutWithMock(kombu.pools, 'producers') self.mox.StubOutWithMock(kombu.common, 'maybe_declare') + models.ImageExists.objects.get(id=exist.id).AndReturn(exist) producer = self.mox.CreateMockAnything() producer.channel = self.mox.CreateMockAnything() kombu.pools.producers[connection].AndReturn(producer) diff --git a/tests/unit/test_nova_verifier.py b/tests/unit/test_nova_verifier.py index d1a84ff..629f52f 100644 --- a/tests/unit/test_nova_verifier.py +++ b/tests/unit/test_nova_verifier.py @@ -1083,6 +1083,7 @@ class NovaVerifierTestCase(StacktachBaseTestCase): connection = self.mox.CreateMockAnything() exchange = self.mox.CreateMockAnything() exist = self.mox.CreateMockAnything() + exist.id = 1 exist.raw = self.mox.CreateMockAnything() exist_dict = [ 'monitor.info', @@ -1097,6 +1098,7 @@ class NovaVerifierTestCase(StacktachBaseTestCase): uuid.uuid4().AndReturn('some_other_uuid') self.mox.StubOutWithMock(kombu.pools, 'producers') self.mox.StubOutWithMock(kombu.common, 'maybe_declare') + models.InstanceExists.objects.get(id=exist.id).AndReturn(exist) routing_keys = ['notifications.info', 'monitor.info'] for key in routing_keys: producer = self.mox.CreateMockAnything() @@ -1120,6 +1122,7 @@ class NovaVerifierTestCase(StacktachBaseTestCase): connection = self.mox.CreateMockAnything() exchange = self.mox.CreateMockAnything() exist = self.mox.CreateMockAnything() + exist.id = 1 exist.raw = self.mox.CreateMockAnything() exist_dict = [ 'monitor.info', @@ -1132,6 +1135,7 @@ class NovaVerifierTestCase(StacktachBaseTestCase): exist.raw.json = exist_str self.mox.StubOutWithMock(kombu.pools, 'producers') self.mox.StubOutWithMock(kombu.common, 'maybe_declare') + models.InstanceExists.objects.get(id=exist.id).AndReturn(exist) producer = self.mox.CreateMockAnything() producer.channel = self.mox.CreateMockAnything() kombu.pools.producers[connection].AndReturn(producer) diff --git a/verifier/base_verifier.py b/verifier/base_verifier.py index cdded08..021736b 100644 --- a/verifier/base_verifier.py +++ b/verifier/base_verifier.py @@ -167,11 +167,15 @@ class Verifier(object): self.config.userid(), self.config.password(), "librabbitmq", self.config.virtual_host()) as conn: def callback(result): - (verified, exist) = result - if verified: - self.send_verified_notification( - exist, conn, exchange, routing_keys=routing_keys) - + try: + (verified, exist) = result + if verified: + self.send_verified_notification( + exist, conn, exchange, + routing_keys=routing_keys) + except Exception, e: + msg = "ERROR in Callback %s: %s" % (exchange_name, e) + LOG.exception(msg, e) try: self._run(callback=callback) except Exception, e: diff --git a/verifier/glance_verifier.py b/verifier/glance_verifier.py index 3ed49b6..3197a59 100644 --- a/verifier/glance_verifier.py +++ b/verifier/glance_verifier.py @@ -171,7 +171,12 @@ class GlanceVerifier(Verifier): def send_verified_notification(self, exist, connection, exchange, routing_keys=None): - body = exist.raw.json + # NOTE (apmelton) + # The exist we're provided from the callback may have cached queries + # from before it was serialized. We don't want to use them as + # they could have been lost somewhere in the process forking. + # So, grab a new InstanceExists object from the database and use it. + body = models.ImageExists.objects.get(id=exist.id).raw.json json_body = json.loads(body) json_body[1]['event_type'] = 'image.exists.verified.old' json_body[1]['original_message_id'] = json_body[1]['message_id'] diff --git a/verifier/nova_verifier.py b/verifier/nova_verifier.py index eaa373e..194b828 100644 --- a/verifier/nova_verifier.py +++ b/verifier/nova_verifier.py @@ -267,7 +267,12 @@ class NovaVerifier(base_verifier.Verifier): def send_verified_notification(self, exist, connection, exchange, routing_keys=None): - body = exist.raw.json + # NOTE (apmelton) + # The exist we're provided from the callback may have cached queries + # from before it was serialized. We don't want to use them as + # they could have been lost somewhere in the process forking. + # So, grab a new InstanceExists object from the database and use it. + body = models.InstanceExists.objects.get(id=exist.id).raw.json json_body = json.loads(body) json_body[1]['event_type'] = 'compute.instance.exists.verified.old' json_body[1]['original_message_id'] = json_body[1]['message_id']