diff --git a/cinder/tests/unit/test_block_device.py b/cinder/tests/unit/test_block_device.py index 22aac47cb5a..c501c9fbea4 100644 --- a/cinder/tests/unit/test_block_device.py +++ b/cinder/tests/unit/test_block_device.py @@ -153,16 +153,18 @@ class TestBlockDeviceDriver(cinder.test.TestCase): gud_mocked: self.drv._update_volume_stats() - self.assertEqual({'total_capacity_gb': 2, - 'free_capacity_gb': 2, - 'reserved_percentage': - self.configuration.reserved_percentage, - 'QoS_support': False, - 'vendor_name': "Open Source", - 'driver_version': self.drv.VERSION, - 'storage_protocol': 'unknown', - 'volume_backend_name': 'BlockDeviceDriver', - }, self.drv._stats) + reserved_percentage = self.configuration.reserved_percentage + self.assertEqual({ + 'vendor_name': "Open Source", + 'driver_version': self.drv.VERSION, + 'volume_backend_name': 'BlockDev', + 'storage_protocol': 'unknown', + 'pools': [{ + 'QoS_support': False, + 'total_capacity_gb': 2, + 'free_capacity_gb': 2, + 'reserved_percentage': reserved_percentage, + 'pool_name': 'BlockDev'}]}, self.drv._stats) gud_mocked.assert_called_once_with() ds_mocked.assert_called_once_with() diff --git a/cinder/volume/drivers/block_device.py b/cinder/volume/drivers/block_device.py index 8c3ecd4fd06..9f6df4a0cc1 100644 --- a/cinder/volume/drivers/block_device.py +++ b/cinder/volume/drivers/block_device.py @@ -44,7 +44,7 @@ CONF.register_opts(volume_opts) class BlockDeviceDriver(driver.BaseVD, driver.LocalVD, driver.CloneableImageVD, driver.TransferVD): - VERSION = '2.2.0' + VERSION = '2.3.0' def __init__(self, *args, **kwargs): super(BlockDeviceDriver, self).__init__(*args, **kwargs) @@ -62,12 +62,13 @@ class BlockDeviceDriver(driver.BaseVD, driver.LocalVD, def check_for_setup_error(self): pass - def _update_provider_location(self, object, device): + def _update_provider_location(self, obj, device): # We update provider_location and host to mark device as used to # avoid race with other threads. # TODO(ynesenenko): need to remove DB access from driver - object.update({'provider_location': device, 'host': self.host}) - object.save() + host = '{host}#{pool}'.format(host=self.host, pool=self.get_pool(obj)) + obj.update({'provider_location': device, 'host': host}) + obj.save() @utils.synchronized('block_device', external=True) def create_volume(self, volume): @@ -153,18 +154,26 @@ class BlockDeviceDriver(driver.BaseVD, driver.LocalVD, total_size += size LOG.debug("Updating volume stats.") - backend_name = self.configuration.safe_get('volume_backend_name') - data = {'total_capacity_gb': total_size / units.Ki, - 'free_capacity_gb': free_size / units.Ki, - 'reserved_percentage': self.configuration.reserved_percentage, - 'QoS_support': False, - 'volume_backend_name': backend_name or self.__class__.__name__, - 'vendor_name': "Open Source", - 'driver_version': self.VERSION, - 'storage_protocol': 'unknown'} + data = { + 'volume_backend_name': self.backend_name, + 'vendor_name': "Open Source", + 'driver_version': self.VERSION, + 'storage_protocol': 'unknown', + 'pools': []} + single_pool = { + 'pool_name': data['volume_backend_name'], + 'total_capacity_gb': total_size / units.Ki, + 'free_capacity_gb': free_size / units.Ki, + 'reserved_percentage': self.configuration.reserved_percentage, + 'QoS_support': False} + + data['pools'].append(single_pool) self._stats = data + def get_pool(self, volume): + return self.backend_name + def _get_used_paths(self, lst): used_dev = set() for item in lst: diff --git a/releasenotes/notes/bdd-pools-stats-afb4398daa9248de.yaml b/releasenotes/notes/bdd-pools-stats-afb4398daa9248de.yaml new file mode 100644 index 00000000000..5612d2e699f --- /dev/null +++ b/releasenotes/notes/bdd-pools-stats-afb4398daa9248de.yaml @@ -0,0 +1,3 @@ +--- +features: + - Report pools in volume stats for Block Device Driver.