Use new get_rpc_client API from oslo.messaging
Use the new API that is consistent with the existing API instead of instantiating the client class directly. This was introduced in release 14.1.0 here [1] and added into oslo.messaging here [2] [1] https://review.opendev.org/c/openstack/requirements/+/869340 [2] https://review.opendev.org/c/openstack/oslo.messaging/+/862419 Change-Id: If1128fe0faacef757ed10023c00a67e5ec0440bd
This commit is contained in:
parent
668d4e590f
commit
c59db128a0
16
nova/rpc.py
16
nova/rpc.py
@ -204,11 +204,9 @@ def get_client(target, version_cap=None, serializer=None,
|
||||
else:
|
||||
serializer = RequestContextSerializer(serializer)
|
||||
|
||||
return messaging.RPCClient(TRANSPORT,
|
||||
target,
|
||||
version_cap=version_cap,
|
||||
serializer=serializer,
|
||||
call_monitor_timeout=call_monitor_timeout)
|
||||
return messaging.get_rpc_client(TRANSPORT, target,
|
||||
version_cap=version_cap, serializer=serializer,
|
||||
call_monitor_timeout=call_monitor_timeout)
|
||||
|
||||
|
||||
def get_server(target, endpoints, serializer=None):
|
||||
@ -436,9 +434,9 @@ class ClientRouter(periodic_task.PeriodicTasks):
|
||||
transport = context.mq_connection
|
||||
if transport:
|
||||
cmt = self.default_client.call_monitor_timeout
|
||||
return messaging.RPCClient(transport, self.target,
|
||||
version_cap=self.version_cap,
|
||||
serializer=self.serializer,
|
||||
call_monitor_timeout=cmt)
|
||||
return messaging.get_rpc_client(transport, self.target,
|
||||
version_cap=self.version_cap,
|
||||
serializer=self.serializer,
|
||||
call_monitor_timeout=cmt)
|
||||
else:
|
||||
return self.default_client
|
||||
|
9
nova/tests/fixtures/nova.py
vendored
9
nova/tests/fixtures/nova.py
vendored
@ -565,11 +565,10 @@ class CellDatabases(fixtures.Fixture):
|
||||
call_monitor_timeout=None):
|
||||
"""Mirror rpc.get_client() but with our special sauce."""
|
||||
serializer = CheatingSerializer(serializer)
|
||||
return messaging.RPCClient(rpc.TRANSPORT,
|
||||
target,
|
||||
version_cap=version_cap,
|
||||
serializer=serializer,
|
||||
call_monitor_timeout=call_monitor_timeout)
|
||||
return messaging.get_rpc_client(rpc.TRANSPORT, target,
|
||||
version_cap=version_cap,
|
||||
serializer=serializer,
|
||||
call_monitor_timeout=call_monitor_timeout)
|
||||
|
||||
def add_cell_database(self, connection_str, default=False):
|
||||
"""Add a cell database to the fixture.
|
||||
|
@ -214,20 +214,20 @@ class TestRPC(test.NoDBTestCase):
|
||||
@mock.patch.object(rpc, 'TRANSPORT')
|
||||
@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, mock_TRANSPORT):
|
||||
@mock.patch.object(messaging, 'get_rpc_client')
|
||||
def test_get_client(self, mock_get, mock_ser, mock_TRANSPORT):
|
||||
tgt = mock.Mock()
|
||||
ser = mock.Mock()
|
||||
mock_client.return_value = 'client'
|
||||
mock_get.return_value = 'client'
|
||||
mock_ser.return_value = ser
|
||||
|
||||
client = rpc.get_client(tgt, version_cap='1.0', serializer='foo')
|
||||
|
||||
mock_ser.assert_called_once_with('foo')
|
||||
mock_client.assert_called_once_with(mock_TRANSPORT,
|
||||
tgt, version_cap='1.0',
|
||||
call_monitor_timeout=None,
|
||||
serializer=ser)
|
||||
mock_get.assert_called_once_with(mock_TRANSPORT,
|
||||
tgt, version_cap='1.0',
|
||||
call_monitor_timeout=None,
|
||||
serializer=ser)
|
||||
self.assertEqual('client', client)
|
||||
|
||||
@mock.patch.object(rpc, 'TRANSPORT')
|
||||
@ -253,21 +253,21 @@ class TestRPC(test.NoDBTestCase):
|
||||
@mock.patch.object(rpc, 'TRANSPORT')
|
||||
@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,
|
||||
@mock.patch.object(messaging, 'get_rpc_client')
|
||||
def test_get_client_profiler_enabled(self, mock_get, mock_ser,
|
||||
mock_TRANSPORT):
|
||||
tgt = mock.Mock()
|
||||
ser = mock.Mock()
|
||||
mock_client.return_value = 'client'
|
||||
mock_get.return_value = 'client'
|
||||
mock_ser.return_value = ser
|
||||
|
||||
client = rpc.get_client(tgt, version_cap='1.0', serializer='foo')
|
||||
|
||||
mock_ser.assert_called_once_with('foo')
|
||||
mock_client.assert_called_once_with(mock_TRANSPORT,
|
||||
tgt, version_cap='1.0',
|
||||
call_monitor_timeout=None,
|
||||
serializer=ser)
|
||||
mock_get.assert_called_once_with(mock_TRANSPORT,
|
||||
tgt, version_cap='1.0',
|
||||
call_monitor_timeout=None,
|
||||
serializer=ser)
|
||||
self.assertEqual('client', client)
|
||||
|
||||
@mock.patch.object(rpc, 'TRANSPORT')
|
||||
@ -432,11 +432,11 @@ class TestProfilerRequestContextSerializer(test.NoDBTestCase):
|
||||
|
||||
|
||||
class TestClientRouter(test.NoDBTestCase):
|
||||
@mock.patch('oslo_messaging.RPCClient')
|
||||
def test_by_instance(self, mock_rpcclient):
|
||||
@mock.patch('oslo_messaging.get_rpc_client')
|
||||
def test_by_instance(self, mock_get):
|
||||
default_client = mock.Mock()
|
||||
cell_client = mock.Mock()
|
||||
mock_rpcclient.return_value = cell_client
|
||||
mock_get.return_value = cell_client
|
||||
ctxt = mock.Mock()
|
||||
ctxt.mq_connection = mock.sentinel.transport
|
||||
|
||||
@ -444,7 +444,7 @@ class TestClientRouter(test.NoDBTestCase):
|
||||
client = router.client(ctxt)
|
||||
|
||||
# verify a client was created by ClientRouter
|
||||
mock_rpcclient.assert_called_once_with(
|
||||
mock_get.assert_called_once_with(
|
||||
mock.sentinel.transport, default_client.target,
|
||||
version_cap=default_client.version_cap,
|
||||
call_monitor_timeout=default_client.call_monitor_timeout,
|
||||
@ -452,11 +452,11 @@ class TestClientRouter(test.NoDBTestCase):
|
||||
# verify cell client was returned
|
||||
self.assertEqual(cell_client, client)
|
||||
|
||||
@mock.patch('oslo_messaging.RPCClient')
|
||||
def test_by_instance_untargeted(self, mock_rpcclient):
|
||||
@mock.patch('oslo_messaging.get_rpc_client')
|
||||
def test_by_instance_untargeted(self, mock_get):
|
||||
default_client = mock.Mock()
|
||||
cell_client = mock.Mock()
|
||||
mock_rpcclient.return_value = cell_client
|
||||
mock_get.return_value = cell_client
|
||||
ctxt = mock.Mock()
|
||||
ctxt.mq_connection = None
|
||||
|
||||
@ -464,7 +464,7 @@ class TestClientRouter(test.NoDBTestCase):
|
||||
client = router.client(ctxt)
|
||||
|
||||
self.assertEqual(router.default_client, client)
|
||||
self.assertFalse(mock_rpcclient.called)
|
||||
self.assertFalse(mock_get.called)
|
||||
|
||||
|
||||
class TestIsNotificationsEnabledDecorator(test.NoDBTestCase):
|
||||
|
@ -42,7 +42,7 @@ oslo.upgradecheck>=1.3.0
|
||||
oslo.utils>=4.12.1 # Apache-2.0
|
||||
oslo.db>=10.0.0 # Apache-2.0
|
||||
oslo.rootwrap>=5.15.0 # Apache-2.0
|
||||
oslo.messaging>=10.3.0 # Apache-2.0
|
||||
oslo.messaging>=14.1.0 # Apache-2.0
|
||||
oslo.policy>=3.11.0 # Apache-2.0
|
||||
oslo.privsep>=2.6.2 # Apache-2.0
|
||||
oslo.i18n>=5.1.0 # Apache-2.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user