Network space aware address for cluster relation
Use the get_relation_ip function for selecting addresses for the cluster relationship. Including overrides for the admin, internal, and public config settings or extra bindings. Partial-Bug: #1687439 Change-Id: I49f8039f069ba51a6eca58949106507d27af5302
This commit is contained in:
parent
5eaf8e3cf2
commit
3c91613af5
|
@ -108,8 +108,6 @@ from charmhelpers.payload.execd import execd_preinstall
|
|||
from charmhelpers.contrib.network.ip import (
|
||||
get_iface_for_address,
|
||||
get_netmask_for_address,
|
||||
get_address_in_network,
|
||||
get_ipv6_addr,
|
||||
is_ipv6,
|
||||
get_relation_ip,
|
||||
)
|
||||
|
@ -429,25 +427,23 @@ def ceph_broken():
|
|||
|
||||
@hooks.hook('cluster-relation-joined')
|
||||
def cluster_joined(relation_id=None):
|
||||
settings = {}
|
||||
|
||||
for addr_type in ADDRESS_TYPES:
|
||||
address = get_address_in_network(
|
||||
config('os-{}-network'.format(addr_type))
|
||||
)
|
||||
address = get_relation_ip(
|
||||
addr_type,
|
||||
cidr_network=config('os-{}-network'.format(addr_type)))
|
||||
if address:
|
||||
relation_set(
|
||||
relation_id=relation_id,
|
||||
relation_settings={'{}-address'.format(addr_type): address}
|
||||
)
|
||||
settings['{}-address'.format(addr_type)] = address
|
||||
|
||||
settings['private-address'] = get_relation_ip('cluster')
|
||||
|
||||
relation_set(relation_id=relation_id, relation_settings=settings)
|
||||
|
||||
# Only do if this is fired by cluster rel
|
||||
if not relation_id:
|
||||
check_db_initialised()
|
||||
|
||||
if config('prefer-ipv6'):
|
||||
private_addr = get_ipv6_addr(exc_list=[config('vip')])[0]
|
||||
relation_set(relation_id=relation_id,
|
||||
relation_settings={'private-address': private_addr})
|
||||
|
||||
|
||||
@hooks.hook('cluster-relation-changed',
|
||||
'cluster-relation-departed')
|
||||
|
|
|
@ -93,7 +93,6 @@ TO_PATCH = [
|
|||
'is_elected_leader',
|
||||
'get_hacluster_config',
|
||||
'execd_preinstall',
|
||||
'get_ipv6_addr',
|
||||
'sync_db_with_multi_ipv6_addresses',
|
||||
'delete_keyring',
|
||||
'get_relation_ip',
|
||||
|
|
|
@ -67,7 +67,6 @@ TO_PATCH = [
|
|||
# charmhelpers.contrib.network.ip
|
||||
'get_iface_for_address',
|
||||
'get_netmask_for_address',
|
||||
'get_address_in_network',
|
||||
'get_relation_ip',
|
||||
]
|
||||
|
||||
|
@ -108,26 +107,20 @@ class TestClusterHooks(CharmTestCase):
|
|||
@patch.object(hooks, 'check_db_initialised', lambda *args, **kwargs: None)
|
||||
def test_cluster_joined_hook(self):
|
||||
self.config.side_effect = self.test_config.get
|
||||
self.get_address_in_network.return_value = None
|
||||
hooks.hooks.execute(['hooks/cluster-relation-joined'])
|
||||
self.assertFalse(self.relation_set.called)
|
||||
self.assertTrue(self.relation_set.called)
|
||||
|
||||
@patch.object(hooks, 'check_db_initialised', lambda *args, **kwargs: None)
|
||||
def test_cluster_joined_hook_multinet(self):
|
||||
self.config.side_effect = self.test_config.get
|
||||
self.get_address_in_network.side_effect = [
|
||||
'192.168.20.2',
|
||||
'10.20.3.2',
|
||||
'146.162.23.45'
|
||||
]
|
||||
self.get_relation_ip.return_value = '10.1.1.1'
|
||||
hooks.hooks.execute(['hooks/cluster-relation-joined'])
|
||||
self.relation_set.assert_has_calls([
|
||||
call(relation_id=None,
|
||||
relation_settings={'admin-address': '192.168.20.2'}),
|
||||
call(relation_id=None,
|
||||
relation_settings={'internal-address': '10.20.3.2'}),
|
||||
call(relation_id=None,
|
||||
relation_settings={'public-address': '146.162.23.45'}),
|
||||
call(relation_id=None, relation_settings={
|
||||
'private-address': '10.1.1.1',
|
||||
'admin-address': '10.1.1.1',
|
||||
'internal-address': '10.1.1.1',
|
||||
'public-address': '10.1.1.1'})
|
||||
])
|
||||
|
||||
def test_ha_joined_complete_config(self):
|
||||
|
|
Loading…
Reference in New Issue