]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
RemoteFS: Reporting configured reserved_percentage in _update_volume_stats
authorBharat Kumar Kobagana <bharat.kobagana@redhat.com>
Tue, 12 May 2015 12:56:34 +0000 (18:26 +0530)
committerBharat Kumar Kobagana <bharat.kobagana@redhat.com>
Wed, 1 Jul 2015 17:13:31 +0000 (22:43 +0530)
In remotefs, reserved_percentage will be always reported up to the
scheduler as 0, irrespective of the value of cfg.reserved_percentage.

This patch modifies the code to use reserved_percentage configuration
parameter while updating status.

Closes-Bug: #1458640
Change-Id: I53917835b79797417aca7b1b3c794c84b6143ab5

cinder/tests/unit/test_nfs.py
cinder/volume/drivers/remotefs.py

index 111c9277753d992d5c0e5d346941e26a43445290..8a2ee1bfc3e6b5adf6ba98722859b2b85c645f44 100644 (file)
@@ -371,6 +371,7 @@ class NfsDriverTestCase(test.TestCase):
         self.configuration.nas_ip = None
         self.configuration.nas_share_path = None
         self.configuration.nas_mount_options = None
+        self.configuration.reserved_percentage = 0
         self.configuration.volume_dd_blocksize = '1M'
         self._driver = nfs.NfsDriver(configuration=self.configuration)
         self._driver.shares = {}
@@ -848,9 +849,39 @@ class NfsDriverTestCase(test.TestCase):
         drv.get_volume_stats()
         self.assertEqual(30.0, drv._stats['total_capacity_gb'])
         self.assertEqual(5.0, drv._stats['free_capacity_gb'])
+        self.assertEqual(0, drv._stats['reserved_percentage'])
 
         mox.VerifyAll()
 
+    def test_get_volume_stats_with_non_zero_reserved_percentage(self):
+        """get_volume_stats must fill the correct values."""
+        mox = self.mox
+        drv = self._driver
+        self.configuration.reserved_percentage = 10.0
+
+        drv._mounted_shares = [self.TEST_NFS_EXPORT1, self.TEST_NFS_EXPORT2]
+
+        mox.StubOutWithMock(drv, '_ensure_shares_mounted')
+        mox.StubOutWithMock(drv, '_get_capacity_info')
+
+        drv._ensure_shares_mounted()
+
+        drv._get_capacity_info(self.TEST_NFS_EXPORT1).\
+            AndReturn((10 * units.Gi, 2 * units.Gi,
+                       2 * units.Gi))
+        drv._get_capacity_info(self.TEST_NFS_EXPORT2).\
+            AndReturn((20 * units.Gi, 3 * units.Gi,
+                       3 * units.Gi))
+
+        mox.ReplayAll()
+
+        drv.get_volume_stats()
+
+        self.assertEqual(30.0, drv._stats['total_capacity_gb'])
+        self.assertEqual(5.0, drv._stats['free_capacity_gb'])
+        self.assertEqual(10.0, drv._stats['reserved_percentage'])
+        mox.VerifyAll()
+
     def _check_is_share_eligible(self, total_size, total_available,
                                  total_allocated, requested_volume_size):
         with mock.patch.object(self._driver, '_get_capacity_info')\
index 3cadd7c4aaf873a387a013051a02149ba8bcafee..f08b009c80a198c91cd7b724ed5068f3f67a9d5d 100644 (file)
@@ -505,7 +505,7 @@ class RemoteFSDriver(driver.LocalVD, driver.TransferVD, driver.BaseVD):
 
         data['total_capacity_gb'] = global_capacity / float(units.Gi)
         data['free_capacity_gb'] = global_free / float(units.Gi)
-        data['reserved_percentage'] = 0
+        data['reserved_percentage'] = self.configuration.reserved_percentage
         data['QoS_support'] = False
         self._stats = data