summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorey Bryant <corey.bryant@canonical.com>2018-03-21 12:40:22 +0000
committerCorey Bryant <corey.bryant@canonical.com>2018-03-21 14:17:33 +0000
commit8893bace59853c6379659a94f81c1a4a5cc095d1 (patch)
treea9b37072992e788ab1a7b7ff204791c82faae370
parent1cd062efde836bfa643a593394be83b3b8dd9bcf (diff)
Ensure only the leader can add hosts to cell
Ensure that only the elected leader can add compute hosts to the cell in cloud-compute-relation-changed as database commands should only be run by the elected leader. Change-Id: I4806580f58e2a2feba82c74d9d5ff29dfb220c9e Closes-Bug: #1752402
Notes
Notes (review): Code-Review+2: Liam Young <liam.young@canonical.com> Verified+1: Canonical CI <uosci-testing-bot@ubuntu.com> Workflow+1: Ryan Beisner <ryan.beisner@canonical.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 21 Mar 2018 17:47:11 +0000 Reviewed-on: https://review.openstack.org/554931 Project: openstack/charm-nova-cloud-controller Branch: refs/heads/master
-rwxr-xr-xhooks/nova_cc_hooks.py2
-rw-r--r--unit_tests/test_nova_cc_hooks.py32
2 files changed, 33 insertions, 1 deletions
diff --git a/hooks/nova_cc_hooks.py b/hooks/nova_cc_hooks.py
index 6120a72..48e1cba 100755
--- a/hooks/nova_cc_hooks.py
+++ b/hooks/nova_cc_hooks.py
@@ -649,7 +649,7 @@ def compute_changed(rid=None, unit=None):
649 if not rel_settings.get('region', None) == config('region'): 649 if not rel_settings.get('region', None) == config('region'):
650 relation_set(relation_id=rid, region=config('region')) 650 relation_set(relation_id=rid, region=config('region'))
651 651
652 if is_cellv2_init_ready() and is_db_initialised(): 652 if is_leader() and is_cellv2_init_ready() and is_db_initialised():
653 add_hosts_to_cell() 653 add_hosts_to_cell()
654 654
655 if 'migration_auth_type' not in rel_settings: 655 if 'migration_auth_type' not in rel_settings:
diff --git a/unit_tests/test_nova_cc_hooks.py b/unit_tests/test_nova_cc_hooks.py
index 12a12ad..8c8a376 100644
--- a/unit_tests/test_nova_cc_hooks.py
+++ b/unit_tests/test_nova_cc_hooks.py
@@ -318,6 +318,38 @@ class NovaCCHooksTests(CharmTestCase):
318 self.assertEqual(sorted(self.relation_set.call_args_list), 318 self.assertEqual(sorted(self.relation_set.call_args_list),
319 sorted(expected_relations)) 319 sorted(expected_relations))
320 320
321 @patch.object(hooks, 'is_cellv2_init_ready')
322 @patch.object(hooks, 'is_db_initialised')
323 @patch.object(hooks, 'add_hosts_to_cell')
324 def test_compute_changed_add_hosts_leader(self,
325 mock_add_hosts_to_cell,
326 mock_is_db_initialised,
327 mock_is_cellv2_init_ready):
328 self.is_leader.return_value = True
329 mock_is_db_initialised.return_value = True
330 mock_is_cellv2_init_ready.return_value = True
331 hooks.compute_changed()
332 self.assertTrue(self.is_leader.called)
333 self.assertTrue(mock_is_db_initialised.called)
334 self.assertTrue(mock_is_cellv2_init_ready.called)
335 self.assertTrue(mock_add_hosts_to_cell.called)
336
337 @patch.object(hooks, 'is_cellv2_init_ready')
338 @patch.object(hooks, 'is_db_initialised')
339 @patch.object(hooks, 'add_hosts_to_cell')
340 def test_compute_changed_add_hosts_nonleader(self,
341 mock_add_hosts_to_cell,
342 mock_is_db_initialised,
343 mock_is_cellv2_init_ready):
344 self.is_leader.return_value = False
345 mock_is_db_initialised.return_value = True
346 mock_is_cellv2_init_ready.return_value = True
347 hooks.compute_changed()
348 self.assertTrue(self.is_leader.called)
349 self.assertFalse(mock_is_db_initialised.called)
350 self.assertFalse(mock_is_cellv2_init_ready.called)
351 self.assertFalse(mock_add_hosts_to_cell.called)
352
321 @patch.object(hooks, 'canonical_url') 353 @patch.object(hooks, 'canonical_url')
322 @patch.object(utils, 'config') 354 @patch.object(utils, 'config')
323 @patch.object(hooks, '_auth_config') 355 @patch.object(hooks, '_auth_config')