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: I9a22868bca6b443f9b7b0e7cecc314ca6b50a112 Partial-Bug: #1687439
This commit is contained in:
parent
1b3808c223
commit
1479919153
|
@ -28,14 +28,13 @@ from charmhelpers.core.hookenv import (
|
|||
relation_ids,
|
||||
relation_get,
|
||||
relation_set,
|
||||
related_units,
|
||||
local_unit,
|
||||
open_port,
|
||||
unit_get,
|
||||
status_set,
|
||||
leader_get,
|
||||
leader_set,
|
||||
is_leader,
|
||||
network_get_primary_address,
|
||||
)
|
||||
|
||||
from charmhelpers.core.host import (
|
||||
|
@ -57,9 +56,8 @@ from charmhelpers.contrib.hahelpers.cluster import (
|
|||
from charmhelpers.contrib.network.ip import (
|
||||
get_iface_for_address,
|
||||
get_netmask_for_address,
|
||||
get_address_in_network,
|
||||
get_ipv6_addr,
|
||||
is_ipv6
|
||||
is_ipv6,
|
||||
get_relation_ip,
|
||||
)
|
||||
|
||||
from charmhelpers.contrib.openstack.utils import (
|
||||
|
@ -180,13 +178,14 @@ def db_joined():
|
|||
config('database-user'),
|
||||
relation_prefix='heat')
|
||||
else:
|
||||
host = None
|
||||
try:
|
||||
# NOTE: try to use network spaces
|
||||
host = network_get_primary_address('shared-db')
|
||||
except NotImplementedError:
|
||||
# NOTE: fallback to private-address
|
||||
host = unit_get('private-address')
|
||||
# Avoid churn check for access-network early
|
||||
access_network = None
|
||||
for unit in related_units():
|
||||
access_network = relation_get(unit=unit,
|
||||
attribute='access-network')
|
||||
if access_network:
|
||||
break
|
||||
host = get_relation_ip('shared-db', cidr_network=access_network)
|
||||
|
||||
relation_set(heat_database=config('database'),
|
||||
heat_username=config('database-user'),
|
||||
|
@ -289,20 +288,18 @@ def leader_elected():
|
|||
|
||||
@hooks.hook('cluster-relation-joined')
|
||||
def cluster_joined(relation_id=None):
|
||||
for addr_type in ADDRESS_TYPES:
|
||||
address = get_address_in_network(
|
||||
config('os-{}-network'.format(addr_type))
|
||||
)
|
||||
if address:
|
||||
relation_set(
|
||||
relation_id=relation_id,
|
||||
relation_settings={'{}-address'.format(addr_type): address}
|
||||
)
|
||||
settings = {}
|
||||
|
||||
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})
|
||||
for addr_type in ADDRESS_TYPES:
|
||||
address = get_relation_ip(
|
||||
addr_type,
|
||||
cidr_network=config('os-{}-network'.format(addr_type)))
|
||||
if address:
|
||||
settings['{}-address'.format(addr_type)] = address
|
||||
|
||||
settings['private-address'] = get_relation_ip('cluster')
|
||||
|
||||
relation_set(relation_id=relation_id, relation_settings=settings)
|
||||
|
||||
|
||||
@hooks.hook('cluster-relation-changed',
|
||||
|
|
|
@ -46,8 +46,7 @@ TO_PATCH = [
|
|||
'config',
|
||||
'open_port',
|
||||
'relation_set',
|
||||
'unit_get',
|
||||
'network_get_primary_address',
|
||||
'related_units',
|
||||
# charmhelpers.core.host
|
||||
'apt_install',
|
||||
'apt_update',
|
||||
|
@ -75,6 +74,7 @@ TO_PATCH = [
|
|||
'local_unit',
|
||||
'get_hacluster_config',
|
||||
'get_iface_for_address',
|
||||
'get_relation_ip',
|
||||
'get_netmask_for_address',
|
||||
]
|
||||
|
||||
|
@ -85,7 +85,6 @@ class HeatRelationTests(CharmTestCase):
|
|||
super(HeatRelationTests, self).setUp(relations, TO_PATCH)
|
||||
self.config.side_effect = self.test_config.get
|
||||
self.charm_dir.return_value = '/var/lib/juju/charms/heat/charm'
|
||||
self.network_get_primary_address.side_effect = NotImplementedError
|
||||
|
||||
def test_install_hook(self):
|
||||
repo = 'cloud:precise-havana'
|
||||
|
@ -124,23 +123,13 @@ class HeatRelationTests(CharmTestCase):
|
|||
|
||||
self.assertFalse(self.do_openstack_upgrade.called)
|
||||
|
||||
def test_db_joined_spaces(self):
|
||||
self.network_get_primary_address.side_effect = None
|
||||
self.network_get_primary_address.return_value = '192.168.20.1'
|
||||
self.unit_get.return_value = 'heat.foohost.com'
|
||||
def test_db_joined(self):
|
||||
self.get_relation_ip.return_value = '192.168.20.1'
|
||||
relations.db_joined()
|
||||
self.relation_set.assert_called_with(heat_database='heat',
|
||||
heat_username='heat',
|
||||
heat_hostname='192.168.20.1')
|
||||
self.assertFalse(self.unit_get.called)
|
||||
|
||||
def test_db_joined(self):
|
||||
self.unit_get.return_value = 'heat.foohost.com'
|
||||
relations.db_joined()
|
||||
self.relation_set.assert_called_with(heat_database='heat',
|
||||
heat_username='heat',
|
||||
heat_hostname='heat.foohost.com')
|
||||
self.unit_get.assert_called_with('private-address')
|
||||
self.assertTrue(self.get_relation_ip.called)
|
||||
|
||||
def _shared_db_test(self, configs):
|
||||
self.relation_get.return_value = 'heat/0 heat/1'
|
||||
|
@ -204,7 +193,6 @@ class HeatRelationTests(CharmTestCase):
|
|||
@patch.object(relations, 'canonical_url')
|
||||
def test_identity_service_joined(self, _canonical_url):
|
||||
"It properly requests unclustered endpoint via identity-service"
|
||||
self.unit_get.return_value = 'heatnode1'
|
||||
_canonical_url.return_value = 'http://heatnode1'
|
||||
relations.identity_joined()
|
||||
expected = {
|
||||
|
@ -284,7 +272,6 @@ class HeatRelationTests(CharmTestCase):
|
|||
|
||||
def test_db_joined_with_ipv6(self):
|
||||
'It properly requests access to a shared-db service'
|
||||
self.unit_get.return_value = 'heatnode1'
|
||||
self.sync_db_with_multi_ipv6_addresses.return_value = MagicMock()
|
||||
self.test_config.set('prefer-ipv6', True)
|
||||
relations.db_joined()
|
||||
|
|
Loading…
Reference in New Issue