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
This commit is contained in:
Liam Young 2017-10-03 09:38:21 +00:00
parent ea08e0af12
commit 6cc620ab27
2 changed files with 13 additions and 0 deletions

View File

@ -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),

View File

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