]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Python 3: Replace reduce and xrange with six.moves
authorAnkit Agrawal <ankit11.agrawal@nttdata.com>
Fri, 15 Jan 2016 09:56:56 +0000 (01:56 -0800)
committerAnkit Agrawal <ankit11.agrawal@nttdata.com>
Fri, 15 Jan 2016 10:34:56 +0000 (02:34 -0800)
1. Builtin function 'reduce' in Python 2 has been moved to standard
library module in Python 3 [1]. To make code compatible, replaced
reduce(expr) with six.moves.reduce(expr).
2. xrange is renamed to range in Python 3, replaced it with
six.moves.range
3. Added __bool__() method in FeatureState class to make it python 3
compatible because Python 3 calls the __bool__() method instead of
__nonzero__ when evaluating an instance in a boolean context.
4. Added this test case to tests-py3.txt.

[1] http://python3porting.com/stdlib.html#moved-builtins

Closes-Bug: 1530249
Change-Id: I376cd643b9f58358a3e147532dafe77a7325a114

cinder/tests/unit/volume/drivers/netapp/eseries/test_library.py
cinder/volume/drivers/netapp/utils.py
tests-py3.txt

index 66d6663d8a75067ede9fb5d59d7b71f7b9e85c57..1d1e49764bd9b89d8220b212e18709a9c977f3f1 100644 (file)
@@ -24,6 +24,8 @@ import time
 import mock
 from oslo_utils import units
 import six
+from six.moves import range
+from six.moves import reduce
 
 from cinder import exception
 from cinder import test
@@ -152,7 +154,7 @@ class NetAppEseriesLibraryTestCase(test.TestCase):
                          new_attr=mock.Mock(return_value=system))
         self.mock_object(self.library._client, 'update_stored_system_password')
         self.mock_object(time, 'time', new_attr = mock.Mock(
-            side_effect=xrange(0, 60, 5)))
+            side_effect=range(0, 60, 5)))
 
         self.assertRaisesRegexp(exception.NetAppDriverException,
                                 'bad.*?status',
@@ -1327,7 +1329,7 @@ class NetAppEseriesLibraryMultiAttachTestCase(test.TestCase):
         """Test volume extend with a thick-provisioned volume"""
 
         def get_copy_progress():
-            for eta in xrange(5, -1, -1):
+            for eta in range(5, -1, -1):
                 action_status = 'none' if eta == 0 else 'remappingDve'
                 complete = action_status == 'none'
                 yield complete, action_status, eta
index 0c1c7c0fc80370d2b723a4c915ac6ae6c97e308b..bb472b0844a63025fa4d32625cbdd0d42c6327e2 100644 (file)
@@ -490,3 +490,10 @@ class FeatureState(object):
         :returns: True if the feature is supported, otherwise False
         """
         return self.supported
+
+    def __bool__(self):
+        """py3 Allow a FeatureState object to be tested for truth value
+
+        :returns: True if the feature is supported, otherwise False
+        """
+        return self.supported
index 0390be76620c3a664737791d336c4acc014f29d1..2e21480c19884be38cef395957daf97dc570baf5 100644 (file)
@@ -151,6 +151,7 @@ cinder.tests.unit.test_vzstorage
 cinder.tests.unit.test_xio
 cinder.tests.unit.test_zfssa
 cinder.tests.unit.volume.drivers.emc.scaleio
+cinder.tests.unit.volume.drivers.netapp.eseries.test_library
 cinder.tests.unit.volume.drivers.test_fujitsu
 cinder.tests.unit.volume.flows.test_create_volume_flow
 cinder.tests.unit.windows.test_smbfs