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')