Using new exist object in callback

This commit is contained in:
Andrew Melton 2013-10-24 13:38:04 -04:00
parent 4a591c2917
commit 3515078cad
5 changed files with 30 additions and 7 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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:

View File

@ -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']

View File

@ -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']