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