]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Added unit test cases for _is_share_eligible in NFS driver.
authorThang Pham <thang.g.pham@gmail.com>
Thu, 27 Mar 2014 16:18:35 +0000 (12:18 -0400)
committerThang Pham <thang.g.pham@gmail.com>
Tue, 8 Apr 2014 21:23:37 +0000 (17:23 -0400)
The generic NFS driver (under cinder/volume/drivers/nfs.py) has
a method called _is_share_eligible, which checks if a given NFS
share meet user specified conditions, such as:
  1. The ratio of actual space (used_space / total_space) is
     less than 'nfs_used_ratio'.
  2. There is enough space is available for the new volume.
This patch adds the corresponding unit test case for it.

Change-Id: I4489cbbca0a1a75a1144a87628843baf0a92f8a8
Closes-Bug: #1298414

cinder/tests/test_nfs.py

index 27b38fc1cde7e48ad34f0ecb0d6255d43ea43eed..af624718b9cc4cfa7165bd1ca646dcb3e12d66ea 100644 (file)
@@ -629,3 +629,61 @@ class NfsDriverTestCase(test.TestCase):
         self.assertEqual(drv._stats['free_capacity_gb'], 5.0)
 
         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')\
+                as mock_get_capacity_info:
+            mock_get_capacity_info.return_value = (total_size,
+                                                   total_available,
+                                                   total_allocated)
+            return self._driver._is_share_eligible('fake_share',
+                                                   requested_volume_size)
+
+    def test_is_share_eligible(self):
+        total_size = 100.0 * units.GiB
+        total_available = 90.0 * units.GiB
+        total_allocated = 10.0 * units.GiB
+        requested_volume_size = 1  # GiB
+
+        self.assertTrue(self._check_is_share_eligible(total_size,
+                                                      total_available,
+                                                      total_allocated,
+                                                      requested_volume_size))
+
+    def test_is_share_eligible_above_used_ratio(self):
+        total_size = 100.0 * units.GiB
+        total_available = 4.0 * units.GiB
+        total_allocated = 96.0 * units.GiB
+        requested_volume_size = 1  # GiB
+
+        # Check used > used_ratio statement entered
+        self.assertFalse(self._check_is_share_eligible(total_size,
+                                                       total_available,
+                                                       total_allocated,
+                                                       requested_volume_size))
+
+    def test_is_share_eligible_above_oversub_ratio(self):
+        total_size = 100.0 * units.GiB
+        total_available = 10.0 * units.GiB
+        total_allocated = 90.0 * units.GiB
+        requested_volume_size = 10  # GiB
+
+        # Check apparent_available <= requested_volume_size statement entered
+        self.assertFalse(self._check_is_share_eligible(total_size,
+                                                       total_available,
+                                                       total_allocated,
+                                                       requested_volume_size))
+
+    def test_is_share_eligible_reserved_space_above_oversub_ratio(self):
+        total_size = 100.0 * units.GiB
+        total_available = 10.0 * units.GiB
+        total_allocated = 100.0 * units.GiB
+        requested_volume_size = 1  # GiB
+
+        # Check total_allocated / total_size >= oversub_ratio
+        # statement entered
+        self.assertFalse(self._check_is_share_eligible(total_size,
+                                                       total_available,
+                                                       total_allocated,
+                                                       requested_volume_size))