From 6cc620ab270bc0d9f12a2ff3e3b439c7f4e10a90 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Tue, 3 Oct 2017 09:38:21 +0000 Subject: [PATCH] Block endpoint reg if cluster partially formed When an existing cluster of the service is scaled out the new unit will join with keystone before it is fully clustered. In identity joined hook the charmhelpers function canonical_url is called which in turn uses another charmhelpers function, resolve_address. resolve_address will only return the vip if the vip is set in config AND the unit is clustered. This means that the units local address is returned and that is then registered with keystone. This change gates registering an endpoint if the cluster is partially formed. Change-Id: I233e0cccb8ccd732080fd239df6d1e7db174eba5 Partial-Bug: #1544959 --- hooks/neutron_api_hooks.py | 6 ++++++ unit_tests/test_neutron_api_hooks.py | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/hooks/neutron_api_hooks.py b/hooks/neutron_api_hooks.py index ff4377b3..237092fe 100755 --- a/hooks/neutron_api_hooks.py +++ b/hooks/neutron_api_hooks.py @@ -27,6 +27,7 @@ from charmhelpers.core.hookenv import ( is_relation_made, local_unit, log, + DEBUG, ERROR, WARNING, relation_get, @@ -99,6 +100,7 @@ from neutron_api_context import ( from charmhelpers.contrib.hahelpers.cluster import ( get_hacluster_config, + is_clustered, is_elected_leader, ) @@ -395,6 +397,10 @@ def relation_broken(): @hooks.hook('identity-service-relation-joined') def identity_joined(rid=None, relation_trigger=False): + if config('vip') and not is_clustered(): + log('Defering registration until clustered', level=DEBUG) + return + public_url = '{}:{}'.format(canonical_url(CONFIGS, PUBLIC), api_port('neutron-server')) admin_url = '{}:{}'.format(canonical_url(CONFIGS, ADMIN), diff --git a/unit_tests/test_neutron_api_hooks.py b/unit_tests/test_neutron_api_hooks.py index a8b61ed0..a1a4fb5e 100644 --- a/unit_tests/test_neutron_api_hooks.py +++ b/unit_tests/test_neutron_api_hooks.py @@ -66,6 +66,7 @@ TO_PATCH = [ 'get_l2population', 'get_overlay_network_type', 'git_install', + 'is_clustered', 'is_elected_leader', 'is_relation_made', 'log', @@ -450,6 +451,12 @@ class NeutronAPIHooksTests(CharmTestCase): relation_settings=_endpoints ) + def test_identity_joined_partial_cluster(self): + self.is_clustered.return_value = False + self.test_config.set('vip', '10.0.0.10') + hooks.identity_joined() + self.assertFalse(self.relation_set.called) + @patch('charmhelpers.contrib.openstack.ip.service_name', lambda *args: 'neutron-api') @patch('charmhelpers.contrib.openstack.ip.unit_get')