Use application_name by default for creating pools

Charms consuming Ceph storage typically follow the convention that
pools are named for the application rather than the service name. Most
charms also allow for the pool name to be defined via a config option.
Charms which inherit from the BaseOpenStackCephCharm class will not
follow this typical behavior as the pool created is based on the charm
name.

This change updates the create_pool function to allow for a concrete
charm to optionally provide the name of the pool to be created,
defaulting to the application_name if one is not provided. This is a
change in behavior as the previous behavior was to use the charm
class's name property. Reviewing all known charms which inherit
from/mixin the BaseOpenStackCephCharm reveals that Gnocchi is the only
user of the create_pool method.

As such, it stands to reason that a change in behavior is safe in this
context since the charm class's name for gnocchi was set to the
'gnocchi' which is also the typical application name.

Change-Id: I1756ff4e1362fbc7584551249c583f8d3cb0c8dc
Closes-Bug: #1918821
This commit is contained in:
Billy Olsen 2021-03-16 19:09:34 -07:00
parent 976dd86b83
commit df9a2eddec
2 changed files with 19 additions and 3 deletions

View File

@ -262,11 +262,19 @@ class BaseOpenStackCephCharm(object):
]
return states_to_check
def create_pool(self, ceph_interface):
def create_pool(self, ceph_interface, pool_name=None):
"""Request pool for service.
The pool created will be a replicated pool and will adopt standard
BlueStore compression options that are configured for the charm.
Charms that do not have provide BlueStore compression options will
create pools using the Ceph storage configured defaults.
:param ceph_interface: Ceph interface instance
:type ceph_interface: CephRequires
:param pool_name: (Optional) name of the pool to create.
Defaults to the name of the application deployed.
:type pool_name: str
"""
try:
bluestore_compression = self._get_bluestore_compression()
@ -280,7 +288,7 @@ class BaseOpenStackCephCharm(object):
.format(str(e)))
return
kwargs = {
'name': self.name,
'name': pool_name or self.application_name,
}
if bluestore_compression:
kwargs.update(bluestore_compression)

View File

@ -166,11 +166,19 @@ class TestOpenStackCephConsumingCharm(BaseOpenStackCharmTest):
self._get_bluestore_compression.side_effect = ValueError
self.target.create_pool(ceph_interface)
self.assertFalse(ceph_interface.create_replicated_pool.called)
self.patch_object(cpl.ch_core.hookenv, 'application_name',
return_value='svc1')
self._get_bluestore_compression.side_effect = None
self._get_bluestore_compression.return_value = {'fake': 'value'}
self.target.create_pool(ceph_interface)
ceph_interface.create_replicated_pool.assert_called_once_with(
name='charmname', fake='value')
name='svc1', fake='value')
ceph_interface.create_replicated_pool.reset_mock()
self.target.create_pool(ceph_interface, pool_name='custom_pool')
ceph_interface.create_replicated_pool.assert_called_once_with(
name='custom_pool', fake='value')
class TestCephCharm(BaseOpenStackCharmTest):