From 24e359957214893326aa5940bccc8b7399d35350 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Tue, 3 Oct 2017 13:21:39 +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: Icf2753b6b21347af8106ebad03d81309177d09f2 Partial-Bug: #1544959 --- hooks/ceilometer_hooks.py | 6 ++++++ unit_tests/test_ceilometer_hooks.py | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/hooks/ceilometer_hooks.py b/hooks/ceilometer_hooks.py index c375a3f..e85ef97 100755 --- a/hooks/ceilometer_hooks.py +++ b/hooks/ceilometer_hooks.py @@ -34,6 +34,7 @@ from charmhelpers.core.hookenv import ( log, status_set, WARNING, + DEBUG, ) from charmhelpers.core.host import ( service_restart, @@ -84,6 +85,7 @@ from charmhelpers.contrib.network.ip import ( ) from charmhelpers.contrib.hahelpers.cluster import ( get_hacluster_config, + is_clustered, is_elected_leader ) from charmhelpers.contrib.peerstorage import ( @@ -350,6 +352,10 @@ def ha_changed(): @hooks.hook("identity-service-relation-joined") def keystone_joined(relid=None): + if config('vip') and not is_clustered(): + log('Defering registration until clustered', level=DEBUG) + return + public_url = "{}:{}".format( canonical_url(CONFIGS, PUBLIC), CEILOMETER_PORT diff --git a/unit_tests/test_ceilometer_hooks.py b/unit_tests/test_ceilometer_hooks.py index 5c8ca4b..b2d8440 100644 --- a/unit_tests/test_ceilometer_hooks.py +++ b/unit_tests/test_ceilometer_hooks.py @@ -68,6 +68,7 @@ TO_PATCH = [ 'mkdir', 'init_is_systemd', 'get_relation_ip', + 'is_clustered', ] @@ -264,6 +265,12 @@ class CeilometerHooksTest(CharmTestCase): requested_roles=hooks.CEILOMETER_ROLE, region='myregion', relation_id=None) + def test_keystone_joined_partial_cluster(self): + self.is_clustered.return_value = False + self.test_config.set('vip', '10.0.0.10') + hooks.keystone_joined() + self.assertFalse(self.relation_set.called) + @patch('charmhelpers.core.hookenv.config') def test_ceilometer_joined(self, mock_config): self.relation_ids.return_value = ['ceilometer:0']