Skip to content

Commit

Permalink
XenAPINFS: fix capacity reporting
Browse files Browse the repository at this point in the history
Fixes bug 1129056

XenAPINFS did not implement the get_volume_stats method, thus
CapacityFilter fitered out the host, thus no volume was scheduled. This
fix is working around this problem quickly, by reporting an 'unknown'
capacity.

Change-Id: I1dc5327e420a3316201318d52f602ced071d459b
  • Loading branch information
Mate Lakat committed Feb 19, 2013
1 parent e1815e8 commit b0cdbdf
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 28 deletions.
69 changes: 41 additions & 28 deletions cinder/tests/test_xenapi_sm.py
Expand Up @@ -32,6 +32,14 @@ def __init__(ctxt, auth_token):
ctxt.auth_token = auth_token


def get_configured_driver(server='ignore_server', path='ignore_path'):
configuration = mox.MockObject(conf.Configuration)
configuration.xenapi_nfs_server = server
configuration.xenapi_nfs_serverpath = path
configuration.append_config_values(mox.IgnoreArg())
return driver.XenAPINFSDriver(configuration=configuration)


class DriverTestCase(unittest.TestCase):

def assert_flag(self, flagname):
Expand Down Expand Up @@ -76,13 +84,8 @@ def test_do_setup(self):
def test_create_volume(self):
mock = mox.Mox()

configuration = mox.MockObject(conf.Configuration)
configuration.xenapi_nfs_server = 'server'
configuration.xenapi_nfs_serverpath = 'path'
configuration.append_config_values(mox.IgnoreArg())

ops = mock.CreateMock(lib.NFSBasedVolumeOperations)
drv = driver.XenAPINFSDriver(configuration=configuration)
drv = get_configured_driver('server', 'path')
drv.nfs_ops = ops

volume_details = dict(
Expand All @@ -102,13 +105,8 @@ def test_create_volume(self):
def test_delete_volume(self):
mock = mox.Mox()

configuration = mox.MockObject(conf.Configuration)
configuration.xenapi_nfs_server = 'server'
configuration.xenapi_nfs_serverpath = 'path'
configuration.append_config_values(mox.IgnoreArg())

ops = mock.CreateMock(lib.NFSBasedVolumeOperations)
drv = driver.XenAPINFSDriver(configuration=configuration)
drv = get_configured_driver('server', 'path')
drv.nfs_ops = ops

ops.delete_volume('server', 'path', 'sr_uuid', 'vdi_uuid')
Expand All @@ -131,11 +129,7 @@ def test_remove_export_does_not_raise_exception(self):
def test_initialize_connection(self):
mock = mox.Mox()

configuration = mox.MockObject(conf.Configuration)
configuration.xenapi_nfs_server = 'server'
configuration.xenapi_nfs_serverpath = 'path'
configuration.append_config_values(mox.IgnoreArg())
drv = driver.XenAPINFSDriver(configuration=configuration)
drv = get_configured_driver('server', 'path')

mock.ReplayAll()
result = drv.initialize_connection(
Expand Down Expand Up @@ -166,12 +160,8 @@ def test_initialize_connection(self):

def test_initialize_connection_null_values(self):
mock = mox.Mox()
configuration = mox.MockObject(conf.Configuration)
configuration.xenapi_nfs_server = 'server'
configuration.xenapi_nfs_serverpath = 'path'
configuration.append_config_values(mox.IgnoreArg())

drv = driver.XenAPINFSDriver(configuration=configuration)
drv = get_configured_driver('server', 'path')

mock.ReplayAll()
result = drv.initialize_connection(
Expand Down Expand Up @@ -203,12 +193,7 @@ def test_initialize_connection_null_values(self):
def _setup_mock_driver(self, server, serverpath, sr_base_path="_srbp"):
mock = mox.Mox()

configuration = mox.MockObject(conf.Configuration)
configuration.xenapi_nfs_server = server
configuration.xenapi_nfs_serverpath = serverpath
configuration.append_config_values(mox.IgnoreArg())

drv = driver.XenAPINFSDriver(configuration=configuration)
drv = get_configured_driver(server, serverpath)
ops = mock.CreateMock(lib.NFSBasedVolumeOperations)
db = mock.CreateMock(db_api)
drv.nfs_ops = ops
Expand Down Expand Up @@ -323,3 +308,31 @@ def test_copy_image_to_volume_fail(self):
MockContext('token'), volume, "ignore", "image_id"))

mock.VerifyAll()

def test_get_volume_stats_reports_required_keys(self):
drv = get_configured_driver()

stats = drv.get_volume_stats()

required_metrics = [
'volume_backend_name', 'vendor_name', 'driver_version',
'storage_protocol', 'total_capacity_gb', 'free_capacity_gb',
'reserved_percentage'
]

for metric in required_metrics:
self.assertTrue(metric in stats)

def test_get_volume_stats_reports_unknown_cap(self):
drv = get_configured_driver()

stats = drv.get_volume_stats()

self.assertEquals('unknown', stats['free_capacity_gb'])

def test_reported_driver_type(self):
drv = get_configured_driver()

stats = drv.get_volume_stats()

self.assertEquals('xensm', stats['storage_protocol'])
13 changes: 13 additions & 0 deletions cinder/volume/drivers/xenapi/sm.py
Expand Up @@ -200,3 +200,16 @@ def copy_volume_to_image(self, context, volume, image_service, image_meta):
image_id,
auth_token,
FLAGS.xenapi_sr_base_path)

def get_volume_stats(self, refresh=False):
if refresh or not self._stats:
self._stats = dict(
volume_backend_name='XenAPINFS',
vendor_name='Open Source',
driver_version='1.0',
storage_protocol='xensm',
total_capacity_gb='unknown',
free_capacity_gb='unknown',
reserved_percentage=0)

return self._stats

0 comments on commit b0cdbdf

Please sign in to comment.