Merge pull request #233 from ramielrowe/callback_fix
Using new exist object in callback
This commit is contained in:
commit
6ce529ffd4
@ -54,6 +54,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()
|
||||
@ -506,6 +507,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',
|
||||
@ -523,6 +525,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()
|
||||
@ -546,6 +549,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',
|
||||
@ -561,6 +565,7 @@ class GlanceVerifierTestCase(StacktachBaseTestCase):
|
||||
exist.owner = "1"
|
||||
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)
|
||||
|
@ -1108,6 +1108,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',
|
||||
@ -1122,6 +1123,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()
|
||||
@ -1145,6 +1147,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',
|
||||
@ -1157,6 +1160,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)
|
||||
|
@ -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:
|
||||
|
@ -170,7 +170,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'] = self.config.glance_event_type()
|
||||
json_body[1]['original_message_id'] = json_body[1]['message_id']
|
||||
|
@ -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'] = self.config.nova_event_type()
|
||||
json_body[1]['original_message_id'] = json_body[1]['message_id']
|
||||
|
Loading…
x
Reference in New Issue
Block a user