ensure that we can delete shares in cephfs

This commit is contained in:
Chris MacNaughton 2022-03-21 15:00:12 +01:00
parent ac1048ed1c
commit 6294e8fd0c
4 changed files with 20 additions and 2 deletions

View File

@ -59,6 +59,10 @@ delete-share:
exist then this action will have no effect. exist then this action will have no effect.
type: string type: string
default: default:
purge:
type: boolean
default: False
description: Delete the backing CephFS share as well.
list-shares: list-shares:
description: List all shares that this application is managing description: List all shares that this application is managing
# TODO: Update, delete share # TODO: Update, delete share

View File

@ -434,7 +434,8 @@ class CephNfsCharm(
return return
client = GaneshaNfs(self.client_name, self.pool_name) client = GaneshaNfs(self.client_name, self.pool_name)
name = event.params.get('name') name = event.params.get('name')
client.delete_share(name) purge = event.params.get('purge')
client.delete_share(name, purge=purge)
self.peers.trigger_reload() self.peers.trigger_reload()
event.set_results({ event.set_results({
"message": "Share deleted", "message": "Share deleted",

View File

@ -177,7 +177,7 @@ class GaneshaNfs(object):
logging.warning("Encountered an independently created export") logging.warning("Encountered an independently created export")
return exports return exports
def delete_share(self, name: str): def delete_share(self, name: str, purge=False):
share = [share for share in self.list_shares() if share.name == name] share = [share for share in self.list_shares() if share.name == name]
if share: if share:
share = share[0] share = share[0]
@ -189,6 +189,8 @@ class GaneshaNfs(object):
self._remove_share_from_index(share.export_id) self._remove_share_from_index(share.export_id)
logging.debug("Removing export file from RADOS") logging.debug("Removing export file from RADOS")
self._rados_rm('ganesha-export-{}'.format(share.export_id)) self._rados_rm('ganesha-export-{}'.format(share.export_id))
if purge:
self._delete_cephfs_share(name)
def grant_access(self, name: str, client: str) -> Optional[str]: def grant_access(self, name: str, client: str) -> Optional[str]:
share = self.get_share(name) share = self.get_share(name)
@ -248,6 +250,16 @@ class GaneshaNfs(object):
logging.debug("About to call: {}".format(cmd)) logging.debug("About to call: {}".format(cmd))
return subprocess.check_output(cmd) return subprocess.check_output(cmd)
def _delete_cephfs_share(self, name: str):
"""Delete a CephFS share.
:param name: String name of the share to create
"""
self._ceph_subvolume_command(
'deauthorize', 'ceph-fs', name,
'ganesha-{name}'.format(name=name))
self._ceph_subvolume_command('rm', 'ceph-fs', name)
def _create_cephfs_share(self, name: str, size_in_bytes: int = None): def _create_cephfs_share(self, name: str, size_in_bytes: int = None):
"""Create an authorise a CephFS share. """Create an authorise a CephFS share.

View File

@ -48,6 +48,7 @@ class NfsGaneshaTest(unittest.TestCase):
'delete-share', 'delete-share',
action_params={ action_params={
'name': self.created_share, 'name': self.created_share,
'purge': True
}) })
def _create_share(self, name: str, size: int = 10, def _create_share(self, name: str, size: int = 10,