From 6d3c847a5108b82772a2cf668495ba174f96a90b Mon Sep 17 00:00:00 2001 From: Federico Bosi Date: Wed, 17 Apr 2024 09:39:32 +0200 Subject: [PATCH] Add ipv6 bind flags Following https://tracker.ceph.com/issues/52867 we need to tell ceph which address family to use via the ms_bind_ipv4/6 config flags. I added them to the ceph.conf template and updated the config hook. Closes-Bug: #2056337 Change-Id: Ib735bd4876b6909762288b97857bccaa597c2b80 (cherry picked from commit 3510058b19338ef30e9f70d7d96d2490165677cb) --- ceph-mon/src/ceph_hooks.py | 2 ++ ceph-mon/templates/ceph.conf | 6 +++++ ceph-mon/unit_tests/test_ceph_hooks.py | 36 ++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/ceph-mon/src/ceph_hooks.py b/ceph-mon/src/ceph_hooks.py index 251bfead..1c2c8ff3 100755 --- a/ceph-mon/src/ceph_hooks.py +++ b/ceph-mon/src/ceph_hooks.py @@ -204,6 +204,8 @@ 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 if not public_network: cephcontext['public_addr'] = dynamic_ipv6_address if not cluster_network: diff --git a/ceph-mon/templates/ceph.conf b/ceph-mon/templates/ceph.conf index 3ad2bc07..52c1cb8f 100644 --- a/ceph-mon/templates/ceph.conf +++ b/ceph-mon/templates/ceph.conf @@ -23,6 +23,12 @@ debug osd = {{ loglevel }}/5 # skew calculation. mon pg warn max object skew = -1 +{% if ms_bind_ipv6 %} +ms_bind_ipv6 = true +{%- endif %} +{%- if ms_bind_ipv4 == false %} +ms_bind_ipv4 = false +{% endif %} {% if ceph_public_network is string %} public network = {{ ceph_public_network }} {%- endif %} diff --git a/ceph-mon/unit_tests/test_ceph_hooks.py b/ceph-mon/unit_tests/test_ceph_hooks.py index 860f4425..1e82f880 100644 --- a/ceph-mon/unit_tests/test_ceph_hooks.py +++ b/ceph-mon/unit_tests/test_ceph_hooks.py @@ -197,6 +197,42 @@ def test_get_ceph_context_w_config_flags_invalid(self, mock_config, 'use_syslog': 'true'} self.assertEqual(ctxt, expected) + @patch.object(ceph_hooks, 'get_rbd_features', return_value=None) + @patch.object(ceph_hooks, 'get_ipv6_addr', + lambda **kwargs: ["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', + '2a01:348:2f4:0:685e:5748:ae62:20a0']) + @patch.object(ceph_hooks, 'get_networks', lambda *args: "") + @patch.object(ceph_hooks, 'leader_get', lambda *args: '1234') + @patch.object(ceph, 'config') + @patch.object(ceph_hooks, 'config') + def test_get_ceph_context_prefer_ipv6(self, mock_config, mock_config2, + _get_rbd_features): + config = copy.deepcopy(CHARM_CONFIG) + config['prefer-ipv6'] = True + mock_config.side_effect = lambda key: config[key] + mock_config2.side_effect = lambda key: config[key] + ctxt = ceph_hooks.get_ceph_context() + expected = {'auth_supported': 'cephx', + 'ceph_cluster_network': '', + 'ceph_public_network': '', + 'cluster_addr': '2a01:348:2f4:0:685e:5748:ae62:209f', + 'dio': 'true', + 'fsid': '1234', + 'loglevel': 1, + 'mon_hosts': '2a01:348:2f4:0:685e:5748:ae62:209f ' + '2a01:348:2f4:0:685e:5748:ae62:20a0', + 'mon_data_avail_warn': 30, + 'mon_data_avail_crit': 5, + 'old_auth': False, + 'public_addr': '2a01:348:2f4:0:685e:5748:ae62:209f', + 'use_syslog': 'true', + 'ms_bind_ipv4': False, + 'ms_bind_ipv6': True} + self.assertEqual(ctxt, expected) + @patch.object(ceph_hooks, 'config') def test_nrpe_dependency_installed(self, mock_config): config = copy.deepcopy(CHARM_CONFIG)