Move decorator updated_kwarg_default_value to right place
debtcollector's decorator updated_kwarg_default_value is used to indicate default value will be changed in future version. We introduced parameter access_policy and add itfor constructor method of RPCDispatcher ind3a8f280eb
. Other services usually call get_rpc_server method instead of calling constructor method of RPCDispatcher. get_rpc_server method constructs RPCDispatcher instance in [1], then FutureWarning will be generated even we set parameter access_policy explicitly. Need move the decorator updated_kwarg_default_value to method get_rec_server to avoid the case. Closes-Bug: #1661572 [1]f1efaf1b6e/oslo_messaging/rpc/server.py (L200)
. Change-Id: I3214045856d0bbd05a0000eeafb769e4697cd34c
This commit is contained in:
parent
7f990bfe5f
commit
8cbca30afd
@ -34,7 +34,6 @@ import sys
|
||||
|
||||
import six
|
||||
|
||||
from debtcollector.updating import updated_kwarg_default_value
|
||||
from oslo_messaging import _utils as utils
|
||||
from oslo_messaging import dispatcher
|
||||
from oslo_messaging import serializer as msg_serializer
|
||||
@ -145,14 +144,6 @@ class RPCDispatcher(dispatcher.DispatcherBase):
|
||||
|
||||
|
||||
"""
|
||||
@updated_kwarg_default_value('access_policy', None, DefaultRPCAccessPolicy,
|
||||
message='access_policy defaults to '
|
||||
'LegacyRPCAccessPolicy which '
|
||||
'exposes private methods. Explicitly '
|
||||
'set access_policy to '
|
||||
'DefaultRPCAccessPolicy or '
|
||||
'ExplicitRPCAccessPolicy.',
|
||||
version='?')
|
||||
def __init__(self, endpoints, serializer, access_policy=None):
|
||||
"""Construct a rpc server dispatcher.
|
||||
|
||||
|
@ -127,6 +127,8 @@ __all__ = [
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from debtcollector.updating import updated_kwarg_default_value
|
||||
|
||||
from oslo_messaging._i18n import _LE
|
||||
from oslo_messaging.rpc import dispatcher as rpc_dispatcher
|
||||
from oslo_messaging import server as msg_server
|
||||
@ -177,6 +179,15 @@ class RPCServer(msg_server.MessageHandlingServer):
|
||||
del failure
|
||||
|
||||
|
||||
@updated_kwarg_default_value('access_policy', None,
|
||||
rpc_dispatcher.DefaultRPCAccessPolicy,
|
||||
message='access_policy defaults to '
|
||||
'LegacyRPCAccessPolicy which '
|
||||
'exposes private methods. Explicitly '
|
||||
'set access_policy to '
|
||||
'DefaultRPCAccessPolicy or '
|
||||
'ExplicitRPCAccessPolicy.',
|
||||
version='?')
|
||||
def get_rpc_server(transport, target, endpoints,
|
||||
executor='blocking', serializer=None, access_policy=None):
|
||||
"""Construct an RPC server.
|
||||
|
@ -13,15 +13,17 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import eventlet
|
||||
import threading
|
||||
import warnings
|
||||
|
||||
import eventlet
|
||||
from oslo_config import cfg
|
||||
from six.moves import mock
|
||||
import testscenarios
|
||||
|
||||
import oslo_messaging
|
||||
from oslo_messaging import rpc
|
||||
from oslo_messaging.rpc import dispatcher
|
||||
from oslo_messaging.rpc import server as rpc_server_module
|
||||
from oslo_messaging import server as server_module
|
||||
from oslo_messaging.tests import utils as test_utils
|
||||
@ -114,10 +116,16 @@ class TestRPCServer(test_utils.BaseTestCase, ServerSetupMixin):
|
||||
target = oslo_messaging.Target(topic='foo', server='bar')
|
||||
endpoints = [object()]
|
||||
serializer = object()
|
||||
access_policy = dispatcher.DefaultRPCAccessPolicy
|
||||
|
||||
server = oslo_messaging.get_rpc_server(transport, target, endpoints,
|
||||
serializer=serializer)
|
||||
|
||||
with warnings.catch_warnings(record=True) as capture:
|
||||
warnings.simplefilter("always", FutureWarning)
|
||||
server = oslo_messaging.get_rpc_server(transport,
|
||||
target,
|
||||
endpoints,
|
||||
serializer=serializer,
|
||||
access_policy=access_policy)
|
||||
self.assertEqual(0, len(capture))
|
||||
self.assertIs(server.conf, self.conf)
|
||||
self.assertIs(server.transport, transport)
|
||||
self.assertIsInstance(server.dispatcher, oslo_messaging.RPCDispatcher)
|
||||
@ -125,6 +133,19 @@ class TestRPCServer(test_utils.BaseTestCase, ServerSetupMixin):
|
||||
self.assertIs(server.dispatcher.serializer, serializer)
|
||||
self.assertEqual('blocking', server.executor_type)
|
||||
|
||||
def test_constructor_without_explicit_RPCAccessPolicy(self):
|
||||
transport = oslo_messaging.get_transport(self.conf, url='fake:')
|
||||
target = oslo_messaging.Target(topic='foo', server='bar')
|
||||
endpoints = [object()]
|
||||
serializer = object()
|
||||
with warnings.catch_warnings(record=True) as capture:
|
||||
warnings.simplefilter("always", FutureWarning)
|
||||
oslo_messaging.get_rpc_server(transport, target,
|
||||
endpoints, serializer=serializer)
|
||||
self.assertEqual(1, len(capture))
|
||||
w = capture[0]
|
||||
self.assertEqual(FutureWarning, w.category)
|
||||
|
||||
def test_server_wait_method(self):
|
||||
transport = oslo_messaging.get_transport(self.conf, url='fake:')
|
||||
target = oslo_messaging.Target(topic='foo', server='bar')
|
||||
|
Loading…
Reference in New Issue
Block a user