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
This commit is contained in:
parent
3d5f4a5b02
commit
ca7ffbab5b
@ -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)
|
||||
|
||||
# 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')
|
||||
|
||||
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):
|
||||
|
Loading…
Reference in New Issue
Block a user