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. Change-Id: I33de35055ec11be01988c36e69f5d48b10bf7390 Partial-Bug: #1687439
This commit is contained in:
parent
ddb50888c1
commit
92c0ec5ff3
|
@ -70,7 +70,6 @@ from charmhelpers.core.hookenv import (
|
|||
config,
|
||||
local_unit,
|
||||
remote_unit,
|
||||
unit_get,
|
||||
relation_set,
|
||||
relation_ids,
|
||||
relation_get,
|
||||
|
@ -103,8 +102,7 @@ from charmhelpers.contrib.openstack.ip import (
|
|||
from charmhelpers.contrib.network.ip import (
|
||||
get_iface_for_address,
|
||||
get_netmask_for_address,
|
||||
get_address_in_network,
|
||||
get_ipv6_addr,
|
||||
get_relation_ip,
|
||||
is_ipv6,
|
||||
format_ipv6_addr,
|
||||
)
|
||||
|
@ -358,17 +356,15 @@ def object_store_joined(relation_id=None):
|
|||
@hooks.hook('cluster-relation-joined')
|
||||
def cluster_joined(relation_id=None):
|
||||
settings = {}
|
||||
|
||||
for addr_type in ADDRESS_TYPES:
|
||||
netaddr_cfg = 'os-{}-network'.format(addr_type)
|
||||
address = get_address_in_network(config(netaddr_cfg))
|
||||
address = get_relation_ip(
|
||||
addr_type,
|
||||
cidr_network=config('os-{}-network'.format(addr_type)))
|
||||
if address:
|
||||
settings['{}-address'.format(addr_type)] = address
|
||||
|
||||
if config('prefer-ipv6'):
|
||||
private_addr = get_ipv6_addr(exc_list=[config('vip')])[0]
|
||||
settings['private-address'] = private_addr
|
||||
else:
|
||||
settings['private-address'] = unit_get('private-address')
|
||||
settings['private-address'] = get_relation_ip('cluster')
|
||||
|
||||
relation_set(relation_id=relation_id, relation_settings=settings)
|
||||
|
||||
|
|
|
@ -202,35 +202,31 @@ class SwiftHooksTestCase(unittest.TestCase):
|
|||
relation_id='storage:1', timestamp=1234)]
|
||||
mock_rel_set.assert_has_calls(calls)
|
||||
|
||||
@patch.object(swift_hooks, 'unit_get', lambda key: '10.0.0.100')
|
||||
@patch.object(swift_hooks, 'get_relation_ip')
|
||||
@patch.object(swift_hooks, 'relation_set')
|
||||
@patch.object(swift_hooks, 'config')
|
||||
@patch.object(swift_hooks, 'get_address_in_network')
|
||||
def test_cluster_joined(self, mock_get_addr, mock_config,
|
||||
mock_relation_set):
|
||||
addrs = {'10.0.0.0/24': '10.0.0.1',
|
||||
'10.0.1.0/24': '10.0.1.1',
|
||||
'10.0.2.0/24': '10.0.2.1'}
|
||||
|
||||
def fake_get_address_in_network(network):
|
||||
return addrs.get(network)
|
||||
|
||||
def test_cluster_joined(self, mock_config, mock_relation_set,
|
||||
mock_get_relation_ip):
|
||||
mock_get_relation_ip.side_effect = [
|
||||
'10.0.2.1',
|
||||
'10.0.1.1',
|
||||
'10.0.0.1',
|
||||
'10.0.0.100']
|
||||
config = {'os-public-network': '10.0.0.0/24',
|
||||
'os-admin-network': '10.0.1.0/24',
|
||||
'os-internal-network': '10.0.2.0/24'}
|
||||
'os-internal-network': '10.0.1.0/24',
|
||||
'os-admin-network': '10.0.2.0/24'}
|
||||
|
||||
def fake_config(key):
|
||||
return config.get(key)
|
||||
|
||||
mock_get_addr.side_effect = fake_get_address_in_network
|
||||
mock_config.side_effect = fake_config
|
||||
|
||||
swift_hooks.cluster_joined()
|
||||
mock_relation_set.assert_has_calls(
|
||||
[call(relation_id=None,
|
||||
relation_settings={'private-address': '10.0.0.100',
|
||||
'admin-address': '10.0.1.1',
|
||||
'internal-address': '10.0.2.1',
|
||||
'admin-address': '10.0.2.1',
|
||||
'internal-address': '10.0.1.1',
|
||||
'public-address': '10.0.0.1'})])
|
||||
|
||||
@patch.object(swift_hooks, 'relation_set')
|
||||
|
|
Loading…
Reference in New Issue