Using new exist object in callback
This commit is contained in:
@@ -54,6 +54,7 @@ class GlanceVerifierTestCase(StacktachBaseTestCase):
|
|||||||
models.ImageDeletes.objects = self.mox.CreateMockAnything()
|
models.ImageDeletes.objects = self.mox.CreateMockAnything()
|
||||||
self.mox.StubOutWithMock(models, 'ImageExists',
|
self.mox.StubOutWithMock(models, 'ImageExists',
|
||||||
use_mock_anything=True)
|
use_mock_anything=True)
|
||||||
|
models.ImageExists.objects = self.mox.CreateMockAnything()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.mox.UnsetStubs()
|
self.mox.UnsetStubs()
|
||||||
@@ -506,6 +507,7 @@ class GlanceVerifierTestCase(StacktachBaseTestCase):
|
|||||||
connection = self.mox.CreateMockAnything()
|
connection = self.mox.CreateMockAnything()
|
||||||
exchange = self.mox.CreateMockAnything()
|
exchange = self.mox.CreateMockAnything()
|
||||||
exist = self.mox.CreateMockAnything()
|
exist = self.mox.CreateMockAnything()
|
||||||
|
exist.id = 1
|
||||||
exist.raw = self.mox.CreateMockAnything()
|
exist.raw = self.mox.CreateMockAnything()
|
||||||
exist_dict = [
|
exist_dict = [
|
||||||
'monitor.info',
|
'monitor.info',
|
||||||
@@ -523,6 +525,7 @@ class GlanceVerifierTestCase(StacktachBaseTestCase):
|
|||||||
uuid.uuid4().AndReturn('some_other_uuid')
|
uuid.uuid4().AndReturn('some_other_uuid')
|
||||||
self.mox.StubOutWithMock(kombu.pools, 'producers')
|
self.mox.StubOutWithMock(kombu.pools, 'producers')
|
||||||
self.mox.StubOutWithMock(kombu.common, 'maybe_declare')
|
self.mox.StubOutWithMock(kombu.common, 'maybe_declare')
|
||||||
|
models.ImageExists.objects.get(id=exist.id).AndReturn(exist)
|
||||||
routing_keys = ['notifications.info', 'monitor.info']
|
routing_keys = ['notifications.info', 'monitor.info']
|
||||||
for key in routing_keys:
|
for key in routing_keys:
|
||||||
producer = self.mox.CreateMockAnything()
|
producer = self.mox.CreateMockAnything()
|
||||||
@@ -546,6 +549,7 @@ class GlanceVerifierTestCase(StacktachBaseTestCase):
|
|||||||
connection = self.mox.CreateMockAnything()
|
connection = self.mox.CreateMockAnything()
|
||||||
exchange = self.mox.CreateMockAnything()
|
exchange = self.mox.CreateMockAnything()
|
||||||
exist = self.mox.CreateMockAnything()
|
exist = self.mox.CreateMockAnything()
|
||||||
|
exist.id = 1
|
||||||
exist.raw = self.mox.CreateMockAnything()
|
exist.raw = self.mox.CreateMockAnything()
|
||||||
exist_dict = [
|
exist_dict = [
|
||||||
'monitor.info',
|
'monitor.info',
|
||||||
@@ -561,6 +565,7 @@ class GlanceVerifierTestCase(StacktachBaseTestCase):
|
|||||||
exist.owner = "1"
|
exist.owner = "1"
|
||||||
self.mox.StubOutWithMock(kombu.pools, 'producers')
|
self.mox.StubOutWithMock(kombu.pools, 'producers')
|
||||||
self.mox.StubOutWithMock(kombu.common, 'maybe_declare')
|
self.mox.StubOutWithMock(kombu.common, 'maybe_declare')
|
||||||
|
models.ImageExists.objects.get(id=exist.id).AndReturn(exist)
|
||||||
producer = self.mox.CreateMockAnything()
|
producer = self.mox.CreateMockAnything()
|
||||||
producer.channel = self.mox.CreateMockAnything()
|
producer.channel = self.mox.CreateMockAnything()
|
||||||
kombu.pools.producers[connection].AndReturn(producer)
|
kombu.pools.producers[connection].AndReturn(producer)
|
||||||
|
@@ -1108,6 +1108,7 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
|
|||||||
connection = self.mox.CreateMockAnything()
|
connection = self.mox.CreateMockAnything()
|
||||||
exchange = self.mox.CreateMockAnything()
|
exchange = self.mox.CreateMockAnything()
|
||||||
exist = self.mox.CreateMockAnything()
|
exist = self.mox.CreateMockAnything()
|
||||||
|
exist.id = 1
|
||||||
exist.raw = self.mox.CreateMockAnything()
|
exist.raw = self.mox.CreateMockAnything()
|
||||||
exist_dict = [
|
exist_dict = [
|
||||||
'monitor.info',
|
'monitor.info',
|
||||||
@@ -1122,6 +1123,7 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
|
|||||||
uuid.uuid4().AndReturn('some_other_uuid')
|
uuid.uuid4().AndReturn('some_other_uuid')
|
||||||
self.mox.StubOutWithMock(kombu.pools, 'producers')
|
self.mox.StubOutWithMock(kombu.pools, 'producers')
|
||||||
self.mox.StubOutWithMock(kombu.common, 'maybe_declare')
|
self.mox.StubOutWithMock(kombu.common, 'maybe_declare')
|
||||||
|
models.InstanceExists.objects.get(id=exist.id).AndReturn(exist)
|
||||||
routing_keys = ['notifications.info', 'monitor.info']
|
routing_keys = ['notifications.info', 'monitor.info']
|
||||||
for key in routing_keys:
|
for key in routing_keys:
|
||||||
producer = self.mox.CreateMockAnything()
|
producer = self.mox.CreateMockAnything()
|
||||||
@@ -1145,6 +1147,7 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
|
|||||||
connection = self.mox.CreateMockAnything()
|
connection = self.mox.CreateMockAnything()
|
||||||
exchange = self.mox.CreateMockAnything()
|
exchange = self.mox.CreateMockAnything()
|
||||||
exist = self.mox.CreateMockAnything()
|
exist = self.mox.CreateMockAnything()
|
||||||
|
exist.id = 1
|
||||||
exist.raw = self.mox.CreateMockAnything()
|
exist.raw = self.mox.CreateMockAnything()
|
||||||
exist_dict = [
|
exist_dict = [
|
||||||
'monitor.info',
|
'monitor.info',
|
||||||
@@ -1157,6 +1160,7 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
|
|||||||
exist.raw.json = exist_str
|
exist.raw.json = exist_str
|
||||||
self.mox.StubOutWithMock(kombu.pools, 'producers')
|
self.mox.StubOutWithMock(kombu.pools, 'producers')
|
||||||
self.mox.StubOutWithMock(kombu.common, 'maybe_declare')
|
self.mox.StubOutWithMock(kombu.common, 'maybe_declare')
|
||||||
|
models.InstanceExists.objects.get(id=exist.id).AndReturn(exist)
|
||||||
producer = self.mox.CreateMockAnything()
|
producer = self.mox.CreateMockAnything()
|
||||||
producer.channel = self.mox.CreateMockAnything()
|
producer.channel = self.mox.CreateMockAnything()
|
||||||
kombu.pools.producers[connection].AndReturn(producer)
|
kombu.pools.producers[connection].AndReturn(producer)
|
||||||
|
@@ -167,11 +167,15 @@ class Verifier(object):
|
|||||||
self.config.userid(), self.config.password(),
|
self.config.userid(), self.config.password(),
|
||||||
"librabbitmq", self.config.virtual_host()) as conn:
|
"librabbitmq", self.config.virtual_host()) as conn:
|
||||||
def callback(result):
|
def callback(result):
|
||||||
(verified, exist) = result
|
try:
|
||||||
if verified:
|
(verified, exist) = result
|
||||||
self.send_verified_notification(
|
if verified:
|
||||||
exist, conn, exchange, routing_keys=routing_keys)
|
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:
|
try:
|
||||||
self._run(callback=callback)
|
self._run(callback=callback)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
@@ -170,7 +170,12 @@ class GlanceVerifier(Verifier):
|
|||||||
|
|
||||||
def send_verified_notification(self, exist, connection, exchange,
|
def send_verified_notification(self, exist, connection, exchange,
|
||||||
routing_keys=None):
|
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 = json.loads(body)
|
||||||
json_body[1]['event_type'] = self.config.glance_event_type()
|
json_body[1]['event_type'] = self.config.glance_event_type()
|
||||||
json_body[1]['original_message_id'] = json_body[1]['message_id']
|
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,
|
def send_verified_notification(self, exist, connection, exchange,
|
||||||
routing_keys=None):
|
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 = json.loads(body)
|
||||||
json_body[1]['event_type'] = self.config.nova_event_type()
|
json_body[1]['event_type'] = self.config.nova_event_type()
|
||||||
json_body[1]['original_message_id'] = json_body[1]['message_id']
|
json_body[1]['original_message_id'] = json_body[1]['message_id']
|
||||||
|
Reference in New Issue
Block a user