From 8e63cccb652cfc4bba58c5068466a588a7094376 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 25 May 2015 17:08:00 +0200 Subject: [PATCH] Replace xrange() with six.moves.range() Add "from six.moves import range" to replace the builtin range() function with six.moves.range() to always create an iterator, instead of creating a temporary list. Replace "xrange" with "range". Don't add the import for ranges of 1024 items or less. Blueprint cinder-python3 Change-Id: If618b4e810e444f7eb6592bb2398805e9d14d548 --- cinder/backup/drivers/ceph.py | 5 +- cinder/common/sqlalchemyutils.py | 5 +- cinder/image/glance.py | 3 +- cinder/tests/unit/api/openstack/test_wsgi.py | 4 +- cinder/tests/unit/api/v1/test_limits.py | 3 +- cinder/tests/unit/api/v2/test_limits.py | 3 +- cinder/tests/unit/api/v2/test_volumes.py | 7 +-- .../unit/backup/drivers/test_backup_nfs.py | 2 +- .../unit/scheduler/test_chance_weigher.py | 2 +- .../tests/unit/scheduler/test_host_manager.py | 6 +-- cinder/tests/unit/test_backup_ceph.py | 9 ++-- cinder/tests/unit/test_backup_swift.py | 2 +- cinder/tests/unit/test_db_api.py | 48 +++++++++---------- cinder/tests/unit/test_utils.py | 3 +- cinder/tests/unit/test_volume.py | 4 +- cinder/volume/drivers/emc/emc_vnx_cli.py | 3 +- cinder/volume/drivers/eqlx.py | 3 +- .../drivers/netapp/eseries/host_mapper.py | 1 + cinder/volume/drivers/srb.py | 3 +- cinder/volume/drivers/violin/v6000_common.py | 2 +- cinder/volume/drivers/violin/v6000_fcp.py | 3 +- cinder/volume/drivers/violin/v6000_iscsi.py | 2 +- cinder/volume/utils.py | 3 +- doc/ext/cinder_todo.py | 2 +- 24 files changed, 71 insertions(+), 57 deletions(-) diff --git a/cinder/backup/drivers/ceph.py b/cinder/backup/drivers/ceph.py index 001c39a17..62de90409 100644 --- a/cinder/backup/drivers/ceph.py +++ b/cinder/backup/drivers/ceph.py @@ -54,6 +54,7 @@ from oslo_log import log as logging from oslo_utils import encodeutils from oslo_utils import excutils from oslo_utils import units +from six.moves import range from cinder.backup import driver from cinder import exception @@ -284,7 +285,7 @@ class CephBackupDriver(driver.BackupDriver): else: zeroes = '\0' * length chunks = int(length / self.chunk_size) - for chunk in xrange(0, chunks): + for chunk in range(0, chunks): LOG.debug("Writing zeroes chunk %d", chunk) volume.write(zeroes) volume.flush() @@ -306,7 +307,7 @@ class CephBackupDriver(driver.BackupDriver): LOG.debug("%(chunks)s chunks of %(bytes)s bytes to be transferred", {'chunks': chunks, 'bytes': self.chunk_size}) - for chunk in xrange(0, chunks): + for chunk in range(0, chunks): before = time.time() data = src.read(self.chunk_size) # If we have reach end of source, discard any extraneous bytes from diff --git a/cinder/common/sqlalchemyutils.py b/cinder/common/sqlalchemyutils.py index 4ff6711d2..4ff438ce3 100644 --- a/cinder/common/sqlalchemyutils.py +++ b/cinder/common/sqlalchemyutils.py @@ -19,6 +19,7 @@ """Implementation of paginate query.""" from oslo_log import log as logging +from six.moves import range import sqlalchemy from cinder import exception @@ -100,9 +101,9 @@ def paginate_query(query, model, limit, sort_keys, marker=None, # Build up an array of sort criteria as in the docstring criteria_list = [] - for i in xrange(0, len(sort_keys)): + for i in range(0, len(sort_keys)): crit_attrs = [] - for j in xrange(0, i): + for j in range(0, i): model_attr = getattr(model, sort_keys[j]) crit_attrs.append((model_attr == marker_values[j])) diff --git a/cinder/image/glance.py b/cinder/image/glance.py index 6825b1e6e..893e1ab3c 100644 --- a/cinder/image/glance.py +++ b/cinder/image/glance.py @@ -32,6 +32,7 @@ from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import timeutils import six +from six.moves import range from six.moves import urllib from cinder import exception @@ -169,7 +170,7 @@ class GlanceClientWrapper(object): glanceclient.exc.CommunicationError) num_attempts = 1 + CONF.glance_num_retries - for attempt in xrange(1, num_attempts + 1): + for attempt in range(1, num_attempts + 1): client = self.client or self._create_onetime_client(context, version) try: diff --git a/cinder/tests/unit/api/openstack/test_wsgi.py b/cinder/tests/unit/api/openstack/test_wsgi.py index 82f49ea78..bcf52a5ee 100644 --- a/cinder/tests/unit/api/openstack/test_wsgi.py +++ b/cinder/tests/unit/api/openstack/test_wsgi.py @@ -114,7 +114,7 @@ class RequestTest(test.TestCase): self.assertIsNone(request.cached_resource_by_id('r-0')) resources = [] - for x in xrange(3): + for x in range(3): resources.append({'id': 'r-%s' % x}) # Cache an empty list of resources using the default name @@ -161,7 +161,7 @@ class RequestTest(test.TestCase): r = wsgi.Request.blank('/foo') resources = [] - for x in xrange(3): + for x in range(3): resources.append({'id': 'id%s' % x}) # Store 2 diff --git a/cinder/tests/unit/api/v1/test_limits.py b/cinder/tests/unit/api/v1/test_limits.py index 9d0f31c33..d87cb424f 100644 --- a/cinder/tests/unit/api/v1/test_limits.py +++ b/cinder/tests/unit/api/v1/test_limits.py @@ -23,6 +23,7 @@ from lxml import etree from oslo_serialization import jsonutils import six from six.moves import http_client +from six.moves import range import webob from cinder.api.v1 import limits @@ -401,7 +402,7 @@ class LimiterTest(BaseLimitTestSuite): def _check(self, num, verb, url, username=None): """Check and yield results from checks.""" - for x in xrange(num): + for x in range(num): yield self.limiter.check_for_delay(verb, url, username)[0] def _check_sum(self, num, verb, url, username=None): diff --git a/cinder/tests/unit/api/v2/test_limits.py b/cinder/tests/unit/api/v2/test_limits.py index 9d5291079..9f3a02755 100644 --- a/cinder/tests/unit/api/v2/test_limits.py +++ b/cinder/tests/unit/api/v2/test_limits.py @@ -23,6 +23,7 @@ from lxml import etree from oslo_serialization import jsonutils import six from six.moves import http_client +from six.moves import range import webob from cinder.api.v2 import limits @@ -406,7 +407,7 @@ class LimiterTest(BaseLimitTestSuite): def _check(self, num, verb, url, username=None): """Check and yield results from checks.""" - for x in xrange(num): + for x in range(num): yield self.limiter.check_for_delay(verb, url, username)[0] def _check_sum(self, num, verb, url, username=None): diff --git a/cinder/tests/unit/api/v2/test_volumes.py b/cinder/tests/unit/api/v2/test_volumes.py index 941300667..bf675d2d7 100644 --- a/cinder/tests/unit/api/v2/test_volumes.py +++ b/cinder/tests/unit/api/v2/test_volumes.py @@ -21,6 +21,7 @@ import mock from oslo_config import cfg from oslo_utils import timeutils import six +from six.moves import range from six.moves import urllib import webob @@ -1118,7 +1119,7 @@ class VolumeApiTest(test.TestCase): filters=None, viewable_admin_meta=False): vols = [stubs.stub_volume(i) - for i in xrange(CONF.osapi_max_limit)] + for i in range(CONF.osapi_max_limit)] if limit is None or limit >= len(vols): return vols return vols[:limit] @@ -1136,7 +1137,7 @@ class VolumeApiTest(test.TestCase): filters=None, viewable_admin_meta=False): vols = [stubs.stub_volume(i) - for i in xrange(100)] + for i in range(100)] if limit is None or limit >= len(vols): return vols return vols[:limit] @@ -1154,7 +1155,7 @@ class VolumeApiTest(test.TestCase): filters=None, viewable_admin_meta=False): vols = [stubs.stub_volume(i) - for i in xrange(CONF.osapi_max_limit + 100)] + for i in range(CONF.osapi_max_limit + 100)] if limit is None or limit >= len(vols): return vols return vols[:limit] diff --git a/cinder/tests/unit/backup/drivers/test_backup_nfs.py b/cinder/tests/unit/backup/drivers/test_backup_nfs.py index 183dd59f9..8c340fca0 100644 --- a/cinder/tests/unit/backup/drivers/test_backup_nfs.py +++ b/cinder/tests/unit/backup/drivers/test_backup_nfs.py @@ -289,7 +289,7 @@ class BackupNFSSwiftBasedTestCase(test.TestCase): mock.Mock(return_value=mock_remotefsclient)) # Remove tempdir. self.addCleanup(shutil.rmtree, self.temp_dir) - for _i in xrange(0, 128): + for _i in range(0, 128): self.volume_file.write(os.urandom(1024)) def test_backup_uncompressed(self): diff --git a/cinder/tests/unit/scheduler/test_chance_weigher.py b/cinder/tests/unit/scheduler/test_chance_weigher.py index 6c47daab0..e80a66d3f 100644 --- a/cinder/tests/unit/scheduler/test_chance_weigher.py +++ b/cinder/tests/unit/scheduler/test_chance_weigher.py @@ -62,6 +62,6 @@ class ChanceWeigherTestCase(test.TestCase): # the ChanceWeigher hm = host_manager.HostManager() fake_hosts = [host_manager.HostState('fake_host%s' % x) - for x in xrange(1, 5)] + for x in range(1, 5)] weighed_hosts = hm.get_weighed_hosts(fake_hosts, {}, 'ChanceWeigher') self.assertEqual(4, len(weighed_hosts)) diff --git a/cinder/tests/unit/scheduler/test_host_manager.py b/cinder/tests/unit/scheduler/test_host_manager.py index 101151b7a..61284590e 100644 --- a/cinder/tests/unit/scheduler/test_host_manager.py +++ b/cinder/tests/unit/scheduler/test_host_manager.py @@ -46,7 +46,7 @@ class HostManagerTestCase(test.TestCase): super(HostManagerTestCase, self).setUp() self.host_manager = host_manager.HostManager() self.fake_hosts = [host_manager.HostState('fake_host%s' % x) - for x in xrange(1, 5)] + for x in range(1, 5)] def test_choose_host_filters_not_found(self): self.flags(scheduler_default_filters='FakeFilterClass3') @@ -254,7 +254,7 @@ class HostManagerTestCase(test.TestCase): # Get host_state_map and make sure we have the first 4 hosts host_state_map = self.host_manager.host_state_map self.assertEqual(len(host_state_map), 3) - for i in xrange(3): + for i in range(3): volume_node = services[i] host = volume_node['host'] self.assertEqual(host_state_map[host].service, volume_node) @@ -280,7 +280,7 @@ class HostManagerTestCase(test.TestCase): # down, host4 is missing capabilities) host_state_map = self.host_manager.host_state_map self.assertEqual(len(host_state_map), 2) - for i in xrange(2): + for i in range(2): volume_node = services[i] host = volume_node['host'] self.assertEqual(host_state_map[host].service, diff --git a/cinder/tests/unit/test_backup_ceph.py b/cinder/tests/unit/test_backup_ceph.py index f65f3a487..5e8e83d4f 100644 --- a/cinder/tests/unit/test_backup_ceph.py +++ b/cinder/tests/unit/test_backup_ceph.py @@ -24,6 +24,7 @@ from oslo_concurrency import processutils from oslo_log import log as logging from oslo_serialization import jsonutils import six +from six.moves import range from cinder.backup import driver from cinder.backup.drivers import ceph @@ -171,7 +172,7 @@ class BackupCephTestCase(test.TestCase): # Create a file with some data in it. self.volume_file = tempfile.NamedTemporaryFile() self.addCleanup(self.volume_file.close) - for _i in xrange(0, self.num_chunks): + for _i in range(0, self.num_chunks): data = os.urandom(self.chunk_size) self.checksum.update(data) self.volume_file.write(data) @@ -285,7 +286,7 @@ class BackupCephTestCase(test.TestCase): checksum = hashlib.sha256() test_file.seek(0) - for _c in xrange(0, self.num_chunks): + for _c in range(0, self.num_chunks): checksum.update(test_file.read(self.chunk_size)) # Ensure the files are equal @@ -350,7 +351,7 @@ class BackupCephTestCase(test.TestCase): checksum = hashlib.sha256() test_file.seek(0) - for _c in xrange(0, self.num_chunks): + for _c in range(0, self.num_chunks): checksum.update(test_file.read(self.chunk_size)) # Ensure the files are equal @@ -627,7 +628,7 @@ class BackupCephTestCase(test.TestCase): checksum = hashlib.sha256() test_file.seek(0) - for _c in xrange(0, self.num_chunks): + for _c in range(0, self.num_chunks): checksum.update(test_file.read(self.chunk_size)) # Ensure the files are equal diff --git a/cinder/tests/unit/test_backup_swift.py b/cinder/tests/unit/test_backup_swift.py index 3f0afe3b1..01840f8e5 100644 --- a/cinder/tests/unit/test_backup_swift.py +++ b/cinder/tests/unit/test_backup_swift.py @@ -90,7 +90,7 @@ class BackupSwiftTestCase(test.TestCase): self.addCleanup(self.volume_file.close) # Remove tempdir. self.addCleanup(shutil.rmtree, self.temp_dir) - for _i in xrange(0, 128): + for _i in range(0, 128): self.volume_file.write(os.urandom(1024)) def test_backup_swift_url(self): diff --git a/cinder/tests/unit/test_db_api.py b/cinder/tests/unit/test_db_api.py index 2fc79fb2c..74cb105b7 100644 --- a/cinder/tests/unit/test_db_api.py +++ b/cinder/tests/unit/test_db_api.py @@ -268,34 +268,34 @@ class DBAPIVolumeTestCase(BaseTest): self.assertEqual(attachment['attached_host'], host_name) def test_volume_data_get_for_host(self): - for i in xrange(THREE): - for j in xrange(THREE): + for i in range(THREE): + for j in range(THREE): db.volume_create(self.ctxt, {'host': 'h%d' % i, 'size': ONE_HUNDREDS}) - for i in xrange(THREE): + for i in range(THREE): self.assertEqual((THREE, THREE_HUNDREDS), db.volume_data_get_for_host( self.ctxt, 'h%d' % i)) def test_volume_data_get_for_host_for_multi_backend(self): - for i in xrange(THREE): - for j in xrange(THREE): + for i in range(THREE): + for j in range(THREE): db.volume_create(self.ctxt, {'host': 'h%d@lvmdriver-1#lvmdriver-1' % i, 'size': ONE_HUNDREDS}) - for i in xrange(THREE): + for i in range(THREE): self.assertEqual((THREE, THREE_HUNDREDS), db.volume_data_get_for_host( self.ctxt, 'h%d@lvmdriver-1' % i)) def test_volume_data_get_for_project(self): - for i in xrange(THREE): - for j in xrange(THREE): + for i in range(THREE): + for j in range(THREE): db.volume_create(self.ctxt, {'project_id': 'p%d' % i, 'size': ONE_HUNDREDS, 'host': 'h-%d-%d' % (i, j), }) - for i in xrange(THREE): + for i in range(THREE): self.assertEqual((THREE, THREE_HUNDREDS), db.volume_data_get_for_project( self.ctxt, 'p%d' % i)) @@ -349,7 +349,7 @@ class DBAPIVolumeTestCase(BaseTest): def test_volume_get_all(self): volumes = [db.volume_create(self.ctxt, {'host': 'h%d' % i, 'size': i}) - for i in xrange(3)] + for i in range(3)] self._assertEqualListsOfObjects(volumes, db.volume_get_all( self.ctxt, None, None, ['host'], None)) @@ -366,10 +366,10 @@ class DBAPIVolumeTestCase(BaseTest): def test_volume_get_all_by_host(self): volumes = [] - for i in xrange(3): + for i in range(3): volumes.append([db.volume_create(self.ctxt, {'host': 'h%d' % i}) - for j in xrange(3)]) - for i in xrange(3): + for j in range(3)]) + for i in range(3): self._assertEqualListsOfObjects(volumes[i], db.volume_get_all_by_host( self.ctxt, 'h%d' % i)) @@ -377,7 +377,7 @@ class DBAPIVolumeTestCase(BaseTest): def test_volume_get_all_by_host_with_pools(self): volumes = [] vol_on_host_wo_pool = [db.volume_create(self.ctxt, {'host': 'foo'}) - for j in xrange(3)] + for j in range(3)] vol_on_host_w_pool = [db.volume_create( self.ctxt, {'host': 'foo#pool0'})] volumes.append((vol_on_host_wo_pool + @@ -424,10 +424,10 @@ class DBAPIVolumeTestCase(BaseTest): def test_volume_get_all_by_group(self): volumes = [] - for i in xrange(3): + for i in range(3): volumes.append([db.volume_create(self.ctxt, { - 'consistencygroup_id': 'g%d' % i}) for j in xrange(3)]) - for i in xrange(3): + 'consistencygroup_id': 'g%d' % i}) for j in range(3)]) + for i in range(3): self._assertEqualListsOfObjects(volumes[i], db.volume_get_all_by_group( self.ctxt, 'g%d' % i)) @@ -462,10 +462,10 @@ class DBAPIVolumeTestCase(BaseTest): def test_volume_get_all_by_project(self): volumes = [] - for i in xrange(3): + for i in range(3): volumes.append([db.volume_create(self.ctxt, { - 'project_id': 'p%d' % i}) for j in xrange(3)]) - for i in xrange(3): + 'project_id': 'p%d' % i}) for j in range(3)]) + for i in range(3): self._assertEqualListsOfObjects(volumes[i], db.volume_get_all_by_project( self.ctxt, 'p%d' % i, None, @@ -567,21 +567,21 @@ class DBAPIVolumeTestCase(BaseTest): {'project_id': 'g1', 'display_name': 'name_%d' % i, 'size': 1}) - for i in xrange(2)]) + for i in range(2)]) vols.extend([db.volume_create(self.ctxt, {'project_id': 'g1', 'display_name': 'name_%d' % i, 'size': 2}) - for i in xrange(2)]) + for i in range(2)]) vols.extend([db.volume_create(self.ctxt, {'project_id': 'g1', 'display_name': 'name_%d' % i}) - for i in xrange(2)]) + for i in range(2)]) vols.extend([db.volume_create(self.ctxt, {'project_id': 'g2', 'display_name': 'name_%d' % i, 'size': 1}) - for i in xrange(2)]) + for i in range(2)]) # By project, filter on size and name filters = {'size': '1'} diff --git a/cinder/tests/unit/test_utils.py b/cinder/tests/unit/test_utils.py index 4631a723b..ecb8d7c38 100644 --- a/cinder/tests/unit/test_utils.py +++ b/cinder/tests/unit/test_utils.py @@ -25,6 +25,7 @@ from oslo_config import cfg from oslo_utils import timeutils import paramiko import six +from six.moves import range import cinder from cinder import exception @@ -1479,7 +1480,7 @@ class TestRetryDecorator(test.TestCase): expected_sleep_arg = [] - for i in xrange(retries): + for i in range(retries): if i > 0: interval *= backoff_rate expected_sleep_arg.append(float(interval)) diff --git a/cinder/tests/unit/test_volume.py b/cinder/tests/unit/test_volume.py index 7b7fedfb9..651a8174b 100644 --- a/cinder/tests/unit/test_volume.py +++ b/cinder/tests/unit/test_volume.py @@ -2790,7 +2790,7 @@ class VolumeTestCase(BaseVolumeTestCase): # FIXME(jdg): What is this actually testing? # We never call the internal _check method? - for _index in xrange(100): + for _index in range(100): tests_utils.create_volume(self.context, **self.volume_params) for volume_id in volume_ids: self.volume.delete_volume(self.context, volume_id) @@ -5832,7 +5832,7 @@ class ISCSITestCase(DriverTestCase): def _attach_volume(self): """Attach volumes to an instance.""" volume_id_list = [] - for index in xrange(3): + for index in range(3): vol = {} vol['size'] = 0 vol_ref = db.volume_create(self.context, vol) diff --git a/cinder/volume/drivers/emc/emc_vnx_cli.py b/cinder/volume/drivers/emc/emc_vnx_cli.py index 88dfa60e7..f9702101b 100644 --- a/cinder/volume/drivers/emc/emc_vnx_cli.py +++ b/cinder/volume/drivers/emc/emc_vnx_cli.py @@ -31,6 +31,7 @@ from oslo_serialization import jsonutils as json from oslo_utils import excutils from oslo_utils import timeutils import six +from six.moves import range import taskflow.engines from taskflow.patterns import linear_flow from taskflow import task @@ -1694,7 +1695,7 @@ class EMCVnxCliBase(object): LOG.info(_LI("initiator_auto_registration: False. " "Initiator auto registration is not enabled. " "Please register initiator manually.")) - self.hlu_set = set(xrange(1, self.max_luns_per_sg + 1)) + self.hlu_set = set(range(1, self.max_luns_per_sg + 1)) self._client = CommandLineHelper(self.configuration) conf_pools = self.configuration.safe_get("storage_vnx_pool_names") self.storage_pools = self._get_managed_storage_pools(conf_pools) diff --git a/cinder/volume/drivers/eqlx.py b/cinder/volume/drivers/eqlx.py index 3a5843ea5..622982bda 100644 --- a/cinder/volume/drivers/eqlx.py +++ b/cinder/volume/drivers/eqlx.py @@ -25,6 +25,7 @@ from oslo_concurrency import processutils from oslo_config import cfg from oslo_log import log as logging from oslo_utils import excutils +from six.moves import range from cinder import exception from cinder.i18n import _, _LE, _LW, _LI @@ -344,7 +345,7 @@ class DellEQLSanISCSIDriver(san.SanISCSIDriver): """ lines = [line for line in out if line != ''] # Every record has 2 lines - for i in xrange(0, len(lines), 2): + for i in range(0, len(lines), 2): try: int(lines[i][0]) # sanity check diff --git a/cinder/volume/drivers/netapp/eseries/host_mapper.py b/cinder/volume/drivers/netapp/eseries/host_mapper.py index e464da451..507531fa0 100644 --- a/cinder/volume/drivers/netapp/eseries/host_mapper.py +++ b/cinder/volume/drivers/netapp/eseries/host_mapper.py @@ -21,6 +21,7 @@ import collections import random from oslo_log import log as logging +from six.moves import range from cinder import exception from cinder.i18n import _ diff --git a/cinder/volume/drivers/srb.py b/cinder/volume/drivers/srb.py index 1ef094959..30305a677 100644 --- a/cinder/volume/drivers/srb.py +++ b/cinder/volume/drivers/srb.py @@ -32,6 +32,7 @@ from oslo_log import log as logging from oslo_utils import excutils from oslo_utils import units import six +from six.moves import range from cinder.brick.local_dev import lvm from cinder import exception @@ -84,7 +85,7 @@ class retry(object): sleep_time = self._sleep_factor exc_info = None - for attempt in xrange(self._count): + for attempt in range(self._count): if attempt != 0: LOG.warning(_LW('Retrying failed call to %(func)s, ' 'attempt %(attempt)i.'), diff --git a/cinder/volume/drivers/violin/v6000_common.py b/cinder/volume/drivers/violin/v6000_common.py index d308e9190..c14dbfd9a 100644 --- a/cinder/volume/drivers/violin/v6000_common.py +++ b/cinder/volume/drivers/violin/v6000_common.py @@ -536,7 +536,7 @@ class V6000Common(object): LOG.debug("Entering _wait_for_export_config loop: state=%s.", state) - for node_id in xrange(2): + for node_id in range(2): resp = mg_conns[node_id].basic.get_node_values(bn) if state and len(resp.keys()): status[node_id] = True diff --git a/cinder/volume/drivers/violin/v6000_fcp.py b/cinder/volume/drivers/violin/v6000_fcp.py index cf4dc9cf9..1d9ecb1c0 100644 --- a/cinder/volume/drivers/violin/v6000_fcp.py +++ b/cinder/volume/drivers/violin/v6000_fcp.py @@ -37,6 +37,7 @@ driver documentation for more information. from oslo_log import log as logging from oslo_utils import units +from six.moves import range from cinder import context from cinder.db.sqlalchemy import models @@ -505,7 +506,7 @@ class V6000FCDriver(driver.FibreChannelDriver): output = [] for w in wwns: output.append('wwn.{0}'.format( - ':'.join(w[x:x + 2] for x in xrange(0, len(w), 2)))) + ':'.join(w[x:x + 2] for x in range(0, len(w), 2)))) return output def _convert_wwns_vmem_to_openstack(self, wwns): diff --git a/cinder/volume/drivers/violin/v6000_iscsi.py b/cinder/volume/drivers/violin/v6000_iscsi.py index c711417e4..908d2ae30 100644 --- a/cinder/volume/drivers/violin/v6000_iscsi.py +++ b/cinder/volume/drivers/violin/v6000_iscsi.py @@ -588,7 +588,7 @@ class V6000ISCSIDriver(driver.ISCSIDriver): LOG.debug("Entering _wait_for_targetstate loop: target=%s.", target_name) - for node_id in xrange(2): + for node_id in range(2): resp = mg_conns[node_id].basic.get_node_values(bn) if len(resp.keys()): status[node_id] = True diff --git a/cinder/volume/utils.py b/cinder/volume/utils.py index aa14e7fc9..dbfa4ee2a 100644 --- a/cinder/volume/utils.py +++ b/cinder/volume/utils.py @@ -24,6 +24,7 @@ from oslo_log import log as logging from oslo_utils import strutils from oslo_utils import timeutils from oslo_utils import units +from six.moves import range from cinder.brick.local_dev import lvm as brick_lvm from cinder import db @@ -443,7 +444,7 @@ def generate_password(length=16, symbolgroups=DEFAULT_PASSWORD_SYMBOLS): # then fill with random characters from all symbol groups symbols = ''.join(symbolgroups) - password.extend([random.choice(symbols) for _i in xrange(length)]) + password.extend([random.choice(symbols) for _i in range(length)]) # finally shuffle to ensure first x characters aren't from a # predictable group diff --git a/doc/ext/cinder_todo.py b/doc/ext/cinder_todo.py index af2cfda56..bdd64532a 100644 --- a/doc/ext/cinder_todo.py +++ b/doc/ext/cinder_todo.py @@ -24,7 +24,7 @@ def process_todo_nodes(app, doctree, fromdocname): # remove the item that was added in the constructor, since I'm tired of # reading through docutils for the proper way to construct an empty list lists = [] - for i in xrange(5): + for i in range(5): lists.append(nodes.bullet_list("", nodes.Text('', ''))) lists[i].remove(lists[i][0]) lists[i]['classes'].append('todo_list') -- 2.45.2