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.