]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Port vzstorage to Python 3
authorVictor Stinner <vstinner@redhat.com>
Sun, 8 Nov 2015 21:04:45 +0000 (22:04 +0100)
committerVictor Stinner <vstinner@redhat.com>
Sun, 8 Nov 2015 21:07:57 +0000 (22:07 +0100)
* vzstorage: replace a/b with a//b to use integer division on
  Python 3.
* fix os.path.exists mock: only override return for path /fake
  (shares config)
* tests-py3.txt: add cinder.tests.unit.test_vzstorage

Note: remove also spaces in parameters in two functions calls to
respect the PEP 8.

Partial-Implements: blueprint cinder-python3
Change-Id: I7cee7009d8bc87cd0294e90cb2967f4560276994

cinder/tests/unit/test_vzstorage.py
cinder/volume/drivers/vzstorage.py
tests-py3.txt

index 50332ae467467d079c269992712ec85a7360145d..cb05922eebec026c1bc00b60c0d4cafbdb5a300f 100644 (file)
@@ -27,6 +27,9 @@ from cinder import test
 from cinder.volume.drivers import vzstorage
 
 
+_orig_path_exists = os.path.exists
+
+
 class VZStorageTestCase(test.TestCase):
 
     _FAKE_SHARE = "10.0.0.1,10.0.0.2:/cluster123:123123"
@@ -69,21 +72,31 @@ class VZStorageTestCase(test.TestCase):
         self._vz_driver._execute = mock.Mock()
         self._vz_driver.base = self._FAKE_MNT_BASE
 
+    def _path_exists(self, path):
+        if path.startswith(self._FAKE_VZ_CONFIG.vzstorage_shares_config):
+            return True
+        return _orig_path_exists(path)
+
+    def _path_dont_exists(self, path):
+        if path.startswith('/fake'):
+            return False
+        return _orig_path_exists(path)
+
     @mock.patch('os.path.exists')
     def test_setup_ok(self, mock_exists):
-        mock_exists.return_value = True
+        mock_exists.side_effect = self._path_exists
         self._vz_driver.do_setup(mock.sentinel.context)
 
     @mock.patch('os.path.exists')
     def test_setup_missing_shares_conf(self, mock_exists):
-        mock_exists.return_value = False
+        mock_exists.side_effect = self._path_dont_exists
         self.assertRaises(exception.VzStorageException,
                           self._vz_driver.do_setup,
                           mock.sentinel.context)
 
     @mock.patch('os.path.exists')
     def test_setup_invalid_usage_ratio(self, mock_exists):
-        mock_exists.return_value = True
+        mock_exists.side_effect = self._path_exists
         self._vz_driver.configuration.vzstorage_used_ratio = 1.2
         self.assertRaises(exception.VzStorageException,
                           self._vz_driver.do_setup,
@@ -91,7 +104,7 @@ class VZStorageTestCase(test.TestCase):
 
     @mock.patch('os.path.exists')
     def test_setup_invalid_usage_ratio2(self, mock_exists):
-        mock_exists.return_value = True
+        mock_exists.side_effect = self._path_exists
         self._vz_driver.configuration.vzstorage_used_ratio = 0
         self.assertRaises(exception.VzStorageException,
                           self._vz_driver.do_setup,
@@ -99,7 +112,7 @@ class VZStorageTestCase(test.TestCase):
 
     @mock.patch('os.path.exists')
     def test_setup_invalid_mount_point_base(self, mock_exists):
-        mock_exists.return_value = True
+        mock_exists.side_effect = self._path_exists
         conf = copy.copy(self._FAKE_VZ_CONFIG)
         conf.vzstorage_mount_point_base = './tmp'
         vz_driver = vzstorage.VZStorageDriver(configuration=conf)
@@ -109,7 +122,7 @@ class VZStorageTestCase(test.TestCase):
 
     @mock.patch('os.path.exists')
     def test_setup_no_vzstorage(self, mock_exists):
-        mock_exists.return_value = True
+        mock_exists.side_effect = self._path_exists
         exc = OSError()
         exc.errno = errno.ENOENT
         self._vz_driver._execute.side_effect = exc
@@ -166,7 +179,7 @@ class VZStorageTestCase(test.TestCase):
         drv = self._vz_driver
         cap_info = (100 * units.Gi, 40 * units.Gi, 60 * units.Gi)
         with mock.patch.object(drv, '_get_capacity_info',
-                               return_value = cap_info):
+                               return_value=cap_info):
             ret = drv._is_share_eligible(self._FAKE_SHARE, 50)
             self.assertFalse(ret)
 
@@ -174,7 +187,7 @@ class VZStorageTestCase(test.TestCase):
         drv = self._vz_driver
         cap_info = (100 * units.Gi, 40 * units.Gi, 60 * units.Gi)
         with mock.patch.object(drv, '_get_capacity_info',
-                               return_value = cap_info):
+                               return_value=cap_info):
             ret = drv._is_share_eligible(self._FAKE_SHARE, 30)
             self.assertTrue(ret)
 
index f1659004f083346f4333dda25cb6175a4f31dc71..aaa304e0fedb051faa602b7ab80f7da196198a37 100644 (file)
@@ -219,7 +219,7 @@ class VZStorageDriver(remotefs_drv.RemoteFSSnapDriver):
 
         total_size, available, allocated = self._get_capacity_info(vz_share)
 
-        if (allocated + volume_size) / total_size > used_ratio:
+        if (allocated + volume_size) // total_size > used_ratio:
             LOG.debug('_is_share_eligible: %s is above '
                       'vzstorage_used_ratio.', vz_share)
             return False
index 8e07e9e3cb1d4a438d9a238669979f85bc11686a..179e93af11d443bc5ec3f836ce07b62a904c127d 100644 (file)
@@ -120,6 +120,7 @@ cinder.tests.unit.test_volume_transfer
 cinder.tests.unit.test_volume_types
 cinder.tests.unit.test_volume_types_extra_specs
 cinder.tests.unit.test_volume_utils
+cinder.tests.unit.test_vzstorage
 cinder.tests.unit.volume.drivers.emc.scaleio
 cinder.tests.unit.volume.flows.test_create_volume_flow
 cinder.tests.unit.windows.test_smbfs