diff --git a/config.yaml b/config.yaml index 6a40af1..6aa9a6e 100644 --- a/config.yaml +++ b/config.yaml @@ -34,3 +34,8 @@ options: type: boolean description: | Optionally restrict Ceph key permissions to access pools as required. + rbd-pool-name: + default: + type: string + description: | + Optionally specify an existing rbd pool that cinder should map to. diff --git a/hooks/cinder_contexts.py b/hooks/cinder_contexts.py index 3ebb162..4a9c736 100644 --- a/hooks/cinder_contexts.py +++ b/hooks/cinder_contexts.py @@ -13,6 +13,7 @@ # limitations under the License. from charmhelpers.core.hookenv import ( + config, service_name, is_relation_made, leader_get, @@ -51,9 +52,13 @@ class CephSubordinateContext(OSContextGenerator): else: volume_driver = 'cinder.volume.driver.RBDDriver' + if config('rbd-pool-name'): + pool_name = config('rbd-pool-name') + else: + pool_name = service section = {service: [('volume_backend_name', service), ('volume_driver', volume_driver), - ('rbd_pool', service), + ('rbd_pool', pool_name), ('rbd_user', service), ('rbd_secret_uuid', leader_get('secret-uuid')), ('rbd_ceph_conf', ceph_config_file())]} diff --git a/unit_tests/test_cinder_contexts.py b/unit_tests/test_cinder_contexts.py index 100fe18..b26b6a3 100644 --- a/unit_tests/test_cinder_contexts.py +++ b/unit_tests/test_cinder_contexts.py @@ -19,6 +19,7 @@ from test_utils import ( ) TO_PATCH = [ + 'config', 'is_relation_made', 'service_name', 'get_os_codename_package', @@ -30,6 +31,7 @@ class TestCinderContext(CharmTestCase): def setUp(self): super(TestCinderContext, self).setUp(contexts, TO_PATCH) + self.config.side_effect = self.test_config.get self.leader_get.return_value = 'libvirt-uuid' self.maxDiff = None @@ -111,3 +113,29 @@ class TestCinderContext(CharmTestCase): } } }}) + + def test_ceph_explicit_pool_name(self): + self.test_config.set('rbd-pool-name', 'special_pool') + self.is_relation_made.return_value = True + self.get_os_codename_package.return_value = "mitaka" + service = 'mycinder' + self.service_name.return_value = service + self.assertEqual( + contexts.CephSubordinateContext()(), + {"cinder": { + "/etc/cinder/cinder.conf": { + "sections": { + service: [ + ('volume_backend_name', service), + ('volume_driver', + 'cinder.volume.drivers.rbd.RBDDriver'), + ('rbd_pool', 'special_pool'), + ('rbd_user', service), + ('rbd_secret_uuid', 'libvirt-uuid'), + ('rbd_ceph_conf', + '/var/lib/charm/mycinder/ceph.conf'), + ('report_discard_supported', True) + ] + } + } + }})