Support network space binding of hanode relation
Rework hooks to support network space binding of the hanode peer relation to a specific network space. Note that the get_relation_ip function also deals with the 'prefer-ipv6' legacy configuration option handling, so it was safe to remove some charm specific code in this area. Change-Id: Ic69e97debddba42e3d4a140f7f9cfc95768f71c3 Closes-Bug: 1659464
This commit is contained in:
parent
0bdf97fa9b
commit
b74d4aac41
|
@ -3,3 +3,4 @@ bin/
|
||||||
.tox
|
.tox
|
||||||
.testrepository
|
.testrepository
|
||||||
.coverage
|
.coverage
|
||||||
|
.stestr
|
||||||
|
|
|
@ -29,12 +29,10 @@ from charmhelpers.core.hookenv import (
|
||||||
INFO,
|
INFO,
|
||||||
related_units,
|
related_units,
|
||||||
relation_ids,
|
relation_ids,
|
||||||
relation_get,
|
|
||||||
relation_set,
|
relation_set,
|
||||||
config,
|
config,
|
||||||
Hooks,
|
Hooks,
|
||||||
UnregisteredHookError,
|
UnregisteredHookError,
|
||||||
local_unit,
|
|
||||||
status_set,
|
status_set,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -45,6 +43,10 @@ from charmhelpers.core.host import (
|
||||||
CompareHostReleases,
|
CompareHostReleases,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from charmhelpers.contrib.network.ip import (
|
||||||
|
get_relation_ip,
|
||||||
|
)
|
||||||
|
|
||||||
from charmhelpers.fetch import (
|
from charmhelpers.fetch import (
|
||||||
apt_install,
|
apt_install,
|
||||||
apt_purge,
|
apt_purge,
|
||||||
|
@ -68,7 +70,6 @@ from utils import (
|
||||||
enable_lsb_services,
|
enable_lsb_services,
|
||||||
disable_lsb_services,
|
disable_lsb_services,
|
||||||
disable_upstart_services,
|
disable_upstart_services,
|
||||||
get_ipv6_addr,
|
|
||||||
get_ip_addr_from_resource_params,
|
get_ip_addr_from_resource_params,
|
||||||
validate_dns_ha,
|
validate_dns_ha,
|
||||||
setup_maas_api,
|
setup_maas_api,
|
||||||
|
@ -83,9 +84,6 @@ from utils import (
|
||||||
)
|
)
|
||||||
|
|
||||||
from charmhelpers.contrib.charmsupport import nrpe
|
from charmhelpers.contrib.charmsupport import nrpe
|
||||||
from charmhelpers.contrib.network.ip import (
|
|
||||||
is_ipv6,
|
|
||||||
)
|
|
||||||
|
|
||||||
hooks = Hooks()
|
hooks = Hooks()
|
||||||
|
|
||||||
|
@ -130,18 +128,6 @@ def get_transport():
|
||||||
return val
|
return val
|
||||||
|
|
||||||
|
|
||||||
def ensure_ipv6_requirements(hanode_rid):
|
|
||||||
# hanode relation needs ipv6 private-address
|
|
||||||
addr = relation_get(rid=hanode_rid, unit=local_unit(),
|
|
||||||
attribute='private-address')
|
|
||||||
log("Current private-address is %s" % (addr))
|
|
||||||
if not is_ipv6(addr):
|
|
||||||
addr = get_ipv6_addr()
|
|
||||||
log("New private-address is %s" % (addr))
|
|
||||||
relation_set(relation_id=hanode_rid,
|
|
||||||
**{'private-address': addr})
|
|
||||||
|
|
||||||
|
|
||||||
@hooks.hook('config-changed')
|
@hooks.hook('config-changed')
|
||||||
def config_changed():
|
def config_changed():
|
||||||
|
|
||||||
|
@ -158,9 +144,8 @@ def config_changed():
|
||||||
|
|
||||||
enable_lsb_services('pacemaker')
|
enable_lsb_services('pacemaker')
|
||||||
|
|
||||||
if config('prefer-ipv6'):
|
for rid in relation_ids('hanode'):
|
||||||
for rid in relation_ids('hanode'):
|
hanode_relation_joined(rid)
|
||||||
ensure_ipv6_requirements(rid)
|
|
||||||
|
|
||||||
status_set('maintenance', "Setting up corosync")
|
status_set('maintenance', "Setting up corosync")
|
||||||
if configure_corosync():
|
if configure_corosync():
|
||||||
|
@ -208,17 +193,17 @@ def upgrade_charm():
|
||||||
update_nrpe_config()
|
update_nrpe_config()
|
||||||
|
|
||||||
|
|
||||||
@hooks.hook('hanode-relation-joined',
|
@hooks.hook('hanode-relation-joined')
|
||||||
'hanode-relation-changed')
|
def hanode_relation_joined(relid=None):
|
||||||
def hanode_relation_changed():
|
relation_set(
|
||||||
if config('prefer-ipv6'):
|
relation_id=relid,
|
||||||
ensure_ipv6_requirements(None)
|
relation_settings={'private-address': get_relation_ip('hanode')}
|
||||||
|
)
|
||||||
ha_relation_changed()
|
|
||||||
|
|
||||||
|
|
||||||
@hooks.hook('ha-relation-joined',
|
@hooks.hook('ha-relation-joined',
|
||||||
'ha-relation-changed')
|
'ha-relation-changed',
|
||||||
|
'hanode-relation-changed')
|
||||||
def ha_relation_changed():
|
def ha_relation_changed():
|
||||||
# Check that we are related to a principle and that
|
# Check that we are related to a principle and that
|
||||||
# it has already provided the required corosync configuration
|
# it has already provided the required corosync configuration
|
||||||
|
|
|
@ -253,6 +253,8 @@ class TestHooks(test_utils.CharmTestCase):
|
||||||
super(TestHooks, self).setUp(hooks, self.TO_PATCH)
|
super(TestHooks, self).setUp(hooks, self.TO_PATCH)
|
||||||
self.config.side_effect = self.test_config.get
|
self.config.side_effect = self.test_config.get
|
||||||
|
|
||||||
|
@mock.patch.object(hooks, 'relation_ids')
|
||||||
|
@mock.patch.object(hooks, 'hanode_relation_joined')
|
||||||
@mock.patch.object(hooks, 'maintenance_mode')
|
@mock.patch.object(hooks, 'maintenance_mode')
|
||||||
@mock.patch.object(hooks, 'is_leader')
|
@mock.patch.object(hooks, 'is_leader')
|
||||||
@mock.patch.object(hooks, 'update_nrpe_config')
|
@mock.patch.object(hooks, 'update_nrpe_config')
|
||||||
|
@ -267,13 +269,18 @@ class TestHooks(test_utils.CharmTestCase):
|
||||||
mock_os_mkdir, mock_configure_corosync,
|
mock_os_mkdir, mock_configure_corosync,
|
||||||
mock_wait_for_pcmk, mock_pcmk_commit,
|
mock_wait_for_pcmk, mock_pcmk_commit,
|
||||||
mock_update_nrpe_config, mock_is_leader,
|
mock_update_nrpe_config, mock_is_leader,
|
||||||
mock_maintenance_mode):
|
mock_maintenance_mode,
|
||||||
|
mock_hanode_relation_joined,
|
||||||
|
mock_relation_ids):
|
||||||
|
|
||||||
mock_config.side_effect = self.test_config.get
|
mock_config.side_effect = self.test_config.get
|
||||||
|
mock_relation_ids.return_value = ['hanode:1']
|
||||||
mock_wait_for_pcmk.return_value = True
|
mock_wait_for_pcmk.return_value = True
|
||||||
mock_is_leader.return_value = True
|
mock_is_leader.return_value = True
|
||||||
hooks.config_changed()
|
hooks.config_changed()
|
||||||
mock_maintenance_mode.assert_not_called()
|
mock_maintenance_mode.assert_not_called()
|
||||||
|
mock_relation_ids.assert_called_with('hanode')
|
||||||
|
mock_hanode_relation_joined.assert_called_once_with('hanode:1')
|
||||||
|
|
||||||
# enable maintenance
|
# enable maintenance
|
||||||
self.test_config.set_previous('maintenance-mode', False)
|
self.test_config.set_previous('maintenance-mode', False)
|
||||||
|
@ -320,3 +327,16 @@ class TestHooks(test_utils.CharmTestCase):
|
||||||
hooks.migrate_maas_dns()
|
hooks.migrate_maas_dns()
|
||||||
write_maas_dns_address.assert_called_with(
|
write_maas_dns_address.assert_called_with(
|
||||||
"res_keystone_public_hostname", "172.16.0.1")
|
"res_keystone_public_hostname", "172.16.0.1")
|
||||||
|
|
||||||
|
@mock.patch.object(hooks, 'get_relation_ip')
|
||||||
|
@mock.patch.object(hooks, 'relation_set')
|
||||||
|
def test_hanode_relation_joined(self,
|
||||||
|
mock_relation_set,
|
||||||
|
mock_get_relation_ip):
|
||||||
|
mock_get_relation_ip.return_value = '10.10.10.2'
|
||||||
|
hooks.hanode_relation_joined('hanode:1')
|
||||||
|
mock_get_relation_ip.assert_called_once_with('hanode')
|
||||||
|
mock_relation_set.assert_called_once_with(
|
||||||
|
relation_id='hanode:1',
|
||||||
|
relation_settings={'private-address': '10.10.10.2'}
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue