summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Mooney <work@seanmooney.info>2020-10-12 22:43:31 +0100
committerSean Mooney <work@seanmooney.info>2020-10-13 12:44:30 +0100
commit00d15eaeaba0ded0330cdcec7b19eee3adbfb1e1 (patch)
treec6bb6cb67a01a37f4bbc3e442f7e6e0a93f38c79
parenta997f09e5bd9ce98cc57f1a5380453ff167e47ca (diff)
downloadoslo-messaging-00d15eaeaba0ded0330cdcec7b19eee3adbfb1e1.tar.gz
add min of 1 to rpc_conn_pool_size
This change add a min value of 1 to [oslo_messaging_rabbit]/rpc_conn_pool_size such that there is always at least 1 connection avaiable. This change add a runtime check to ensure that [oslo_messaging_rabbit]/rpc_conn_pool_size is greater than or equal too [oslo_messaging_rabbit]/conn_pool_min_size Change-Id: I2ad4b9f1d012c9f0586a932ac27d96da1bcc4e4c Closes-Bug: #1899533
-rw-r--r--oslo_messaging/_drivers/base.py3
-rw-r--r--oslo_messaging/_drivers/impl_rabbit.py4
-rw-r--r--oslo_messaging/tests/drivers/test_impl_rabbit.py15
3 files changed, 21 insertions, 1 deletions
diff --git a/oslo_messaging/_drivers/base.py b/oslo_messaging/_drivers/base.py
index 2947e6d..a03c1d7 100644
--- a/oslo_messaging/_drivers/base.py
+++ b/oslo_messaging/_drivers/base.py
@@ -24,7 +24,8 @@ from oslo_messaging import exceptions
base_opts = [
cfg.IntOpt('rpc_conn_pool_size', default=30,
deprecated_group='DEFAULT',
- help='Size of RPC connection pool.'),
+ help='Size of RPC connection pool.',
+ min=1),
cfg.IntOpt('conn_pool_min_size', default=2,
help='The pool size limit for connections expiration policy'),
cfg.IntOpt('conn_pool_ttl', default=1200,
diff --git a/oslo_messaging/_drivers/impl_rabbit.py b/oslo_messaging/_drivers/impl_rabbit.py
index 2f48541..a4524d9 100644
--- a/oslo_messaging/_drivers/impl_rabbit.py
+++ b/oslo_messaging/_drivers/impl_rabbit.py
@@ -1387,6 +1387,10 @@ class RabbitDriver(amqpdriver.AMQPDriverBase):
# the pool configuration properties
max_size = conf.oslo_messaging_rabbit.rpc_conn_pool_size
min_size = conf.oslo_messaging_rabbit.conn_pool_min_size
+ if max_size < min_size:
+ raise RuntimeError(
+ f"rpc_conn_pool_size: {max_size} must be greater than "
+ f"or equal to conn_pool_min_size: {min_size}")
ttl = conf.oslo_messaging_rabbit.conn_pool_ttl
connection_pool = pool.ConnectionPool(
diff --git a/oslo_messaging/tests/drivers/test_impl_rabbit.py b/oslo_messaging/tests/drivers/test_impl_rabbit.py
index e70a778..e035150 100644
--- a/oslo_messaging/tests/drivers/test_impl_rabbit.py
+++ b/oslo_messaging/tests/drivers/test_impl_rabbit.py
@@ -33,6 +33,7 @@ from oslo_messaging._drivers import common as driver_common
from oslo_messaging._drivers import impl_rabbit as rabbit_driver
from oslo_messaging.exceptions import MessageDeliveryFailure
from oslo_messaging.tests import utils as test_utils
+from oslo_messaging.transport import DriverLoadFailure
from unittest import mock
load_tests = testscenarios.load_tests_apply_scenarios
@@ -143,6 +144,20 @@ class TestRabbitDriverLoad(test_utils.BaseTestCase):
self.assertIsInstance(driver, rabbit_driver.RabbitDriver)
+ @mock.patch('oslo_messaging._drivers.impl_rabbit.Connection'
+ '.ensure_connection')
+ @mock.patch('oslo_messaging._drivers.impl_rabbit.Connection.reset')
+ def test_driver_load_max_less_than_min(self, fake_ensure, fake_reset):
+ self.config(
+ rpc_conn_pool_size=1, conn_pool_min_size=2,
+ group='oslo_messaging_rabbit')
+ self.messaging_conf.transport_url = self.transport_url
+ error = self.assertRaises(
+ DriverLoadFailure, oslo_messaging.get_transport, self.conf)
+ self.assertIn(
+ "rpc_conn_pool_size: 1 must be greater than or equal "
+ "to conn_pool_min_size: 2", str(error))
+
class TestRabbitDriverLoadSSL(test_utils.BaseTestCase):
scenarios = [