Use new IP helpers for endpoint registration

This commit is contained in:
James Page 2014-07-03 10:57:07 +01:00
parent b1f9283ffa
commit a39798db95
6 changed files with 27 additions and 30 deletions

BIN
.coverage

Binary file not shown.

View File

@ -98,7 +98,7 @@ def is_address_in_network(network, address):
def _get_for_address(address, key):
"""Retrieve an attribute of or the physical interface that
the IP address provided could be bound to.
:param address (str): An individual IPv4 or IPv6 address without a net
mask or subnet prefix. For example, '192.168.1.1'.
:param key: 'iface' for the physical interface name or an attribute
@ -125,7 +125,7 @@ def get_iface_for_address(address):
:param address (str): An individual IPv4 or IPv6 address without a net
mask or subnet prefix. For example, '192.168.1.1'.
:returns str: Interface name or None if address is not bindable.
:returns str: Interface name or None if address is not bindable.
"""
return _get_for_address(address, 'iface')
@ -137,6 +137,6 @@ def get_netmask_for_address(address):
:param address (str): An individual IPv4 or IPv6 address without a net
mask or subnet prefix. For example, '192.168.1.1'.
:returns str: Netmask of configured interface or None if address is
not bindable.
not bindable.
"""
return _get_for_address(address, 'netmask')

View File

@ -148,7 +148,7 @@ class SharedDBContext(OSContextGenerator):
if self.relation_prefix is not None:
hostname_key = "{}_hostname".format(self.relation_prefix)
else:
hostname_key = "hostname"
hostname_key = "hostname"
access_hostname = get_address_in_network(access_network,
unit_get('private-address'))
set_hostname = relation_get(attribute=hostname_key,

View File

@ -35,7 +35,6 @@ from charmhelpers.core.hookenv import (
unit_get,
log,
ERROR,
local_unit,
)
from charmhelpers.fetch import apt_install, apt_update
@ -47,7 +46,6 @@ from charmhelpers.contrib.openstack.utils import (
from charmhelpers.contrib.storage.linux.ceph import ensure_ceph_keyring
from charmhelpers.contrib.hahelpers.cluster import (
canonical_url,
eligible_leader,
is_leader,
get_hacluster_config,
@ -55,9 +53,12 @@ from charmhelpers.contrib.hahelpers.cluster import (
from charmhelpers.payload.execd import execd_preinstall
from charmhelpers.contrib.network.ip import (
get_address_in_network,
get_iface_for_address,
get_netmask_for_address
get_netmask_for_address,
)
from charmhelpers.contrib.openstack.ip import (
canonical_url,
PUBLIC, INTERNAL, ADMIN
)
hooks = Hooks()
@ -181,31 +182,20 @@ def identity_joined(rid=None):
if not eligible_leader(CLUSTER_RES):
return
conf = config()
port = conf['api-listening-port']
public_url = '{}:{}/v1/$(tenant_id)s'.format(
canonical_url(
CONFIGS,
address=get_address_in_network(conf.get('os-public-network'),
unit_get('public-address'))),
port
canonical_url(CONFIGS, PUBLIC),
config('api-listening-port')
)
internal_url = '{}:{}/v1/$(tenant_id)s'.format(
canonical_url(
CONFIGS,
address=get_address_in_network(conf.get('os-internal-network'),
unit_get('private-address'))),
port
canonical_url(CONFIGS, INTERNAL),
config('api-listening-port')
)
admin_url = '{}:{}/v1/$(tenant_id)s'.format(
canonical_url(
CONFIGS,
address=get_address_in_network(conf.get('os-admin-network'),
unit_get('private-address'))),
port
canonical_url(CONFIGS, ADMIN),
config('api-listening-port')
)
settings = {
'region': conf['region'],
'region': config('region'),
'service': 'cinder',
'public_url': public_url,
'internal_url': internal_url,

View File

@ -300,6 +300,7 @@ class TestJoinedHooks(CharmTestCase):
def test_identity_service_joined(self):
'It properly requests unclustered endpoint via identity-service'
self.unit_get.return_value = 'cindernode1'
self.config.side_effect = self.test_config.get
self.canonical_url.return_value = 'http://cindernode1'
hooks.hooks.execute(['hooks/identity-service-relation-joined'])
expected = {

View File

@ -51,7 +51,10 @@ TO_PATCH = [
# charmhelpers.contrib.hahelpers.cluster_utils
'eligible_leader',
'get_hacluster_config',
'is_leader'
'is_leader',
# charmhelpers.contrib.network.ip
'get_iface_for_address',
'get_netmask_for_address'
]
@ -96,19 +99,22 @@ class TestClusterHooks(CharmTestCase):
'vip_cidr': '19',
}
self.get_hacluster_config.return_value = conf
self.get_iface_for_address.return_value = 'eth101'
self.get_netmask_for_address.return_value = '255.255.224.0'
hooks.hooks.execute(['hooks/ha-relation-joined'])
ex_args = {
'corosync_mcastport': '37373',
'init_services': {'res_cinder_haproxy': 'haproxy'},
'resource_params': {
'res_cinder_vip':
'params ip="192.168.25.163" cidr_netmask="19" nic="eth101"',
'res_cinder_eth101_vip':
'params ip="192.168.25.163" cidr_netmask="255.255.224.0"'
' nic="eth101"',
'res_cinder_haproxy': 'op monitor interval="5s"'
},
'corosync_bindiface': 'eth100',
'clones': {'cl_cinder_haproxy': 'res_cinder_haproxy'},
'resources': {
'res_cinder_vip': 'ocf:heartbeat:IPaddr2',
'res_cinder_eth101_vip': 'ocf:heartbeat:IPaddr2',
'res_cinder_haproxy': 'lsb:haproxy'
}
}