Browse Source

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 ca7ffbab5b)
tags/2.1.0
Kiall Mac Innes 3 years ago
parent
commit
85b172c047
1 changed files with 28 additions and 2 deletions
  1. 28
    2
      designate/rpc.py

+ 28
- 2
designate/rpc.py View File

@@ -26,9 +26,12 @@ __all__ = [
26 26
     'TRANSPORT_ALIASES',
27 27
 ]
28 28
 
29
+import inspect
30
+
29 31
 from oslo_config import cfg
30 32
 import oslo_messaging as messaging
31 33
 from oslo_messaging import server as msg_server
34
+from oslo_messaging.rpc import server as rpc_server
32 35
 from oslo_messaging.rpc import dispatcher as rpc_dispatcher
33 36
 from oslo_serialization import jsonutils
34 37
 
@@ -174,6 +177,7 @@ class RequestContextSerializer(messaging.Serializer):
174 177
 
175 178
 class RPCDispatcher(rpc_dispatcher.RPCDispatcher):
176 179
     def _dispatch(self, *args, **kwds):
180
+        # TODO(kiall): Remove when oslo.messaging 5 is the min in requirements
177 181
         try:
178 182
             return super(RPCDispatcher, self)._dispatch(*args, **kwds)
179 183
         except Exception as e:
@@ -182,6 +186,15 @@ class RPCDispatcher(rpc_dispatcher.RPCDispatcher):
182 186
             else:
183 187
                 raise
184 188
 
189
+    def dispatch(self, *args, **kwds):
190
+        try:
191
+            return super(RPCDispatcher, self).dispatch(*args, **kwds)
192
+        except Exception as e:
193
+            if getattr(e, 'expected', False):
194
+                raise rpc_dispatcher.ExpectedException()
195
+            else:
196
+                raise
197
+
185 198
 
186 199
 def get_transport_url(url_str=None):
187 200
     return messaging.TransportURL.parse(CONF, url_str, TRANSPORT_ALIASES)
@@ -204,8 +217,21 @@ def get_server(target, endpoints, serializer=None):
204 217
         serializer = DesignateObjectSerializer()
205 218
     serializer = RequestContextSerializer(serializer)
206 219
 
207
-    dispatcher = RPCDispatcher(target, endpoints, serializer)
208
-    return msg_server.MessageHandlingServer(TRANSPORT, dispatcher, 'eventlet')
220
+    # TODO(kiall): Remove when oslo.messaging 5 is the min in requirements
221
+    argspec = inspect.getargspec(rpc_dispatcher.RPCDispatcher.__init__)
222
+    if 'target' in argspec.args:
223
+        # We're on oslo.messaging < 5
224
+        dispatcher = RPCDispatcher(target, endpoints, serializer)
225
+
226
+        return msg_server.MessageHandlingServer(
227
+            TRANSPORT, dispatcher, 'eventlet')
228
+
229
+    else:
230
+        # We're on oslo.messaging >= 5
231
+        dispatcher = RPCDispatcher(endpoints, serializer)
232
+
233
+        return rpc_server.RPCServer(
234
+            TRANSPORT, target, dispatcher, 'eventlet')
209 235
 
210 236
 
211 237
 def get_listener(targets, endpoints, serializer=None):

Loading…
Cancel
Save