Switch to enabling the managment plugin by default
Over time the managment plugin has become a core part of managing a rabbit deployment. This includes allowing tools such as nrpe to be able to query the api and alert for situations such as orphaned queues. Change-Id: Icbf760610ce83b9d95f48e99f6607ddf23963c97 Partial-Bug: 1930547
This commit is contained in:
parent
32bce11f0f
commit
df711c6717
|
@ -28,8 +28,10 @@ options:
|
|||
to run. Supported modules currently include os, ssh, apache and mysql.
|
||||
management_plugin:
|
||||
type: boolean
|
||||
default: False
|
||||
description: Enable the management plugin.
|
||||
default: True
|
||||
description: |
|
||||
Enable the management plugin. This only applys to deployments using
|
||||
Focal or later.
|
||||
mirroring-queues:
|
||||
type: boolean
|
||||
default: True
|
||||
|
|
|
@ -89,6 +89,8 @@ from charmhelpers.core.host import (
|
|||
write_file,
|
||||
cmp_pkgrevno,
|
||||
rsync,
|
||||
lsb_release,
|
||||
CompareHostReleases,
|
||||
)
|
||||
|
||||
from charmhelpers.contrib.peerstorage import (
|
||||
|
@ -1421,6 +1423,19 @@ def remove_file(path):
|
|||
log('{} file does not exist'.format(path), level='DEBUG')
|
||||
|
||||
|
||||
def management_plugin_enabled():
|
||||
"""Check if management plugin should be enabled.
|
||||
|
||||
:returns: Whether anagement plugin should be enabled
|
||||
:rtype: bool
|
||||
"""
|
||||
_release = lsb_release()['DISTRIB_CODENAME'].lower()
|
||||
if CompareHostReleases(_release) < "bionic":
|
||||
return False
|
||||
else:
|
||||
return config('management_plugin') is True
|
||||
|
||||
|
||||
def sync_nrpe_files():
|
||||
"""Sync all NRPE-related files.
|
||||
|
||||
|
@ -1436,7 +1451,7 @@ def sync_nrpe_files():
|
|||
if config('queue_thresholds') and config('stats_cron_schedule'):
|
||||
rsync(os.path.join(charm_dir(), 'files', 'check_rabbitmq_queues.py'),
|
||||
os.path.join(NAGIOS_PLUGINS, 'check_rabbitmq_queues.py'))
|
||||
if config('management_plugin'):
|
||||
if management_plugin_enabled():
|
||||
rsync(os.path.join(charm_dir(), 'files', 'check_rabbitmq_cluster.py'),
|
||||
os.path.join(NAGIOS_PLUGINS, 'check_rabbitmq_cluster.py'))
|
||||
|
||||
|
@ -1467,7 +1482,7 @@ def remove_nrpe_files():
|
|||
# `stats_cron_schedule` isn't in the config
|
||||
remove_file(os.path.join(NAGIOS_PLUGINS, 'check_rabbitmq_queues.py'))
|
||||
|
||||
if not config('management_plugin'):
|
||||
if not management_plugin_enabled():
|
||||
# This script is redundant if the value `management_plugin` isn't
|
||||
# in the config
|
||||
remove_file(os.path.join(NAGIOS_PLUGINS, 'check_rabbitmq_cluster.py'))
|
||||
|
@ -1676,7 +1691,7 @@ def nrpe_update_cluster_check(nrpe_compat, user, password):
|
|||
:param password: password of NRPE user
|
||||
:type: str
|
||||
"""
|
||||
if config('management_plugin'):
|
||||
if management_plugin_enabled():
|
||||
cmd = '{}/check_rabbitmq_cluster.py --port {} ' \
|
||||
'--user {} --password {}'.format(
|
||||
NAGIOS_PLUGINS, get_managment_port(), user, password)
|
||||
|
|
|
@ -722,7 +722,7 @@ def config_changed(check_deferred_restarts=True):
|
|||
chown(RABBIT_DIR, rabbit.RABBIT_USER, rabbit.RABBIT_USER)
|
||||
chmod(RABBIT_DIR, 0o775)
|
||||
|
||||
if config('management_plugin') is True:
|
||||
if rabbit.management_plugin_enabled():
|
||||
rabbit.enable_plugin(MAN_PLUGIN)
|
||||
open_port(rabbit.get_managment_port())
|
||||
else:
|
||||
|
|
|
@ -47,6 +47,7 @@ TO_PATCH = [
|
|||
'config',
|
||||
'is_unit_paused_set',
|
||||
'local_unit',
|
||||
'lsb_release',
|
||||
]
|
||||
|
||||
|
||||
|
@ -158,6 +159,8 @@ class UtilsTests(CharmTestCase):
|
|||
self.nrpe_compat = mock.MagicMock()
|
||||
self.nrpe_compat.add_check = mock.MagicMock()
|
||||
self.nrpe_compat.remove_check = mock.MagicMock()
|
||||
self.lsb_release.return_value = {
|
||||
'DISTRIB_CODENAME': 'focal'}
|
||||
|
||||
def tearDown(self):
|
||||
super(UtilsTests, self).tearDown()
|
||||
|
@ -1453,3 +1456,17 @@ class UtilsTests(CharmTestCase):
|
|||
self.assertEqual(generated_policy, policy)
|
||||
|
||||
mock_set_policy.reset_mock()
|
||||
|
||||
@mock.patch('rabbit_utils.config')
|
||||
def test_management_plugin_enabled(self, mock_config):
|
||||
mock_config.side_effect = self.test_config
|
||||
self.lsb_release.return_value = {
|
||||
'DISTRIB_CODENAME': 'focal'}
|
||||
self.test_config.set('management_plugin', True)
|
||||
self.assertTrue(rabbit_utils.management_plugin_enabled())
|
||||
self.test_config.set('management_plugin', False)
|
||||
self.assertFalse(rabbit_utils.management_plugin_enabled())
|
||||
self.lsb_release.return_value = {
|
||||
'DISTRIB_CODENAME': 'xenial'}
|
||||
self.test_config.set('management_plugin', True)
|
||||
self.assertFalse(rabbit_utils.management_plugin_enabled())
|
||||
|
|
|
@ -419,6 +419,7 @@ class RelationUtil(CharmTestCase):
|
|||
mock_add_check.reset_mock()
|
||||
mock_remove_check.reset_mock()
|
||||
self.test_config.unset('stats_cron_schedule')
|
||||
self.test_config.set('management_plugin', False)
|
||||
rabbitmq_server_relations.update_nrpe_checks()
|
||||
mock_remove_file.assert_has_calls([
|
||||
call(stats_confile),
|
||||
|
|
Loading…
Reference in New Issue