Set access_policy for messaging's dispatcher
oslo.messaging allow dispatcher to restrict endpoint methods since 5.11.0 in d3a8f280ebd6fd12865fd20c4d772774e39aefa2, set with DefaultRPCAccessPolicy to fix FutureWarning like: FutureWarning: The access_policy argument is changing its default value to <class 'oslo_messaging.rpc.dispatcher.DefaultRPCAccessPolicy'> in version '?', please update the code to explicitly set None as the value: access_policy defaults to LegacyRPCAccessPolicy which exposes private methods. Explicitly set access_policy to DefaultRPCAccessPolicy or ExplicitRPCAccessPolicy. Change-Id: Ie3dc84840fd39a3a55d6c1dad720d998fadd3c2e
This commit is contained in:
parent
7a5dc9c8e9
commit
907e598dbd
@ -30,6 +30,7 @@ import socket
|
||||
|
||||
|
||||
import oslo_messaging as messaging
|
||||
from oslo_messaging.rpc import dispatcher
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import importutils
|
||||
|
||||
@ -155,6 +156,7 @@ def get_client(target, version_cap=None, serializer=None, timeout=None):
|
||||
|
||||
def get_server(target, endpoints, serializer=None):
|
||||
assert TRANSPORT is not None
|
||||
access_policy = dispatcher.DefaultRPCAccessPolicy
|
||||
if profiler:
|
||||
serializer = ProfilerRequestContextSerializer(serializer)
|
||||
else:
|
||||
@ -164,7 +166,8 @@ def get_server(target, endpoints, serializer=None):
|
||||
target,
|
||||
endpoints,
|
||||
executor='eventlet',
|
||||
serializer=serializer)
|
||||
serializer=serializer,
|
||||
access_policy=access_policy)
|
||||
|
||||
|
||||
def get_notifier(service='container-infra', host=None, publisher_id=None):
|
||||
|
@ -15,6 +15,7 @@
|
||||
"""Common RPC service and API tools for Magnum."""
|
||||
|
||||
import oslo_messaging as messaging
|
||||
from oslo_messaging.rpc import dispatcher
|
||||
from oslo_service import service
|
||||
from oslo_utils import importutils
|
||||
|
||||
@ -48,10 +49,12 @@ class Service(service.Service):
|
||||
serializer = _init_serializer()
|
||||
transport = messaging.get_rpc_transport(CONF)
|
||||
# TODO(asalkeld) add support for version='x.y'
|
||||
access_policy = dispatcher.DefaultRPCAccessPolicy
|
||||
target = messaging.Target(topic=topic, server=server)
|
||||
self._server = messaging.get_rpc_server(transport, target, handlers,
|
||||
executor='eventlet',
|
||||
serializer=serializer)
|
||||
serializer=serializer,
|
||||
access_policy=access_policy)
|
||||
self.binary = binary
|
||||
profiler.setup(binary, CONF.host)
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
import mock
|
||||
import oslo_messaging as messaging
|
||||
from oslo_messaging.rpc import dispatcher
|
||||
from oslo_serialization import jsonutils
|
||||
|
||||
from magnum.common import context
|
||||
@ -71,12 +72,13 @@ class TestRpc(base.TestCase):
|
||||
ends = mock.Mock()
|
||||
mock_ser.return_value = ser
|
||||
mock_get.return_value = 'server'
|
||||
|
||||
access_policy = dispatcher.DefaultRPCAccessPolicy
|
||||
server = rpc.get_server(tgt, ends, serializer='foo')
|
||||
|
||||
mock_ser.assert_called_once_with('foo')
|
||||
mock_get.assert_called_once_with(rpc.TRANSPORT, tgt, ends,
|
||||
executor='eventlet', serializer=ser)
|
||||
executor='eventlet', serializer=ser,
|
||||
access_policy=access_policy)
|
||||
self.assertEqual('server', server)
|
||||
|
||||
@mock.patch.object(rpc, 'profiler', mock.Mock())
|
||||
@ -89,12 +91,13 @@ class TestRpc(base.TestCase):
|
||||
ends = mock.Mock()
|
||||
mock_ser.return_value = ser
|
||||
mock_get.return_value = 'server'
|
||||
|
||||
access_policy = dispatcher.DefaultRPCAccessPolicy
|
||||
server = rpc.get_server(tgt, ends, serializer='foo')
|
||||
|
||||
mock_ser.assert_called_once_with('foo')
|
||||
mock_get.assert_called_once_with(rpc.TRANSPORT, tgt, ends,
|
||||
executor='eventlet', serializer=ser)
|
||||
executor='eventlet', serializer=ser,
|
||||
access_policy=access_policy)
|
||||
self.assertEqual('server', server)
|
||||
|
||||
@mock.patch.object(messaging, 'TransportURL')
|
||||
|
Loading…
Reference in New Issue
Block a user