Set os-network relation data on cluster join
By providing openstack network relation data during cluster join we allow haproxy backends to be configured in the corresponding os networks should a 'public-address' not be available. Change-Id: Ie370552410fffb859d236a011844427d8b3aff45 Closes-Bug: #1669044
This commit is contained in:
parent
73538608a7
commit
f36d6e5cb1
|
@ -77,7 +77,8 @@ from charmhelpers.contrib.openstack.ip import (
|
|||
from charmhelpers.contrib.charmsupport import nrpe
|
||||
from charmhelpers.contrib.network.ip import (
|
||||
get_iface_for_address,
|
||||
get_netmask_for_address
|
||||
get_netmask_for_address,
|
||||
get_address_in_network
|
||||
)
|
||||
from charmhelpers.contrib.hahelpers.cluster import (
|
||||
get_hacluster_config,
|
||||
|
@ -223,6 +224,8 @@ def upgrade_charm():
|
|||
install()
|
||||
update_nrpe_config()
|
||||
any_changed()
|
||||
for rid in relation_ids('cluster'):
|
||||
cluster_joined(relation_id=rid)
|
||||
|
||||
|
||||
def install_ceilometer_ocf():
|
||||
|
@ -247,7 +250,7 @@ def install_ceilometer_ocf():
|
|||
|
||||
@hooks.hook('cluster-relation-joined')
|
||||
@restart_on_change(restart_map(), stopstart=True)
|
||||
def cluster_joined():
|
||||
def cluster_joined(relation_id=None):
|
||||
install_ceilometer_ocf()
|
||||
|
||||
# If this node is the elected leader then share our secret with other nodes
|
||||
|
@ -255,6 +258,15 @@ def cluster_joined():
|
|||
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))
|
||||
)
|
||||
if address:
|
||||
relation_set(
|
||||
relation_id=relation_id,
|
||||
relation_settings={'{}-address'.format(addr_type): address}
|
||||
)
|
||||
|
||||
|
||||
@hooks.hook('cluster-relation-changed',
|
||||
|
|
2
tox.ini
2
tox.ini
|
@ -14,7 +14,7 @@ install_command =
|
|||
pip install --allow-unverified python-apt {opts} {packages}
|
||||
commands = ostestr {posargs}
|
||||
whitelist_externals = juju
|
||||
passenv = HOME TERM AMULET_*
|
||||
passenv = HOME TERM AMULET_* CS_API_URL
|
||||
|
||||
[testenv:py27]
|
||||
basepython = python2.7
|
||||
|
|
|
@ -148,6 +148,15 @@ class CeilometerHooksTest(CharmTestCase):
|
|||
self.assertTrue(changed.called)
|
||||
self.assertTrue(install.called)
|
||||
|
||||
@patch('charmhelpers.core.hookenv.config')
|
||||
@patch.object(hooks, 'cluster_joined')
|
||||
def test_upgrade_charm_with_cluster(self, cluster_joined, mock_config):
|
||||
self.relation_ids.return_value = ['ceilometer/0',
|
||||
'ceilometer/1',
|
||||
'ceilometer/2']
|
||||
hooks.hooks.execute(['hooks/upgrade-charm'])
|
||||
self.assertEquals(cluster_joined.call_count, 3)
|
||||
|
||||
@patch.object(hooks, 'install_event_pipeline_setting')
|
||||
@patch('charmhelpers.core.hookenv.config')
|
||||
@patch.object(hooks, 'ceilometer_joined')
|
||||
|
@ -280,6 +289,31 @@ class CeilometerHooksTest(CharmTestCase):
|
|||
self.peer_store.assert_called_with('shared_secret', 'secret')
|
||||
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):
|
||||
mock_leader.return_value = False
|
||||
get_addr.return_value = '10.0.0.100'
|
||||
rel_settings = {'int-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