From ff313acaf28db195df8e8933e801a402837f4690 Mon Sep 17 00:00:00 2001 From: Rajat Dhasmana Date: Tue, 3 Dec 2024 17:23:04 +0530 Subject: [PATCH] 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 --- .../samples/stores-list-detail-response.json | 3 ++- glance/api/v2/discovery.py | 24 ++++++++++++++++++- glance/tests/unit/base.py | 5 +++- glance/tests/unit/v2/test_discovery_stores.py | 3 ++- ...-in-rbd-store-detail-9c611684c7f59c32.yaml | 5 ++++ 5 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/add-fsid-in-rbd-store-detail-9c611684c7f59c32.yaml diff --git a/api-ref/source/v2/samples/stores-list-detail-response.json b/api-ref/source/v2/samples/stores-list-detail-response.json index 4f2db586f5..e758a68c8e 100644 --- a/api-ref/source/v2/samples/stores-list-detail-response.json +++ b/api-ref/source/v2/samples/stores-list-detail-response.json @@ -9,7 +9,8 @@ "properties": { "pool": "pool1", "chunk_size": 65536, - "thin_provisioning": false + "thin_provisioning": false, + "fsid": "ddf1b25f-1907-449e-89f6-cd30a679c8dc", } }, { diff --git a/glance/api/v2/discovery.py b/glance/api/v2/discovery.py index 0ce36221a7..4aa8ed0cb7 100644 --- a/glance/api/v2/discovery.py +++ b/glance/api/v2/discovery.py @@ -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 diff --git a/glance/tests/unit/base.py b/glance/tests/unit/base.py index 92aa28adb7..4f81367176 100644 --- a/glance/tests/unit/base.py +++ b/glance/tests/unit/base.py @@ -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() diff --git a/glance/tests/unit/v2/test_discovery_stores.py b/glance/tests/unit/v2/test_discovery_stores.py index 60e0b8e6c8..b4af5e45d5 100644 --- a/glance/tests/unit/v2/test_discovery_stores.py +++ b/glance/tests/unit/v2/test_discovery_stores.py @@ -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'], diff --git a/releasenotes/notes/add-fsid-in-rbd-store-detail-9c611684c7f59c32.yaml b/releasenotes/notes/add-fsid-in-rbd-store-detail-9c611684c7f59c32.yaml new file mode 100644 index 0000000000..1faf301e1b --- /dev/null +++ b/releasenotes/notes/add-fsid-in-rbd-store-detail-9c611684c7f59c32.yaml @@ -0,0 +1,5 @@ +--- +other: + - | + Updated the stores detail API response to include + ``fsid`` field in RBD store properties.