Browse Source

Merge "Re-use transport for rpc calls"

changes/23/773923/1
Zuul 2 months ago
committed by Gerrit Code Review
parent
commit
d614499825
4 changed files with 8 additions and 40 deletions
  1. +0
    -5
      magnum/common/rpc.py
  2. +4
    -8
      magnum/common/rpc_service.py
  3. +2
    -3
      magnum/conductor/api.py
  4. +2
    -24
      magnum/tests/unit/common/test_rpc.py

+ 0
- 5
magnum/common/rpc.py View File

@ -142,11 +142,6 @@ def get_transport_url(url_str=None):
def get_client(target, version_cap=None, serializer=None, timeout=None):
assert TRANSPORT is not None
if profiler:
serializer = ProfilerRequestContextSerializer(serializer)
else:
serializer = RequestContextSerializer(serializer)
return messaging.RPCClient(TRANSPORT,
target,
version_cap=version_cap,


+ 4
- 8
magnum/common/rpc_service.py View File

@ -79,20 +79,16 @@ class Service(service.Service):
class API(object):
def __init__(self, transport=None, context=None, topic=None, server=None,
def __init__(self, context=None, topic=None, server=None,
timeout=None):
serializer = _init_serializer()
if transport is None:
exmods = rpc.get_allowed_exmods()
transport = messaging.get_rpc_transport(
CONF, allowed_remote_exmods=exmods)
self._context = context
if topic is None:
topic = ''
target = messaging.Target(topic=topic, server=server)
self._client = messaging.RPCClient(transport, target,
serializer=serializer,
timeout=timeout)
self._client = rpc.get_client(target,
serializer=serializer,
timeout=timeout)
def _call(self, method, *args, **kwargs):
return self._client.call(self._context, method, *args, **kwargs)


+ 2
- 3
magnum/conductor/api.py View File

@ -25,9 +25,8 @@ CONF = magnum.conf.CONF
@profiler.trace_cls("rpc")
class API(rpc_service.API):
def __init__(self, transport=None, context=None, topic=None):
super(API, self).__init__(transport, context,
topic=CONF.conductor.topic)
def __init__(self, context=None, topic=CONF.conductor.topic):
super(API, self).__init__(context=context, topic=topic)
# Cluster Operations


+ 2
- 24
magnum/tests/unit/common/test_rpc.py View File

@ -26,38 +26,16 @@ from magnum.tests import base
class TestRpc(base.TestCase):
@mock.patch.object(rpc, 'profiler', None)
@mock.patch.object(rpc, 'RequestContextSerializer')
@mock.patch.object(messaging, 'RPCClient')
def test_get_client(self, mock_client, mock_ser):
rpc.TRANSPORT = mock.Mock()
tgt = mock.Mock()
ser = mock.Mock()
mock_client.return_value = 'client'
mock_ser.return_value = ser
client = rpc.get_client(tgt, version_cap='1.0', serializer='foo',
timeout=6969)
mock_ser.assert_called_once_with('foo')
mock_client.assert_called_once_with(rpc.TRANSPORT,
tgt, version_cap='1.0',
serializer=ser, timeout=6969)
self.assertEqual('client', client)
@mock.patch.object(rpc, 'profiler', mock.Mock())
@mock.patch.object(rpc, 'ProfilerRequestContextSerializer')
@mock.patch.object(messaging, 'RPCClient')
def test_get_client_profiler_enabled(self, mock_client, mock_ser):
def test_get_client(self, mock_client):
rpc.TRANSPORT = mock.Mock()
tgt = mock.Mock()
ser = mock.Mock()
mock_client.return_value = 'client'
mock_ser.return_value = ser
client = rpc.get_client(tgt, version_cap='1.0', serializer='foo',
client = rpc.get_client(tgt, version_cap='1.0', serializer=ser,
timeout=6969)
mock_ser.assert_called_once_with('foo')
mock_client.assert_called_once_with(rpc.TRANSPORT,
tgt, version_cap='1.0',
serializer=ser, timeout=6969)


Loading…
Cancel
Save