Handle list of addresses in ceph-public-address
charmhelpers' CephContext class is capable of handling a list of IP addresses in the ceph-public-address attribute, this allows ceph-proxy to hand the list of monitor hosts. Closes-Bug: 1642430 Change-Id: I2bbff167fce2c75a3a619b658f0c569c6d5be3d5
This commit is contained in:
parent
4d9a2c0044
commit
d9ee86297e
|
@ -35,7 +35,6 @@ from charmhelpers.core.hookenv import (
|
|||
)
|
||||
from charmhelpers.contrib.network.ip import (
|
||||
format_ipv6_addr,
|
||||
get_host_ip,
|
||||
get_ipv6_addr,
|
||||
)
|
||||
from charmhelpers.contrib.storage.linux.ceph import CephConfContext
|
||||
|
@ -125,7 +124,7 @@ def ensure_host_resolvable_v6(hostname):
|
|||
shutil.rmtree(dtmp)
|
||||
|
||||
|
||||
class MonContext(context.OSContextGenerator):
|
||||
class MonContext(context.CephContext):
|
||||
interfaces = ['ceph-radosgw']
|
||||
|
||||
def __call__(self):
|
||||
|
@ -133,17 +132,21 @@ class MonContext(context.OSContextGenerator):
|
|||
return {}
|
||||
mon_hosts = []
|
||||
auths = []
|
||||
for relid in relation_ids('mon'):
|
||||
for unit in related_units(relid):
|
||||
ceph_public_addr = relation_get('ceph-public-address', unit,
|
||||
relid)
|
||||
if ceph_public_addr:
|
||||
host_ip = format_ipv6_addr(ceph_public_addr) or \
|
||||
get_host_ip(ceph_public_addr)
|
||||
mon_hosts.append('{}:6789'.format(host_ip))
|
||||
_auth = relation_get('auth', unit, relid)
|
||||
if _auth:
|
||||
auths.append(_auth)
|
||||
|
||||
for rid in relation_ids('mon'):
|
||||
for unit in related_units(rid):
|
||||
_auth = relation_get('auth', rid=rid, unit=unit)
|
||||
if _auth:
|
||||
auths.append(_auth)
|
||||
|
||||
ceph_pub_addr = relation_get('ceph-public-address', rid=rid,
|
||||
unit=unit)
|
||||
unit_priv_addr = relation_get('private-address', rid=rid,
|
||||
unit=unit)
|
||||
ceph_addr = ceph_pub_addr or unit_priv_addr
|
||||
ceph_addr = format_ipv6_addr(ceph_addr) or ceph_addr
|
||||
if ceph_addr:
|
||||
mon_hosts.append(ceph_addr)
|
||||
|
||||
if len(set(auths)) != 1:
|
||||
e = ("Inconsistent or absent auth returned by mon units. Setting "
|
||||
|
|
|
@ -190,7 +190,7 @@ class MonContextTest(CharmTestCase):
|
|||
expect = {
|
||||
'auth_supported': 'cephx',
|
||||
'hostname': 'testhost',
|
||||
'mon_hosts': '10.5.4.1:6789 10.5.4.2:6789 10.5.4.3:6789',
|
||||
'mon_hosts': '10.5.4.1 10.5.4.2 10.5.4.3',
|
||||
'old_auth': False,
|
||||
'use_syslog': 'false',
|
||||
'loglevel': 1,
|
||||
|
@ -208,6 +208,44 @@ class MonContextTest(CharmTestCase):
|
|||
self.assertEqual(expect, mon_ctxt())
|
||||
self.assertTrue(mock_ensure_rsv_v6.called)
|
||||
|
||||
@patch.object(ceph, 'config', lambda *args:
|
||||
'{"client.radosgw.gateway": {"rgw init timeout": 60}}')
|
||||
@patch.object(context, 'ensure_host_resolvable_v6')
|
||||
def test_list_of_addresses_from_ceph_proxy(self, mock_ensure_rsv_v6):
|
||||
self.socket.gethostname.return_value = 'testhost'
|
||||
mon_ctxt = context.MonContext()
|
||||
addresses = ['10.5.4.1 10.5.4.2 10.5.4.3']
|
||||
|
||||
def _relation_get(attr, unit, rid):
|
||||
if attr == 'ceph-public-address':
|
||||
return addresses.pop()
|
||||
elif attr == 'auth':
|
||||
return 'cephx'
|
||||
|
||||
self.relation_get.side_effect = _relation_get
|
||||
self.relation_ids.return_value = ['mon:6']
|
||||
self.related_units.return_value = ['ceph-proxy/0']
|
||||
expect = {
|
||||
'auth_supported': 'cephx',
|
||||
'hostname': 'testhost',
|
||||
'mon_hosts': '10.5.4.1 10.5.4.2 10.5.4.3',
|
||||
'old_auth': False,
|
||||
'use_syslog': 'false',
|
||||
'loglevel': 1,
|
||||
'port': 70,
|
||||
'client_radosgw_gateway': {'rgw init timeout': 60},
|
||||
'ipv6': False
|
||||
}
|
||||
self.assertEqual(expect, mon_ctxt())
|
||||
self.assertFalse(mock_ensure_rsv_v6.called)
|
||||
|
||||
self.test_config.set('prefer-ipv6', True)
|
||||
addresses = ['10.5.4.1 10.5.4.2 10.5.4.3']
|
||||
expect['ipv6'] = True
|
||||
expect['port'] = "[::]:%s" % (70)
|
||||
self.assertEqual(expect, mon_ctxt())
|
||||
self.assertTrue(mock_ensure_rsv_v6.called)
|
||||
|
||||
@patch.object(ceph, 'config', lambda *args:
|
||||
'{"client.radosgw.gateway": {"rgw init timeout": 60}}')
|
||||
def test_ctxt_missing_data(self):
|
||||
|
@ -237,7 +275,7 @@ class MonContextTest(CharmTestCase):
|
|||
expect = {
|
||||
'auth_supported': 'none',
|
||||
'hostname': 'testhost',
|
||||
'mon_hosts': '10.5.4.1:6789 10.5.4.2:6789 10.5.4.3:6789',
|
||||
'mon_hosts': '10.5.4.1 10.5.4.2 10.5.4.3',
|
||||
'old_auth': False,
|
||||
'use_syslog': 'false',
|
||||
'loglevel': 1,
|
||||
|
@ -266,7 +304,7 @@ class MonContextTest(CharmTestCase):
|
|||
expect = {
|
||||
'auth_supported': 'cephx',
|
||||
'hostname': 'testhost',
|
||||
'mon_hosts': '10.5.4.1:6789 10.5.4.2:6789 10.5.4.3:6789',
|
||||
'mon_hosts': '10.5.4.1 10.5.4.2 10.5.4.3',
|
||||
'old_auth': False,
|
||||
'use_syslog': 'false',
|
||||
'loglevel': 1,
|
||||
|
|
Loading…
Reference in New Issue