Merge "Allow static ipv6 addresses & binding check"

This commit is contained in:
Zuul
2024-06-14 08:10:46 +00:00
committed by Gerrit Code Review
3 changed files with 32 additions and 5 deletions

View File

@@ -205,13 +205,33 @@ def get_ceph_context():
}
if config('prefer-ipv6'):
dynamic_ipv6_address = get_ipv6_addr()[0]
cephcontext['ms_bind_ipv4'] = False
cephcontext['ms_bind_ipv6'] = True
local_addresses = get_ipv6_addr(dynamic_only=False)
public_addr = get_public_addr()
cluster_addr = get_cluster_addr()
# try binding to the address that juju will pass to other charms
if public_addr not in local_addresses:
log(f"Couldn't find a match for our assigned "
f"public ip {public_addr} "
f"out of {local_addresses}, "
f"using default {local_addresses[0]}",
level=WARNING)
public_addr = local_addresses[0]
if cluster_addr not in local_addresses:
log(f"Couldn't find a match for our assigned "
f"cluster ip {cluster_addr} "
f"out of {local_addresses}, "
f"using default {local_addresses[0]}",
level=WARNING)
cluster_addr = local_addresses[0]
if not public_network:
cephcontext['public_addr'] = dynamic_ipv6_address
cephcontext['public_addr'] = public_addr
if not cluster_network:
cephcontext['cluster_addr'] = dynamic_ipv6_address
cephcontext['cluster_addr'] = cluster_addr
else:
cephcontext['public_addr'] = get_public_addr()
cephcontext['cluster_addr'] = get_cluster_addr()

View File

@@ -130,7 +130,7 @@ def get_unit_hostname():
@cached
def get_host_ip(hostname=None):
if config('prefer-ipv6'):
return get_ipv6_addr()[0]
return get_ipv6_addr(dynamic_only=False)[0]
hostname = hostname or unit_get('private-address')
try:

View File

@@ -200,8 +200,15 @@ class CephHooksTestCase(test_utils.CharmTestCase):
self.assertEqual(ctxt, expected)
@patch.object(ceph_hooks, 'get_rbd_features', return_value=None)
# Provide multiple local addresses,
# we'll check that the right (second) one is used
@patch.object(ceph_hooks, 'get_ipv6_addr',
lambda **kwargs: ["2a01:348:2f4:0:685e:5748:ae62:209f"])
lambda **kwargs: ["2a01:348:2f4:0:bad:bad:bad:bad",
"2a01:348:2f4:0:685e:5748:ae62:209f"])
@patch.object(ceph_hooks, 'get_public_addr',
lambda *args: "2a01:348:2f4:0:685e:5748:ae62:209f")
@patch.object(ceph_hooks, 'get_cluster_addr',
lambda *args: "2a01:348:2f4:0:685e:5748:ae62:209f")
@patch.object(ceph_hooks, 'cmp_pkgrevno', lambda *args: 1)
@patch.object(ceph_hooks, 'get_mon_hosts',
lambda *args: ['2a01:348:2f4:0:685e:5748:ae62:209f',