Do not access DB when it is in maintenance mode.

If the database is in maintenace mode do not attempt to access
it.

Depends-On: I5d8ed7d3935db5568c50f8d585e37a4d0cc6914f
Change-Id: Ib654a82fd91cd73c6ab5c178d87d054d8717ce4f
This commit is contained in:
Liam Young 2020-01-30 12:37:29 +00:00
parent d3e2fbfb37
commit e74c9a4d5f
2 changed files with 7 additions and 0 deletions

View File

@ -65,6 +65,7 @@ from charmhelpers.contrib.openstack.utils import (
series_upgrade_complete,
series_upgrade_prepare,
sync_db_with_multi_ipv6_addresses,
is_db_maintenance_mode,
)
from charmhelpers.contrib.openstack.ha.utils import (
@ -252,6 +253,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.')
return
if 'shared-db' not in CONFIGS.complete_contexts():
log('shared-db relation incomplete. Peer not ready?')
return

View File

@ -81,6 +81,7 @@ TO_PATCH = [
'relation_get',
'local_unit',
'get_relation_ip',
'is_db_maintenance_mode',
]
@ -187,6 +188,7 @@ class HeatRelationTests(CharmTestCase):
self.assertTrue(self.get_relation_ip.called)
def _shared_db_test(self, configs):
self.is_db_maintenance_mode.return_value = False
self.relation_get.return_value = 'heat/0 heat/1'
self.local_unit.return_value = 'heat/0'
configs.complete_contexts = MagicMock()
@ -203,6 +205,7 @@ class HeatRelationTests(CharmTestCase):
@patch.object(relations, 'CONFIGS')
def test_db_changed_missing_relation_data(self, configs):
self.is_db_maintenance_mode.return_value = False
configs.complete_contexts = MagicMock()
configs.complete_contexts.return_value = []
relations.db_changed()