Add RPC serialization checking, fix exposed problems.
Related to bug 933584. In this bug, I hit a case where some code tried to send a SQLAlchemy model over rpc, which failed since it couldn't be serialized by Qpid. This patch adds a simple serialization check to the fake RPC driver using json. It also fixes problems that were exposed by adding this check. If json can't serialize a message sent through the fake RPC driver, it will raise TypeError, causing unit tests to fail. 18 unit tests failed with the check in place, but it was due to only 2 places in the compute API. Change-Id: I63f3077c0fa35097d4f5d2c485f4e48eede2c751
This commit is contained in:
@@ -18,6 +18,7 @@ queues. Casts will block, but this is very useful for tests.
|
||||
"""
|
||||
|
||||
import inspect
|
||||
import json
|
||||
import signal
|
||||
import sys
|
||||
import time
|
||||
@@ -124,9 +125,16 @@ def create_connection(new=True):
|
||||
return Connection()
|
||||
|
||||
|
||||
def check_serialize(msg):
|
||||
"""Make sure a message intended for rpc can be serialized."""
|
||||
json.dumps(msg)
|
||||
|
||||
|
||||
def multicall(context, topic, msg, timeout=None):
|
||||
"""Make a call that returns multiple times."""
|
||||
|
||||
check_serialize(msg)
|
||||
|
||||
method = msg.get('method')
|
||||
if not method:
|
||||
return
|
||||
@@ -158,7 +166,7 @@ def cast(context, topic, msg):
|
||||
|
||||
|
||||
def notify(context, topic, msg):
|
||||
pass
|
||||
check_serialize(msg)
|
||||
|
||||
|
||||
def cleanup():
|
||||
@@ -167,6 +175,7 @@ def cleanup():
|
||||
|
||||
def fanout_cast(context, topic, msg):
|
||||
"""Cast to all consumers of a topic"""
|
||||
check_serialize(msg)
|
||||
method = msg.get('method')
|
||||
if not method:
|
||||
return
|
||||
|
Reference in New Issue
Block a user