diff --git a/hooks/ceph_hooks.py b/hooks/ceph_hooks.py index ec9d266..ce7b363 100755 --- a/hooks/ceph_hooks.py +++ b/hooks/ceph_hooks.py @@ -225,6 +225,9 @@ def get_ceph_context(): "have support for Availability Zones" ) + if config('default-rbd-features'): + cephcontext['rbd_features'] = config('default-rbd-features') + # NOTE(dosaboy): these sections must correspond to what is supported in the # config template. sections = ['global', 'mds', 'osd', 'mon'] @@ -519,8 +522,8 @@ def client_relation_joined(relid=None): data = {'key': ceph.get_named_key(service_name), 'auth': config('auth-supported'), 'ceph-public-address': public_addr} - if config('rbd-features'): - data['rbd_features'] = config('rbd-features') + if config('default-rbd-features'): + data['rbd-features'] = config('default-rbd-features') relation_set(relation_id=relid, relation_settings=data) else: diff --git a/unit_tests/test_ceph_hooks.py b/unit_tests/test_ceph_hooks.py index 2ce4a98..c99c373 100644 --- a/unit_tests/test_ceph_hooks.py +++ b/unit_tests/test_ceph_hooks.py @@ -31,7 +31,8 @@ CHARM_CONFIG = {'config-flags': '', 'osd-format': 'ext4', 'prefer-ipv6': False, 'customize-failure-domain': False, - 'bluestore': False} + 'bluestore': False, + 'default-rbd-features': None} class CephHooksTestCase(unittest.TestCase): @@ -160,6 +161,39 @@ class CephHooksTestCase(unittest.TestCase): 'bluestore_experimental': True} self.assertEqual(ctxt, expected) + @patch.object(ceph_hooks, 'get_public_addr', lambda *args: "10.0.0.1") + @patch.object(ceph_hooks, 'get_cluster_addr', lambda *args: "10.1.0.1") + @patch.object(ceph_hooks, 'cmp_pkgrevno', + lambda pkg, ver: -1 if ver == '12.1.0' else 1) + @patch.object(ceph_hooks, 'get_mon_hosts', lambda *args: ['10.0.0.1', + '10.0.0.2']) + @patch.object(ceph_hooks, 'get_networks', lambda *args: "") + @patch.object(ceph, 'config') + @patch.object(ceph_hooks, 'config') + def test_get_ceph_context_rbd_features(self, mock_config, mock_config2): + config = copy.deepcopy(CHARM_CONFIG) + config['default-rbd-features'] = 1 + 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': False, + 'ceph_cluster_network': '', + 'ceph_public_network': '', + 'cluster_addr': '10.1.0.1', + 'dio': 'true', + 'fsid': '1234', + 'loglevel': 1, + 'mon_hosts': '10.0.0.1 10.0.0.2', + 'old_auth': False, + 'osd_journal_size': 1024, + 'public_addr': '10.0.0.1', + 'short_object_len': True, + 'use_syslog': 'true', + 'rbd_features': 1, + 'bluestore': False, + 'bluestore_experimental': True} + self.assertEqual(ctxt, expected) + @patch.object(ceph_hooks, 'get_public_addr', lambda *args: "10.0.0.1") @patch.object(ceph_hooks, 'get_cluster_addr', lambda *args: "10.1.0.1") @patch.object(ceph_hooks, 'cmp_pkgrevno', lambda *args: 1)