Merge "ZFSSA driver to return project 'available' space"
This commit is contained in:
commit
87d32b1590
@ -460,10 +460,13 @@ class TestZFSSAISCSIDriver(test.TestCase):
|
|||||||
'')
|
'')
|
||||||
|
|
||||||
def test_get_volume_stats(self):
|
def test_get_volume_stats(self):
|
||||||
self.drv.zfssa.get_pool_stats.return_value = 2 * units.Gi, 3 * units.Gi
|
self.drv.zfssa.get_project_stats.return_value = 2 * units.Gi,\
|
||||||
|
3 * units.Gi
|
||||||
lcfg = self.configuration
|
lcfg = self.configuration
|
||||||
stats = self.drv.get_volume_stats(refresh=True)
|
stats = self.drv.get_volume_stats(refresh=True)
|
||||||
self.drv.zfssa.get_pool_stats.assert_called_once_with(lcfg.zfssa_pool)
|
self.drv.zfssa.get_project_stats.assert_called_once_with(
|
||||||
|
lcfg.zfssa_pool,
|
||||||
|
lcfg.zfssa_project)
|
||||||
self.assertEqual('Oracle', stats['vendor_name'])
|
self.assertEqual('Oracle', stats['vendor_name'])
|
||||||
self.assertEqual(self.configuration.volume_backend_name,
|
self.assertEqual(self.configuration.volume_backend_name,
|
||||||
stats['volume_backend_name'])
|
stats['volume_backend_name'])
|
||||||
@ -1176,6 +1179,27 @@ class TestZFSSAApi(test.TestCase):
|
|||||||
'nodestroy': True}
|
'nodestroy': True}
|
||||||
self.zfssa.rclient.put.assert_called_with(expected_svc, expected_arg)
|
self.zfssa.rclient.put.assert_called_with(expected_svc, expected_arg)
|
||||||
|
|
||||||
|
def test_get_project_stats(self):
|
||||||
|
ret_val = json.dumps({"project": {"name": self.project,
|
||||||
|
"space_available": 15754895360,
|
||||||
|
"space_total": 25754895360,
|
||||||
|
"dedup": False,
|
||||||
|
"logbias": "latency",
|
||||||
|
"encryption": "off"}})
|
||||||
|
self.zfssa.rclient.get.return_value = self._create_response(
|
||||||
|
client.Status.OK, ret_val)
|
||||||
|
self.zfssa.get_project_stats(self.pool, self.project)
|
||||||
|
expected_svc = '/api/storage/v1/pools/' + self.pool + '/projects/' + \
|
||||||
|
self.project
|
||||||
|
self.zfssa.rclient.get.assert_called_with(expected_svc)
|
||||||
|
|
||||||
|
self.zfssa.rclient.get.return_value = self._create_response(
|
||||||
|
client.Status.NOT_FOUND)
|
||||||
|
self.assertRaises(exception.VolumeBackendAPIException,
|
||||||
|
self.zfssa.get_project_stats,
|
||||||
|
self.pool,
|
||||||
|
self.project)
|
||||||
|
|
||||||
|
|
||||||
class TestZFSSANfsApi(test.TestCase):
|
class TestZFSSANfsApi(test.TestCase):
|
||||||
|
|
||||||
|
@ -393,7 +393,8 @@ class ZFSSAISCSIDriver(driver.ISCSIDriver):
|
|||||||
data["storage_protocol"] = self.protocol
|
data["storage_protocol"] = self.protocol
|
||||||
|
|
||||||
lcfg = self.configuration
|
lcfg = self.configuration
|
||||||
(avail, total) = self.zfssa.get_pool_stats(lcfg.zfssa_pool)
|
(avail, total) = self.zfssa.get_project_stats(lcfg.zfssa_pool,
|
||||||
|
lcfg.zfssa_project)
|
||||||
if avail is None or total is None:
|
if avail is None or total is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -352,35 +352,30 @@ class ZFSSAApi(object):
|
|||||||
LOG.error(exception_msg)
|
LOG.error(exception_msg)
|
||||||
raise exception.VolumeBackendAPIException(data=exception_msg)
|
raise exception.VolumeBackendAPIException(data=exception_msg)
|
||||||
|
|
||||||
def get_pool_stats(self, pool):
|
def get_project_stats(self, pool, project):
|
||||||
"""Get pool stats.
|
"""Get project stats.
|
||||||
|
|
||||||
Get space available and total properties of a pool
|
Get available space and total space of a project
|
||||||
returns (avail, total).
|
returns (avail, total).
|
||||||
"""
|
"""
|
||||||
svc = '/api/storage/v1/pools/' + pool
|
svc = '/api/storage/v1/pools/%s/projects/%s' % (pool, project)
|
||||||
ret = self.rclient.get(svc)
|
ret = self.rclient.get(svc)
|
||||||
if ret.status != restclient.Status.OK:
|
if ret.status != restclient.Status.OK:
|
||||||
exception_msg = (_('Error Getting Pool Stats: '
|
exception_msg = (_('Error Getting Project Stats: '
|
||||||
'Pool: %(pool)s '
|
'Pool: %(pool)s '
|
||||||
|
'Project: %(project)s '
|
||||||
'Return code: %(ret.status)d '
|
'Return code: %(ret.status)d '
|
||||||
'Message: %(ret.data)s.')
|
'Message: %(ret.data)s.')
|
||||||
% {'pool': pool,
|
% {'pool': pool,
|
||||||
|
'project': project,
|
||||||
'ret.status': ret.status,
|
'ret.status': ret.status,
|
||||||
'ret.data': ret.data})
|
'ret.data': ret.data})
|
||||||
LOG.error(exception_msg)
|
LOG.error(exception_msg)
|
||||||
raise exception.InvalidVolume(reason=exception_msg)
|
raise exception.VolumeBackendAPIException(data=exception_msg)
|
||||||
|
|
||||||
val = json.loads(ret.data)
|
val = json.loads(ret.data)
|
||||||
|
avail = val['project']['space_available']
|
||||||
if not self._is_pool_owned(val):
|
total = avail + val['project']['space_total']
|
||||||
LOG.error(_LE('Error Pool ownership: Pool %(pool)s is not owned '
|
|
||||||
'by %(host)s.'),
|
|
||||||
{'pool': pool, 'host': self.host})
|
|
||||||
raise exception.InvalidInput(reason=pool)
|
|
||||||
|
|
||||||
avail = val['pool']['usage']['available']
|
|
||||||
total = val['pool']['usage']['total']
|
|
||||||
|
|
||||||
return avail, total
|
return avail, total
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user