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
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@ bin/
|
||||
.tox
|
||||
.testrepository
|
||||
.coverage
|
||||
.stestr
|
||||
|
@ -29,12 +29,10 @@ from charmhelpers.core.hookenv import (
|
||||
INFO,
|
||||
related_units,
|
||||
relation_ids,
|
||||
relation_get,
|
||||
relation_set,
|
||||
config,
|
||||
Hooks,
|
||||
UnregisteredHookError,
|
||||
local_unit,
|
||||
status_set,
|
||||
)
|
||||
|
||||
@ -45,6 +43,10 @@ from charmhelpers.core.host import (
|
||||
CompareHostReleases,
|
||||
)
|
||||
|
||||
from charmhelpers.contrib.network.ip import (
|
||||
get_relation_ip,
|
||||
)
|
||||
|
||||
from charmhelpers.fetch import (
|
||||
apt_install,
|
||||
apt_purge,
|
||||
@ -68,7 +70,6 @@ from utils import (
|
||||
enable_lsb_services,
|
||||
disable_lsb_services,
|
||||
disable_upstart_services,
|
||||
get_ipv6_addr,
|
||||
get_ip_addr_from_resource_params,
|
||||
validate_dns_ha,
|
||||
setup_maas_api,
|
||||
@ -83,9 +84,6 @@ from utils import (
|
||||
)
|
||||
|
||||
from charmhelpers.contrib.charmsupport import nrpe
|
||||
from charmhelpers.contrib.network.ip import (
|
||||
is_ipv6,
|
||||
)
|
||||
|
||||
hooks = Hooks()
|
||||
|
||||
@ -130,18 +128,6 @@ def get_transport():
|
||||
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')
|
||||
def config_changed():
|
||||
|
||||
@ -158,9 +144,8 @@ def config_changed():
|
||||
|
||||
enable_lsb_services('pacemaker')
|
||||
|
||||
if config('prefer-ipv6'):
|
||||
for rid in relation_ids('hanode'):
|
||||
ensure_ipv6_requirements(rid)
|
||||
for rid in relation_ids('hanode'):
|
||||
hanode_relation_joined(rid)
|
||||
|
||||
status_set('maintenance', "Setting up corosync")
|
||||
if configure_corosync():
|
||||
@ -208,17 +193,17 @@ def upgrade_charm():
|
||||
update_nrpe_config()
|
||||
|
||||
|
||||
@hooks.hook('hanode-relation-joined',
|
||||
'hanode-relation-changed')
|
||||
def hanode_relation_changed():
|
||||
if config('prefer-ipv6'):
|
||||
ensure_ipv6_requirements(None)
|
||||
|
||||
ha_relation_changed()
|
||||
@hooks.hook('hanode-relation-joined')
|
||||
def hanode_relation_joined(relid=None):
|
||||
relation_set(
|
||||
relation_id=relid,
|
||||
relation_settings={'private-address': get_relation_ip('hanode')}
|
||||
)
|
||||
|
||||
|
||||
@hooks.hook('ha-relation-joined',
|
||||
'ha-relation-changed')
|
||||
'ha-relation-changed',
|
||||
'hanode-relation-changed')
|
||||
def ha_relation_changed():
|
||||
# Check that we are related to a principle and that
|
||||
# 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)
|
||||
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, 'is_leader')
|
||||
@mock.patch.object(hooks, 'update_nrpe_config')
|
||||
@ -267,13 +269,18 @@ class TestHooks(test_utils.CharmTestCase):
|
||||
mock_os_mkdir, mock_configure_corosync,
|
||||
mock_wait_for_pcmk, mock_pcmk_commit,
|
||||
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_relation_ids.return_value = ['hanode:1']
|
||||
mock_wait_for_pcmk.return_value = True
|
||||
mock_is_leader.return_value = True
|
||||
hooks.config_changed()
|
||||
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
|
||||
self.test_config.set_previous('maintenance-mode', False)
|
||||
@ -320,3 +327,16 @@ class TestHooks(test_utils.CharmTestCase):
|
||||
hooks.migrate_maas_dns()
|
||||
write_maas_dns_address.assert_called_with(
|
||||
"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…
x
Reference in New Issue
Block a user