]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
XenAPINFS: fix capacity reporting
authorMate Lakat <mate.lakat@citrix.com>
Mon, 18 Feb 2013 12:45:37 +0000 (12:45 +0000)
committerMate Lakat <mate.lakat@citrix.com>
Tue, 19 Feb 2013 09:38:05 +0000 (09:38 +0000)
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
cinder/volume/drivers/xenapi/sm.py

index 7621cdaf017d500cd1666a13197b302515864a46..b652ed9802cf28953082f8790b84ef731080e582 100644 (file)
@@ -32,6 +32,14 @@ class MockContext(object):
         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 @@ class DriverTestCase(unittest.TestCase):
     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 @@ class DriverTestCase(unittest.TestCase):
     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 @@ class DriverTestCase(unittest.TestCase):
     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 @@ class DriverTestCase(unittest.TestCase):
 
     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 @@ class DriverTestCase(unittest.TestCase):
     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 @@ class DriverTestCase(unittest.TestCase):
                 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'])
index 3bf093b0469a4511bd01d2cad4e1486002ff22c7..73f1e484fda773a676d4f7ebd15922080f749c06 100644 (file)
@@ -200,3 +200,16 @@ class XenAPINFSDriver(driver.VolumeDriver):
             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