From b0cdbdf71bdd675da6d601a711265996878a4e6f Mon Sep 17 00:00:00 2001 From: Mate Lakat Date: Mon, 18 Feb 2013 12:45:37 +0000 Subject: [PATCH] XenAPINFS: fix capacity reporting 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 --- cinder/tests/test_xenapi_sm.py | 69 ++++++++++++++++++------------ cinder/volume/drivers/xenapi/sm.py | 13 ++++++ 2 files changed, 54 insertions(+), 28 deletions(-) diff --git a/cinder/tests/test_xenapi_sm.py b/cinder/tests/test_xenapi_sm.py index 7621cdaf01..b652ed9802 100644 --- a/cinder/tests/test_xenapi_sm.py +++ b/cinder/tests/test_xenapi_sm.py @@ -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): @@ -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( @@ -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') @@ -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( @@ -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( @@ -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 @@ -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']) diff --git a/cinder/volume/drivers/xenapi/sm.py b/cinder/volume/drivers/xenapi/sm.py index 3bf093b046..73f1e484fd 100644 --- a/cinder/volume/drivers/xenapi/sm.py +++ b/cinder/volume/drivers/xenapi/sm.py @@ -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