Add queue-master-locator config option

queue-master-locator is a configuration option supported by
rabbitmq-server since 3.6, it allows to have control of where the
master queue will be created.

Change-Id: I38cc019b73d062572e19bd532b6bccdaf88638ba
Func-Test-PR: https://github.com/openstack-charmers/zaza-openstack-tests/pull/382
Closes-Bug: #1890759
Signed-off-by: Nicolas Bock <nicolas.bock@canonical.com>
This commit is contained in:
Felipe Reyes 2020-08-10 23:49:02 -04:00
parent 48b86fdb7a
commit 07ec03b5d7
4 changed files with 65 additions and 5 deletions

View File

@ -306,3 +306,12 @@ options:
When using nrpe to monitor the Rabbitmq host, we monitor functionality on
one vhost. This option configures additional vhost name(s) to check.
Space separated list.
queue-master-locator:
type: string
default: min-masters
description: |
Queue master location strategy. Available strategies are:
- min-masters, Pick the node hosting the minimum number of bound masters.
- client-local, Pick the node the client that declares the queue is connected to.
- random, Pick a random node.
This option is only available for RabbitMQ >= 3.6

View File

@ -22,7 +22,7 @@ import sys
import ssl_utils
from charmhelpers.contrib.ssl.service import ServiceCA
from charmhelpers.core.host import is_container
from charmhelpers.core.host import is_container, cmp_pkgrevno
from charmhelpers.fetch import apt_install
from charmhelpers.core.hookenv import (
open_port,
@ -186,6 +186,9 @@ class RabbitMQClusterContext(object):
if config('connection-backlog'):
ctxt['connection_backlog'] = config('connection-backlog')
if cmp_pkgrevno('rabbitmq-server', '3.6') >= 0:
ctxt['queue_master_locator'] = config('queue-master-locator')
return ctxt

View File

@ -31,7 +31,9 @@
{%- endif %}
]},
{%- endif %}
{%- if queue_master_locator %}
{queue_master_locator, <<"{{ queue_master_locator }}">>},
{%- endif %}
{%- if cluster_partition_handling %}
{cluster_partition_handling, {{ cluster_partition_handling }}}
{%- endif %}

View File

@ -84,18 +84,64 @@ class TestRabbitMQSSLContext(unittest.TestCase):
class TestRabbitMQClusterContext(unittest.TestCase):
@mock.patch.object(rabbitmq_context, 'cmp_pkgrevno')
@mock.patch("rabbitmq_context.config")
def test_context_ssl_off(self, config):
config.return_value = "ignore"
def test_context_ssl_off(self, config, mock_cmp_pkgrevno):
config_data = {'cluster-partition-handling': 'ignore',
'connection-backlog': 200,
'queue-master-locator': 'client-local'}
config.side_effect = config_data.get
mock_cmp_pkgrevno.return_value = 0
self.assertEqual(
rabbitmq_context.RabbitMQClusterContext().__call__(), {
'cluster_partition_handling': "ignore",
'connection_backlog': "ignore"
'connection_backlog': 200,
'queue_master_locator': 'client-local',
})
config.assert_has_calls([mock.call("cluster-partition-handling"),
mock.call("connection-backlog")],
mock.call('queue-master-locator'))
@mock.patch.object(rabbitmq_context, 'cmp_pkgrevno')
@mock.patch("rabbitmq_context.config")
def test_queue_master_locator_min_masters(self, config, mock_cmp_pkgrevno):
config_data = {'cluster-partition-handling': 'ignore',
'connection-backlog': 200,
'queue-master-locator': 'min-masters'}
config.side_effect = config_data.get
mock_cmp_pkgrevno.return_value = 0
self.assertEqual(
rabbitmq_context.RabbitMQClusterContext().__call__(), {
'cluster_partition_handling': "ignore",
'connection_backlog': 200,
'queue_master_locator': 'min-masters',
})
config.assert_has_calls([mock.call("cluster-partition-handling"),
mock.call("connection-backlog")],
mock.call('queue-master-locator'))
@mock.patch.object(rabbitmq_context, 'cmp_pkgrevno')
@mock.patch("rabbitmq_context.config")
def test_rabbit_server_3pt6(self, config, mock_cmp_pkgrevno):
config_data = {'cluster-partition-handling': 'ignore',
'queue-master-locator': 'min-masters',
'connection-backlog': 200}
config.side_effect = config_data.get
mock_cmp_pkgrevno.return_value = -1
self.assertEqual(
rabbitmq_context.RabbitMQClusterContext().__call__(), {
'cluster_partition_handling': "ignore",
'connection_backlog': 200,
})
config.assert_has_calls([mock.call("cluster-partition-handling"),
mock.call("connection-backlog")])
assert mock.call('queue-master-locator') not in config.mock_calls
class TestRabbitMQEnvContext(unittest.TestCase):