summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKiall Mac Innes <kiall@macinnes.ie>2016-05-10 13:06:49 +0100
committerGraham Hayes <graham.hayes@hpe.com>2016-05-10 14:48:39 +0000
commit85b172c04781052bae05368f3e6ac512388bdec5 (patch)
tree1cf5e2967e4f5a399bb2c4a09fe2b6594dbedd09
parent49963a766980ef034f463deee1a47fe229d4315c (diff)
downloaddesignate-85b172c04781052bae05368f3e6ac512388bdec5.tar.gz
Support both olso.m v4 and v5
Oslo.Messaging v5 made some API changes which broke us in I5f23e23644e90919cb67f81fc306ee85c5e09974. Update our code to "detect" this API change, and behave accordingly. Closes-Bug: 1580139 Partial-Bug: 1412977 Change-Id: I5b44cd2ded32d90be6efda7b5238df72ce6c6cbd (cherry picked from commit ca7ffbab5b0df9cffa783a1864196c17cfd40b49)
-rw-r--r--designate/rpc.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/designate/rpc.py b/designate/rpc.py
index b13c30b6..f6e275b5 100644
--- a/designate/rpc.py
+++ b/designate/rpc.py
@@ -26,9 +26,12 @@ __all__ = [
'TRANSPORT_ALIASES',
]
+import inspect
+
from oslo_config import cfg
import oslo_messaging as messaging
from oslo_messaging import server as msg_server
+from oslo_messaging.rpc import server as rpc_server
from oslo_messaging.rpc import dispatcher as rpc_dispatcher
from oslo_serialization import jsonutils
@@ -174,6 +177,7 @@ class RequestContextSerializer(messaging.Serializer):
class RPCDispatcher(rpc_dispatcher.RPCDispatcher):
def _dispatch(self, *args, **kwds):
+ # TODO(kiall): Remove when oslo.messaging 5 is the min in requirements
try:
return super(RPCDispatcher, self)._dispatch(*args, **kwds)
except Exception as e:
@@ -182,6 +186,15 @@ class RPCDispatcher(rpc_dispatcher.RPCDispatcher):
else:
raise
+ def dispatch(self, *args, **kwds):
+ try:
+ return super(RPCDispatcher, self).dispatch(*args, **kwds)
+ except Exception as e:
+ if getattr(e, 'expected', False):
+ raise rpc_dispatcher.ExpectedException()
+ else:
+ raise
+
def get_transport_url(url_str=None):
return messaging.TransportURL.parse(CONF, url_str, TRANSPORT_ALIASES)
@@ -204,8 +217,21 @@ def get_server(target, endpoints, serializer=None):
serializer = DesignateObjectSerializer()
serializer = RequestContextSerializer(serializer)
- dispatcher = RPCDispatcher(target, endpoints, serializer)
- return msg_server.MessageHandlingServer(TRANSPORT, dispatcher, 'eventlet')
+ # TODO(kiall): Remove when oslo.messaging 5 is the min in requirements
+ argspec = inspect.getargspec(rpc_dispatcher.RPCDispatcher.__init__)
+ if 'target' in argspec.args:
+ # We're on oslo.messaging < 5
+ dispatcher = RPCDispatcher(target, endpoints, serializer)
+
+ return msg_server.MessageHandlingServer(
+ TRANSPORT, dispatcher, 'eventlet')
+
+ else:
+ # We're on oslo.messaging >= 5
+ dispatcher = RPCDispatcher(endpoints, serializer)
+
+ return rpc_server.RPCServer(
+ TRANSPORT, target, dispatcher, 'eventlet')
def get_listener(targets, endpoints, serializer=None):