We cannot talk to the database during maintenance

Change-Id: Ie0d58c3f11b34d5fd6354c3f2130e8618e49b915
Closes-Bug: #1871647
This commit is contained in:
Chris MacNaughton 2020-04-08 16:09:25 +02:00
parent 793daaef3e
commit 65ed6620c7
2 changed files with 21 additions and 1 deletions

View File

@ -684,7 +684,8 @@ def add_hosts_to_cell_when_ready():
"""
if (hookenv.is_leader() and
ncc_utils.is_cellv2_init_ready() and
ncc_utils.is_db_initialised()):
ncc_utils.is_db_initialised() and
not ch_utils.is_db_maintenance_mode()):
ncc_utils.add_hosts_to_cell()

View File

@ -551,6 +551,7 @@ class NovaCCHooksTests(CharmTestCase):
self.assertTrue(self.is_leader.called)
self.assertTrue(mock_is_db_initialised.called)
self.assertTrue(mock_is_cellv2_init_ready.called)
self.assertTrue(self.is_db_maintenance_mode.called)
self.assertTrue(mock_add_hosts_to_cell.called)
@patch('hooks.nova_cc_utils.is_cellv2_init_ready')
@ -567,6 +568,24 @@ class NovaCCHooksTests(CharmTestCase):
self.assertTrue(self.is_leader.called)
self.assertFalse(mock_is_db_initialised.called)
self.assertFalse(mock_is_cellv2_init_ready.called)
self.assertFalse(self.is_db_maintenance_mode.called)
self.assertFalse(mock_add_hosts_to_cell.called)
@patch('hooks.nova_cc_utils.is_cellv2_init_ready')
@patch('hooks.nova_cc_utils.is_db_initialised')
@patch('hooks.nova_cc_utils.add_hosts_to_cell')
def test_add_hosts_to_cell_when_database_maintenance(
self, mock_add_hosts_to_cell, mock_is_db_initialised,
mock_is_cellv2_init_ready):
self.is_leader.return_value = True
mock_is_db_initialised.return_value = True
mock_is_cellv2_init_ready.return_value = True
self.is_db_maintenance_mode.return_value = True
hooks.add_hosts_to_cell_when_ready()
self.assertTrue(self.is_leader.called)
self.assertTrue(mock_is_db_initialised.called)
self.assertTrue(mock_is_cellv2_init_ready.called)
self.assertTrue(self.is_db_maintenance_mode.called)
self.assertFalse(mock_add_hosts_to_cell.called)
@patch('charmhelpers.contrib.openstack.ip.canonical_url')