Add cephfs filesystem to shares metadata

Make use of the `get_optional_share_creation_data` driver interface
to metadata in shares' created using the cephfs protocol.

Closes-Bug: #2050010
Change-Id: I91b51f974840f593334f2dcddfcfd45adfe87780
This commit is contained in:
silvacarloss 2024-02-22 14:38:26 -03:00
parent 3429717601
commit 7e585a3bb5
3 changed files with 41 additions and 1 deletions

View File

@ -139,7 +139,7 @@ cephfs_opts = [
help="The name of the filesystem to use, if there are "
"multiple filesystems in the cluster."),
cfg.StrOpt('cephfs_ensure_all_shares_salt',
default="manila_cephfs_reef_bobcat",
default="manila_cephfs_reef_caracal",
help="Provide a unique string value to make the driver "
"ensure all of the shares it has created during "
"startup. Ensuring would re-export shares and this "
@ -353,6 +353,14 @@ class CephFSDriver(driver.ExecuteMixin, driver.GaneshaMixin,
return self.protocol_helper.get_export_locations(share, subvolume_path)
def get_optional_share_creation_data(self, share, share_server=None):
"""Get the additional properties to be set in a share.
:return: the metadata to be set in share.
"""
return self.protocol_helper.get_optional_share_creation_data(share)
def setup_default_ceph_cmd_target(self):
global ceph_default_target
if not ceph_default_target:
@ -558,8 +566,13 @@ class CephFSDriver(driver.ExecuteMixin, driver.GaneshaMixin,
self.protocol_helper.reapply_rules_while_ensuring_shares,
}
try:
share_metadata = (
self.get_optional_share_creation_data(share).get(
"metadata", {})
)
share_updates[share['id']].update({
'export_locations': self._get_export_locations(share),
"metadata": share_metadata
})
except exception.ShareBackendException as e:
if 'does not exist' in str(e).lower():
@ -842,6 +855,7 @@ class NativeProtocolHelper(ganesha.NASHelperBase):
return {
"cephfs_ensure_all_shares_salt":
self.configuration.cephfs_ensure_all_shares_salt,
"cephfs_filesystem_name": self.volname,
}
def get_export_locations(self, share, subvolume_path):
@ -861,6 +875,9 @@ class NativeProtocolHelper(ganesha.NASHelperBase):
'metadata': {},
}
def get_optional_share_creation_data(self, share, share_server=None):
return {"metadata": {"__mount_options": f"fs={self.volname}"}}
def _allow_access(self, context, share, access, share_server=None):
if access['access_type'] != CEPHX_ACCESS_TYPE:
raise exception.InvalidShareAccessType(type=access['access_type'])
@ -1057,6 +1074,9 @@ class NFSProtocolHelperMixin():
export_locations.append(export_location)
return export_locations
def get_optional_share_creation_data(self, share, share_server=None):
return {}
def _get_export_path(self, share):
"""Callback to provide export path."""
argdict = {

View File

@ -255,32 +255,42 @@ class CephFSDriverTestCase(test.TestCase):
},
]
share_backend_info = {'metadata': {'__mount_options': 'fs=cephfs'}}
metadata = share_backend_info.get('metadata')
expected_updates = {
shares[0]['id']: {
'status': constants.STATUS_ERROR,
'reapply_access_rules': True,
'metadata': metadata,
},
shares[1]['id']: {
'export_locations': export_locations[0],
'reapply_access_rules': True,
'metadata': metadata,
},
shares[2]['id']: {
'export_locations': export_locations[1],
'reapply_access_rules': True,
'metadata': metadata,
}
}
err_message = (f"Error ENOENT: subvolume {self._share['id']} does "
f"not exist")
expected_exception = exception.ShareBackendException(err_message)
self.mock_object(
self._driver, '_get_export_locations',
mock.Mock(side_effect=[expected_exception] + export_locations))
self.mock_object(
self._driver, 'get_optional_share_creation_data',
mock.Mock(return_value=share_backend_info))
actual_updates = self._driver.ensure_shares(self._context, shares)
self.assertEqual(3, self._driver._get_export_locations.call_count)
self._driver._get_export_locations.assert_has_calls([
mock.call(shares[0]), mock.call(shares[1]), mock.call(shares[2])])
self.assertTrue(self._driver.get_optional_share_creation_data.called)
self.assertEqual(expected_updates, actual_updates)
def test_delete_share(self):

View File

@ -0,0 +1,10 @@
---
upgrade:
- |
Shares created using the CEPHFS Native protocol will now have a new
`__mount_options` metadata containing the `cephfs_filesystem_name` to
enhance usability while mounting shares. Existing shares will be updated
through the ensure shares workflow. To preserve backwards compatibility,
this metadata is mutable by end users. It is strongly recommended that
administrators include "__mount_options" in the
`[DEFAULT]/admin_only_metadata_keys` configuration option.