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.