From c706f499cb49a25ac264c06739b1e87077a5fae6 Mon Sep 17 00:00:00 2001 From: Nicolas Bock Date: Thu, 11 Mar 2021 09:35:55 -0700 Subject: [PATCH] Add 'heartbeat_timeout_threshold` option This change adds the `heartbeat_timeout_threshold` option to the `oslo_messaging_rabbit` section. It also cleans some uses of `conf.get()` to make use of the default `scope=None` parameter. Closes-Bug: #1918673 Signed-off-by: Nicolas Bock --- charmhelpers/contrib/openstack/context.py | 21 ++++++------------- .../templates/section-oslo-messaging-rabbit | 3 +++ tests/contrib/openstack/test_os_contexts.py | 12 +++++++++++ 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/charmhelpers/contrib/openstack/context.py b/charmhelpers/contrib/openstack/context.py index b67dafda8..41244fbc2 100644 --- a/charmhelpers/contrib/openstack/context.py +++ b/charmhelpers/contrib/openstack/context.py @@ -751,22 +751,13 @@ def __call__(self): ctxt['oslo_messaging_flags'] = config_flags_parser( oslo_messaging_flags) - oslo_messaging_driver = conf.get( + ctxt['oslo_messaging_driver'] = conf.get( 'oslo-messaging-driver', DEFAULT_OSLO_MESSAGING_DRIVER) - if oslo_messaging_driver: - ctxt['oslo_messaging_driver'] = oslo_messaging_driver - - notification_format = conf.get('notification-format', None) - if notification_format: - ctxt['notification_format'] = notification_format - - notification_topics = conf.get('notification-topics', None) - if notification_topics: - ctxt['notification_topics'] = notification_topics - - send_notifications_to_logs = conf.get('send-notifications-to-logs', None) - if send_notifications_to_logs: - ctxt['send_notifications_to_logs'] = send_notifications_to_logs + ctxt['notification_format'] = conf.get('notification-format') + ctxt['notification_topics'] = conf.get('notification-topics') + ctxt['send_notifications_to_logs'] = conf.get('send-notifications-to-logs') + ctxt['rabbit_heartbeat_timeout_threshold'] = conf.get( + 'rabbit-heartbeat-timeout-threshold') if not self.complete: return {} diff --git a/charmhelpers/contrib/openstack/templates/section-oslo-messaging-rabbit b/charmhelpers/contrib/openstack/templates/section-oslo-messaging-rabbit index bed2216ab..603810ba0 100644 --- a/charmhelpers/contrib/openstack/templates/section-oslo-messaging-rabbit +++ b/charmhelpers/contrib/openstack/templates/section-oslo-messaging-rabbit @@ -8,3 +8,6 @@ ssl = True {% if rabbit_ssl_ca -%} ssl_ca_file = {{ rabbit_ssl_ca }} {% endif -%} +{% if rabbit_heartbeat_timeout_threshold -%} +heartbeat_timeout_threshold = {{ rabbit_heartbeat_timeout_threshold }} +{% endif -%} diff --git a/tests/contrib/openstack/test_os_contexts.py b/tests/contrib/openstack/test_os_contexts.py index 3445d3e64..30b52903e 100644 --- a/tests/contrib/openstack/test_os_contexts.py +++ b/tests/contrib/openstack/test_os_contexts.py @@ -1291,6 +1291,7 @@ def test_amqp_context_with_data(self): result = amqp() expected = { 'oslo_messaging_driver': 'messagingv2', + 'rabbit_heartbeat_timeout_threshold': None, 'rabbitmq_host': 'rabbithost', 'rabbitmq_password': 'foobar', 'rabbitmq_user': 'adam', @@ -1309,6 +1310,7 @@ def test_amqp_context_explicit_relation_id(self): result = amqp() expected = { 'oslo_messaging_driver': 'messagingv2', + 'rabbit_heartbeat_timeout_threshold': None, 'rabbitmq_host': 'rabbitalthost1', 'rabbitmq_password': 'flump', 'rabbitmq_user': 'adam', @@ -1328,6 +1330,7 @@ def test_amqp_context_with_data_altname(self): result = amqp() expected = { 'oslo_messaging_driver': 'messagingv2', + 'rabbit_heartbeat_timeout_threshold': None, 'rabbitmq_host': 'rabbithost', 'rabbitmq_password': 'foobar', 'rabbitmq_user': 'adam', @@ -1347,6 +1350,7 @@ def test_amqp_context_with_data_ssl(self, _open): result = amqp() expected = { 'oslo_messaging_driver': 'messagingv2', + 'rabbit_heartbeat_timeout_threshold': None, 'rabbitmq_host': 'rabbithost', 'rabbitmq_password': 'foobar', 'rabbitmq_user': 'adam', @@ -1370,6 +1374,7 @@ def test_amqp_context_with_data_ssl_noca(self): result = amqp() expected = { 'oslo_messaging_driver': 'messagingv2', + 'rabbit_heartbeat_timeout_threshold': None, 'rabbitmq_host': 'rabbithost', 'rabbitmq_password': 'foobar', 'rabbitmq_user': 'adam', @@ -1393,6 +1398,7 @@ def test_amqp_context_with_data_clustered(self): expected = { 'oslo_messaging_driver': 'messagingv2', 'clustered': True, + 'rabbit_heartbeat_timeout_threshold': None, 'rabbitmq_host': relation_data['vip'], 'rabbitmq_password': 'foobar', 'rabbitmq_user': 'adam', @@ -1413,6 +1419,7 @@ def test_amqp_context_with_data_active_active(self): result = amqp() expected = { 'oslo_messaging_driver': 'messagingv2', + 'rabbit_heartbeat_timeout_threshold': None, 'rabbitmq_host': 'rabbithost1', 'rabbitmq_password': 'foobar', 'rabbitmq_user': 'adam', @@ -1458,6 +1465,7 @@ def test_amqp_context_with_ipv6(self, format_ipv6_addr): result = amqp() expected = { 'oslo_messaging_driver': 'messagingv2', + 'rabbit_heartbeat_timeout_threshold': None, 'rabbitmq_host': '[2001:db8:1::1]', 'rabbitmq_password': 'foobar', 'rabbitmq_user': 'adam', @@ -1477,6 +1485,7 @@ def test_amqp_context_with_oslo_messaging(self): amqp = context.AMQPContext() result = amqp() expected = { + 'rabbit_heartbeat_timeout_threshold': None, 'rabbitmq_host': 'rabbithost', 'rabbitmq_password': 'foobar', 'rabbitmq_user': 'adam', @@ -1502,6 +1511,7 @@ def test_amqp_context_with_notification_format(self): result = amqp() expected = { 'oslo_messaging_driver': 'messagingv2', + 'rabbit_heartbeat_timeout_threshold': None, 'rabbitmq_host': 'rabbithost', 'rabbitmq_password': 'foobar', 'rabbitmq_user': 'adam', @@ -1522,6 +1532,7 @@ def test_amqp_context_with_notification_topics(self): result = amqp() expected = { 'oslo_messaging_driver': 'messagingv2', + 'rabbit_heartbeat_timeout_threshold': None, 'rabbitmq_host': 'rabbithost', 'rabbitmq_password': 'foobar', 'rabbitmq_user': 'adam', @@ -1542,6 +1553,7 @@ def test_amqp_context_with_notifications_to_logs(self): result = amqp() expected = { 'oslo_messaging_driver': 'messagingv2', + 'rabbit_heartbeat_timeout_threshold': None, 'rabbitmq_host': 'rabbithost', 'rabbitmq_password': 'foobar', 'rabbitmq_user': 'adam',