From: Thang Pham Date: Thu, 27 Mar 2014 16:18:35 +0000 (-0400) Subject: Added unit test cases for _is_share_eligible in NFS driver. X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=e5afa13f0c2d59b3e4abbad77bf9997d849f3290;p=openstack-build%2Fcinder-build.git Added unit test cases for _is_share_eligible in NFS driver. 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 --- diff --git a/cinder/tests/test_nfs.py b/cinder/tests/test_nfs.py index 27b38fc1c..af624718b 100644 --- a/cinder/tests/test_nfs.py +++ b/cinder/tests/test_nfs.py @@ -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))