From: Bharat Kumar Kobagana <bharat.kobagana@redhat.com>
Date: Tue, 12 May 2015 12:56:34 +0000 (+0530)
Subject: RemoteFS: Reporting configured reserved_percentage in _update_volume_stats
X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=53b736fb658b7d301ead1d23e3cddc4b0cdd832f;p=openstack-build%2Fcinder-build.git

RemoteFS: Reporting configured reserved_percentage in _update_volume_stats

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
---

diff --git a/cinder/tests/unit/test_nfs.py b/cinder/tests/unit/test_nfs.py
index 111c92777..8a2ee1bfc 100644
--- a/cinder/tests/unit/test_nfs.py
+++ b/cinder/tests/unit/test_nfs.py
@@ -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')\
diff --git a/cinder/volume/drivers/remotefs.py b/cinder/volume/drivers/remotefs.py
index 3cadd7c4a..f08b009c8 100644
--- a/cinder/volume/drivers/remotefs.py
+++ b/cinder/volume/drivers/remotefs.py
@@ -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