From: Ankit Agrawal Date: Fri, 15 Jan 2016 09:56:56 +0000 (-0800) Subject: Python 3: Replace reduce and xrange with six.moves X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=9cc2b79301d73929c6f673b4314950b8e0013a70;p=openstack-build%2Fcinder-build.git Python 3: Replace reduce and xrange with six.moves 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 --- diff --git a/cinder/tests/unit/volume/drivers/netapp/eseries/test_library.py b/cinder/tests/unit/volume/drivers/netapp/eseries/test_library.py index 66d6663d8..1d1e49764 100644 --- a/cinder/tests/unit/volume/drivers/netapp/eseries/test_library.py +++ b/cinder/tests/unit/volume/drivers/netapp/eseries/test_library.py @@ -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 diff --git a/cinder/volume/drivers/netapp/utils.py b/cinder/volume/drivers/netapp/utils.py index 0c1c7c0fc..bb472b084 100644 --- a/cinder/volume/drivers/netapp/utils.py +++ b/cinder/volume/drivers/netapp/utils.py @@ -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 diff --git a/tests-py3.txt b/tests-py3.txt index 0390be766..2e21480c1 100644 --- a/tests-py3.txt +++ b/tests-py3.txt @@ -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