From 6fafb5abc5536e5333467324629e67bf2489bf3a Mon Sep 17 00:00:00 2001 From: Liam Young Date: Thu, 30 Jan 2020 12:37:43 +0000 Subject: [PATCH] Do not access DB when it is in maintenance mode. If the database is in maintenace mode do not attempt to access it. Change-Id: I42cc19aedff2bc060343f4431c1b4834f9389f03 Depends-On: I5d8ed7d3935db5568c50f8d585e37a4d0cc6914f --- hooks/neutron_api_hooks.py | 4 ++++ unit_tests/test_neutron_api_hooks.py | 3 +++ 2 files changed, 7 insertions(+) diff --git a/hooks/neutron_api_hooks.py b/hooks/neutron_api_hooks.py index a053ab22..1e19aeb6 100755 --- a/hooks/neutron_api_hooks.py +++ b/hooks/neutron_api_hooks.py @@ -66,6 +66,7 @@ from charmhelpers.contrib.openstack.utils import ( CompareOpenStackReleases, series_upgrade_prepare, series_upgrade_complete, + is_db_maintenance_mode, ) from neutron_api_utils import ( @@ -406,6 +407,9 @@ def db_joined(): @hooks.hook('shared-db-relation-changed') @restart_on_change(restart_map()) def db_changed(): + if is_db_maintenance_mode(): + log('Database maintenance mode, aborting hook.', level=DEBUG) + return if 'shared-db' not in CONFIGS.complete_contexts(): log('shared-db relation incomplete. Peer not ready?') return diff --git a/unit_tests/test_neutron_api_hooks.py b/unit_tests/test_neutron_api_hooks.py index ace869b8..f1f0724a 100644 --- a/unit_tests/test_neutron_api_hooks.py +++ b/unit_tests/test_neutron_api_hooks.py @@ -97,6 +97,7 @@ TO_PATCH = [ 'is_db_initialised', 'maybe_do_policyd_overrides', 'maybe_do_policyd_overrides_on_config_changed', + 'is_db_maintenance_mode', ] NEUTRON_CONF_DIR = "/etc/neutron" @@ -293,6 +294,7 @@ class NeutronAPIHooksTests(CharmTestCase): @patch.object(hooks, 'neutron_plugin_api_subordinate_relation_joined') @patch.object(hooks, 'conditional_neutron_migration') def test_shared_db_changed(self, cond_neutron_mig, plugin_joined): + self.is_db_maintenance_mode.return_value = False self.CONFIGS.complete_contexts.return_value = ['shared-db'] self.relation_ids.return_value = ['neutron-plugin-api-subordinate:1'] self._call_hook('shared-db-relation-changed') @@ -303,6 +305,7 @@ class NeutronAPIHooksTests(CharmTestCase): relid='neutron-plugin-api-subordinate:1') def test_shared_db_changed_partial_ctxt(self): + self.is_db_maintenance_mode.return_value = False self.CONFIGS.complete_contexts.return_value = [] self._call_hook('shared-db-relation-changed') self.assertFalse(self.CONFIGS.write_all.called)