Add a new configuration parameter rpc_response_max_timeout
A new parameter rpc_response_max_timeout is added and registered into neutron.conf. (related codes in neutron) The rpc_response_max_timeout plays a role of the ceiling of timeout seconds when waiting for the response of a remote rpc server. During an RPC call, the waiting time starts from the existing parameter rpc_response_timeout(default 60s) and doubled each time until it reaches the ceiling which is currently set as 10 times rpc_response_timeout. It seems to be less flexible since user cannot directly change the ceiling value unless he/she changes the rpc_response_timeout. By adding rpc_response_max_timeout, user can now modify it without changing any other parameters. In class _BackingOffContextWrapper, _max_timeout and its setters are useless temporarily because users can now directly change the rpc_max_ timeout in neutron.conf. However, there're not deleted as we should not prevent the developer to override this parameter. Co-Authored-By: Allain Legacy<Allain.legacy@windriver.com> Change-Id: I45d2e5c063d2dd43cb8aec1d46faa3ee8ea4825f Depends-on: https://review.openstack.org/#/c/626109 Related-Bug: #1805769 Story: 2004456 Task: 28171
This commit is contained in:
parent
152342413b
commit
af902dfb2a
@ -90,6 +90,10 @@ def _get_default_method_timeouts():
|
||||
return collections.defaultdict(_get_default_method_timeout)
|
||||
|
||||
|
||||
def _get_rpc_response_max_timeout():
|
||||
return TRANSPORT.conf.rpc_response_max_timeout
|
||||
|
||||
|
||||
class _ContextWrapper(object):
|
||||
def __init__(self, original_context):
|
||||
self._original_context = original_context
|
||||
@ -129,7 +133,7 @@ class _BackingOffContextWrapper(_ContextWrapper):
|
||||
|
||||
@classmethod
|
||||
def get_max_timeout(cls):
|
||||
return cls._max_timeout or _get_default_method_timeout() * 10
|
||||
return cls._max_timeout or _get_rpc_response_max_timeout()
|
||||
|
||||
@classmethod
|
||||
def set_max_timeout(cls, max_timeout):
|
||||
|
@ -292,6 +292,7 @@ class TimeoutTestCase(base.BaseTestCase):
|
||||
self.call_context = mock.Mock()
|
||||
self.sleep = mock.patch('time.sleep').start()
|
||||
rpc.TRANSPORT.conf.rpc_response_timeout = 10
|
||||
rpc.TRANSPORT.conf.rpc_response_max_timeout = 300
|
||||
|
||||
def test_timeout_unaffected_when_explicitly_set(self):
|
||||
rpc.TRANSPORT.conf.rpc_response_timeout = 5
|
||||
@ -343,19 +344,19 @@ class TimeoutTestCase(base.BaseTestCase):
|
||||
for call in rpc.TRANSPORT._send.call_args_list]
|
||||
self.assertEqual([1, 2, 4, 8, 16], timeouts)
|
||||
|
||||
def test_method_timeout_10x_config_ceiling(self):
|
||||
def test_method_timeout_config_ceiling(self):
|
||||
rpc.TRANSPORT.conf.rpc_response_timeout = 10
|
||||
# 5 doublings should max out at the 10xdefault ceiling
|
||||
for i in range(5):
|
||||
with testtools.ExpectedException(messaging.MessagingTimeout):
|
||||
self.client.call(self.call_context, 'method_1')
|
||||
self.assertEqual(
|
||||
10 * rpc.TRANSPORT.conf.rpc_response_timeout,
|
||||
rpc.TRANSPORT.conf.rpc_response_max_timeout,
|
||||
rpc._BackingOffContextWrapper._METHOD_TIMEOUTS['method_1'])
|
||||
with testtools.ExpectedException(messaging.MessagingTimeout):
|
||||
self.client.call(self.call_context, 'method_1')
|
||||
self.assertEqual(
|
||||
10 * rpc.TRANSPORT.conf.rpc_response_timeout,
|
||||
rpc.TRANSPORT.conf.rpc_response_max_timeout,
|
||||
rpc._BackingOffContextWrapper._METHOD_TIMEOUTS['method_1'])
|
||||
|
||||
def test_timeout_unchanged_on_other_exception(self):
|
||||
@ -426,7 +427,8 @@ class TimeoutTestCase(base.BaseTestCase):
|
||||
def test_set_max_timeout_overrides_default_timeout(self):
|
||||
rpc.TRANSPORT.conf.rpc_response_timeout = 10
|
||||
self.assertEqual(
|
||||
10 * 10, rpc._BackingOffContextWrapper.get_max_timeout())
|
||||
rpc.TRANSPORT.conf.rpc_response_max_timeout,
|
||||
rpc._BackingOffContextWrapper.get_max_timeout())
|
||||
rpc._BackingOffContextWrapper.set_max_timeout(10)
|
||||
self.assertEqual(10, rpc._BackingOffContextWrapper.get_max_timeout())
|
||||
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
features:
|
||||
- Maximum rpc timeout is now configurable by ``rpc_response_max_timeout``
|
||||
from Neutron config instead of being calculated as ``10 *
|
||||
rpc_response_timeout`` value.
|
Loading…
Reference in New Issue
Block a user