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: I3e651e32a970a427597cc485b8549d51442919cd
This commit is contained in:
parent
cc8bcaf510
commit
232e02f37d
|
@ -41,6 +41,7 @@ from charmhelpers.core.host import (
|
|||
mkdir,
|
||||
init_is_systemd,
|
||||
)
|
||||
from charmhelpers.contrib.openstack.context import ADDRESS_TYPES
|
||||
from charmhelpers.contrib.openstack.utils import (
|
||||
configure_installation_source,
|
||||
os_release,
|
||||
|
@ -79,7 +80,7 @@ from charmhelpers.contrib.charmsupport import nrpe
|
|||
from charmhelpers.contrib.network.ip import (
|
||||
get_iface_for_address,
|
||||
get_netmask_for_address,
|
||||
get_address_in_network
|
||||
get_relation_ip,
|
||||
)
|
||||
from charmhelpers.contrib.hahelpers.cluster import (
|
||||
get_hacluster_config,
|
||||
|
@ -259,15 +260,19 @@ def cluster_joined(relation_id=None):
|
|||
peer_store('shared_secret', get_shared_secret())
|
||||
|
||||
CONFIGS.write_all()
|
||||
for addr_type in [ADMIN, PUBLIC, INTERNAL]:
|
||||
address = get_address_in_network(
|
||||
config('os-{}-network'.format(addr_type))
|
||||
)
|
||||
|
||||
settings = {}
|
||||
|
||||
for addr_type in ADDRESS_TYPES:
|
||||
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)
|
||||
|
||||
|
||||
@hooks.hook('cluster-relation-changed',
|
||||
|
|
|
@ -42,6 +42,7 @@ from test_utils import CharmTestCase
|
|||
TO_PATCH = [
|
||||
'relation_get',
|
||||
'relation_set',
|
||||
'related_units',
|
||||
'configure_installation_source',
|
||||
'openstack_upgrade_available',
|
||||
'do_openstack_upgrade',
|
||||
|
@ -68,6 +69,7 @@ TO_PATCH = [
|
|||
'mkdir',
|
||||
'init_is_systemd',
|
||||
'os_release',
|
||||
'get_relation_ip',
|
||||
]
|
||||
|
||||
|
||||
|
@ -272,7 +274,7 @@ class CeilometerHooksTest(CharmTestCase):
|
|||
mock_leader.return_value = False
|
||||
|
||||
hooks.hooks.execute(['hooks/cluster-relation-joined'])
|
||||
self.assertFalse(self.relation_set.called)
|
||||
self.assertTrue(self.relation_set.called)
|
||||
self.assertTrue(self.CONFIGS.write_all.called)
|
||||
|
||||
@patch('charmhelpers.core.hookenv.config')
|
||||
|
@ -290,30 +292,20 @@ class CeilometerHooksTest(CharmTestCase):
|
|||
self.assertTrue(self.CONFIGS.write_all.called)
|
||||
|
||||
@patch('charmhelpers.core.hookenv.config')
|
||||
@patch.object(hooks, 'get_address_in_network')
|
||||
@patch.object(hooks, 'install_ceilometer_ocf')
|
||||
@patch.object(hooks, 'is_elected_leader')
|
||||
def test_cluster_joined_os_networks(self, mock_leader, mock_install_ocf,
|
||||
get_addr, mock_config):
|
||||
def test_cluster_joined(self, mock_leader, mock_install_ocf, mock_config):
|
||||
mock_leader.return_value = False
|
||||
get_addr.return_value = '10.0.0.100'
|
||||
rel_settings = {'int-address': '10.0.0.100'}
|
||||
self.get_relation_ip.side_effect = [
|
||||
'10.0.0.100', '10.0.1.100', '10.0.2.100', '10.0.3.100']
|
||||
rel_settings = {'private-address': '10.0.3.100',
|
||||
'public-address': '10.0.2.100',
|
||||
'internal-address': '10.0.1.100',
|
||||
'admin-address': '10.0.0.100'}
|
||||
hooks.hooks.execute(['hooks/cluster-relation-joined'])
|
||||
self.relation_set.assert_called_with(relation_id=None,
|
||||
relation_settings=rel_settings)
|
||||
|
||||
@patch('charmhelpers.core.hookenv.config')
|
||||
@patch.object(hooks, 'get_address_in_network')
|
||||
@patch.object(hooks, 'install_ceilometer_ocf')
|
||||
@patch.object(hooks, 'is_elected_leader')
|
||||
def test_cluster_joined_no_os_networks(self, mock_leader,
|
||||
mock_install_ocf,
|
||||
get_addr, mock_config):
|
||||
mock_leader.return_value = False
|
||||
get_addr.return_value = None
|
||||
hooks.hooks.execute(['hooks/cluster-relation-joined'])
|
||||
self.assertEquals(self.relation_set.call_count, 0)
|
||||
|
||||
@patch('charmhelpers.core.hookenv.config')
|
||||
@patch.object(hooks, 'set_shared_secret')
|
||||
def test_cluster_changed(self, shared_secret, mock_config):
|
||||
|
|
Loading…
Reference in New Issue