From af902dfb2ac8e5bc253af8fb85bc4d0f61bdfa56 Mon Sep 17 00:00:00 2001 From: nicky Date: Thu, 20 Dec 2018 13:24:00 +0800 Subject: [PATCH] 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 Change-Id: I45d2e5c063d2dd43cb8aec1d46faa3ee8ea4825f Depends-on: https://review.openstack.org/#/c/626109 Related-Bug: #1805769 Story: 2004456 Task: 28171 --- neutron_lib/rpc.py | 6 +++++- neutron_lib/tests/unit/test_rpc.py | 10 ++++++---- ...tter-for-a-newly-added-option-2082877bf7dd136b.yaml | 5 +++++ 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 releasenotes/notes/add-a-getter-for-a-newly-added-option-2082877bf7dd136b.yaml diff --git a/neutron_lib/rpc.py b/neutron_lib/rpc.py index 5716c2dc2..5644fbdb2 100644 --- a/neutron_lib/rpc.py +++ b/neutron_lib/rpc.py @@ -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): diff --git a/neutron_lib/tests/unit/test_rpc.py b/neutron_lib/tests/unit/test_rpc.py index 2c688afa0..b784e4ad7 100644 --- a/neutron_lib/tests/unit/test_rpc.py +++ b/neutron_lib/tests/unit/test_rpc.py @@ -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()) diff --git a/releasenotes/notes/add-a-getter-for-a-newly-added-option-2082877bf7dd136b.yaml b/releasenotes/notes/add-a-getter-for-a-newly-added-option-2082877bf7dd136b.yaml new file mode 100644 index 000000000..a97c4464e --- /dev/null +++ b/releasenotes/notes/add-a-getter-for-a-newly-added-option-2082877bf7dd136b.yaml @@ -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.