Add `fsid` to RBD store properties

Currently the RBD store/backend doesn't report the FSID field.
To include the FSID field, we need a connection to the RBD cluster.
Luckily, while initializing the RBD store, we fetch the FSID and
put it in the _url_prefix field (given fsid and pool info are available).

We just need to fetch it from the _url_prefix field and return it
in the response.
If FSID is not set in the RBD store, we return NULL value.

This is required for the effort of optimizing the upload volume to
image operation from cinder RBD to glance RBD backend.

Partial-Implements: blueprint optimize-upload-volume-to-rbd-store
Change-Id: I3e7dc11bc632ca0f3e134e0bca7eb2442bf797ca
This commit is contained in:
Rajat Dhasmana 2024-12-03 17:23:04 +05:30
parent 667ee18685
commit ff313acaf2
5 changed files with 36 additions and 4 deletions

View File

@ -9,7 +9,8 @@
"properties": {
"pool": "pool1",
"chunk_size": 65536,
"thin_provisioning": false
"thin_provisioning": false,
"fsid": "ddf1b25f-1907-449e-89f6-cd30a679c8dc",
}
},
{

View File

@ -92,12 +92,34 @@ class InfoController(object):
return {'stores': backends}
@staticmethod
def _get_fsid_from_url(store_detail):
fsid = None
prefix = 'rbd://'
url_prefix = store_detail.url_prefix
# When fsid and pool info are not available,
# url_prefix is same as prefix
if url_prefix and url_prefix.startswith(
prefix) and len(url_prefix) > len(prefix):
# Remove last trailing forward slash
url_prefix = (
url_prefix[:-1] if url_prefix.endswith('/') else url_prefix)
pieces = url_prefix[len(prefix):].split('/')
# We expect the rbd store's url format to look like 'rbd://%s/%s/'
# where the fsid is in the first position; if there are more than
# 2 pieces, then something has changed in the driver code, so we
# won't set the fsid
if len(pieces) == 2:
fsid = pieces[0]
return fsid
@staticmethod
def _get_rbd_properties(store_detail):
return {
'chunk_size': store_detail.chunk_size,
'pool': store_detail.pool,
'thin_provisioning': store_detail.thin_provisioning
'thin_provisioning': store_detail.thin_provisioning,
'fsid': InfoController._get_fsid_from_url(store_detail),
}
@staticmethod

View File

@ -73,9 +73,12 @@ class MultiStoreClearingUnitTest(test_utils.BaseTestCase):
:param passing_config: making store driver passes basic configurations.
:returns: the number of how many store drivers been loaded.
"""
fake_fsid = "db437934-7e1c-445b-a4f5-7cc5bc44ba1b"
rbd_store.rados = mock.MagicMock()
rbd_store.rbd = mock.MagicMock()
rbd_store.Store._set_url_prefix = mock.MagicMock()
rbd_store.Store.get_connection = mock.MagicMock()
conn_mock = rbd_store.Store.get_connection.return_value.__enter__()
conn_mock.get_fsid.return_value = fake_fsid
cinder.cinderclient = mock.MagicMock()
cinder.Store.get_cinderclient = mock.MagicMock()
swift.swiftclient = mock.MagicMock()

View File

@ -93,7 +93,8 @@ class TestInfoControllers(base.MultiStoreClearingUnitTest):
self.assertIsNotNone(stores['properties'])
def test_get_stores_detail_properties(self):
store_attributes = {'rbd': ['chunk_size', 'pool', 'thin_provisioning'],
store_attributes = {'rbd': ['chunk_size', 'pool', 'thin_provisioning',
'fsid'],
'file': ['data_dir', 'chunk_size',
'thin_provisioning'],
'cinder': ['volume_type', 'use_multipath'],

View File

@ -0,0 +1,5 @@
---
other:
- |
Updated the stores detail API response to include
``fsid`` field in RBD store properties.