From df711c6717fffdd6d4285b5b2b318ead90fa51fa Mon Sep 17 00:00:00 2001 From: Liam Young Date: Wed, 24 Nov 2021 15:46:36 +0000 Subject: [PATCH] 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 --- config.yaml | 6 ++++-- hooks/rabbit_utils.py | 21 +++++++++++++++++--- hooks/rabbitmq_server_relations.py | 2 +- unit_tests/test_rabbit_utils.py | 17 ++++++++++++++++ unit_tests/test_rabbitmq_server_relations.py | 1 + 5 files changed, 41 insertions(+), 6 deletions(-) diff --git a/config.yaml b/config.yaml index 2245653a..03165f3a 100644 --- a/config.yaml +++ b/config.yaml @@ -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 diff --git a/hooks/rabbit_utils.py b/hooks/rabbit_utils.py index 39793031..d5cfaa54 100644 --- a/hooks/rabbit_utils.py +++ b/hooks/rabbit_utils.py @@ -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) diff --git a/hooks/rabbitmq_server_relations.py b/hooks/rabbitmq_server_relations.py index d477dcfc..9371fa5c 100755 --- a/hooks/rabbitmq_server_relations.py +++ b/hooks/rabbitmq_server_relations.py @@ -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: diff --git a/unit_tests/test_rabbit_utils.py b/unit_tests/test_rabbit_utils.py index 0faf1485..6cad32f9 100644 --- a/unit_tests/test_rabbit_utils.py +++ b/unit_tests/test_rabbit_utils.py @@ -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()) diff --git a/unit_tests/test_rabbitmq_server_relations.py b/unit_tests/test_rabbitmq_server_relations.py index a67a7eec..28bc698d 100644 --- a/unit_tests/test_rabbitmq_server_relations.py +++ b/unit_tests/test_rabbitmq_server_relations.py @@ -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),