Merge "Correct Quobyte driver capacity reporting"

This commit is contained in:
Jenkins 2016-07-22 15:22:35 +00:00 committed by Gerrit Code Review
commit 9dfde6dde7
2 changed files with 44 additions and 7 deletions

View File

@ -76,9 +76,10 @@ class QuobyteShareDriver(driver.ExecuteMixin, driver.ShareDriver,):
1.0.1 - Adds ensure_share() implementation.
1.1 - Adds extend_share() and shrink_share() implementation.
1.2 - Adds update_access() implementation and related methods
1.2.1 - Improved capacity calculation
"""
DRIVER_VERSION = '1.2'
DRIVER_VERSION = '1.2.1'
def __init__(self, *args, **kwargs):
super(QuobyteShareDriver, self).__init__(False, *args, **kwargs)
@ -141,18 +142,28 @@ class QuobyteShareDriver(driver.ExecuteMixin, driver.ShareDriver,):
def _get_capacities(self):
result = self.rpc.call('getSystemStatistics', {})
total = float(result['total_logical_capacity'])
used = float(result['total_logical_usage'])
total = float(result['total_physical_capacity'])
used = float(result['total_physical_usage'])
LOG.info(_LI('Read capacity of %(cap)s bytes and '
'usage of %(use)s bytes from backend. '),
{'cap': total, 'use': used})
free = total - used
if free < 0:
free = 0 # no space available
free_replicated = free / self._get_qb_replication_factor()
# floor numbers to nine digits (bytes)
total = math.floor((total / units.Gi) * units.G) / units.G
free = math.floor((free / units.Gi) * units.G) / units.G
free = math.floor((free_replicated / units.Gi) * units.G) / units.G
return total, free
def _get_qb_replication_factor(self):
result = self.rpc.call('getEffectiveVolumeConfiguration',
{'configuration_name': self.
configuration.quobyte_volume_configuration})
return int(result['configuration']['volume_metadata_configuration']
['replication_factor'])
def check_for_setup_error(self):
pass

View File

@ -318,13 +318,39 @@ class QuobyteShareDriverTestCase(test.TestCase):
def test_get_capacities_gb(self):
capval = 42115548133
useval = 19695128917
replfact = 3
self._driver._get_qb_replication_factor = mock.Mock(
return_value=replfact)
self._driver.rpc.call = mock.Mock(
return_value={'total_logical_capacity': six.text_type(capval),
'total_logical_usage': six.text_type(useval)})
return_value={'total_physical_capacity': six.text_type(capval),
'total_physical_usage': six.text_type(useval)})
self.assertEqual((39.223160718, 20.880642548),
self.assertEqual((39.223160718, 6.960214182),
self._driver._get_capacities())
def test_get_capacities_gb_full(self):
capval = 1024 * 1024 * 1024 * 3
useval = 1024 * 1024 * 1024 * 3 + 1
replfact = 1
self._driver._get_qb_replication_factor = mock.Mock(
return_value=replfact)
self._driver.rpc.call = mock.Mock(
return_value={'total_physical_capacity': six.text_type(capval),
'total_physical_usage': six.text_type(useval)})
self.assertEqual((3.0, 0), self._driver._get_capacities())
def test_get_replication(self):
fakerepl = 42
self._driver.configuration.quobyte_volume_configuration = 'fakeVolConf'
self._driver.rpc.call = mock.Mock(
return_value={'configuration':
{'volume_metadata_configuration':
{'replication_factor':
six.text_type(fakerepl)}}})
self.assertEqual(fakerepl, self._driver._get_qb_replication_factor())
@mock.patch.object(quobyte.QuobyteShareDriver,
"_resolve_volume_name",
return_value="fake_uuid")