Skip to content

Commit

Permalink
Add queue-master-locator config option
Browse files Browse the repository at this point in the history
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: openstack-charmers/zaza-openstack-tests#382
Closes-Bug: #1890759
Signed-off-by: Nicolas Bock <nicolas.bock@canonical.com>
  • Loading branch information
freyes committed Dec 13, 2020
1 parent 48b86fd commit 07ec03b
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 5 deletions.
9 changes: 9 additions & 0 deletions config.yaml
Expand Up @@ -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
5 changes: 4 additions & 1 deletion hooks/rabbitmq_context.py
Expand Up @@ -22,7 +22,7 @@
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,
Expand Down Expand Up @@ -186,6 +186,9 @@ def __call__(self):
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


Expand Down
4 changes: 3 additions & 1 deletion templates/rabbitmq.config
Expand Up @@ -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 %}
Expand Down
52 changes: 49 additions & 3 deletions unit_tests/test_rabbitmq_context.py
Expand Up @@ -84,18 +84,64 @@ class Uid(object):

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):
Expand Down

0 comments on commit 07ec03b

Please sign in to comment.