From: Victor Stinner Date: Wed, 10 Jun 2015 12:55:52 +0000 (+0200) Subject: Replace it.next() with next(it) for py3 compat X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=f25cc1a6d82256e78144478e922e866e4b34abca;p=openstack-build%2Fcinder-build.git Replace it.next() with next(it) for py3 compat The Python 2 next() method of iterators was renamed to __next__() on Python 3. Use the builtin next() function instead which works on Python 2 and Python 3. This patch was generated by the next operation of the sixer tool: https://pypi.python.org/pypi/sixer Manual changes: * cinder/tests/unit/test_cmd.py: use "tpgs = iter([tpg])" instead of using a magic mock for tpgs Blueprint cinder-python3 Change-Id: I261f8cda231d80910f27b9c1329f1d43ccdd77b6 --- diff --git a/cinder/api/openstack/wsgi.py b/cinder/api/openstack/wsgi.py index c72da755d..c38caa1e7 100644 --- a/cinder/api/openstack/wsgi.py +++ b/cinder/api/openstack/wsgi.py @@ -897,7 +897,7 @@ class Resource(wsgi.Application): try: with ResourceExceptionHandler(): gen = ext(req=request, **action_args) - response = gen.next() + response = next(gen) except Fault as ex: response = ex diff --git a/cinder/api/urlmap.py b/cinder/api/urlmap.py index 0fdf41161..2d5a264af 100644 --- a/cinder/api/urlmap.py +++ b/cinder/api/urlmap.py @@ -96,7 +96,7 @@ def parse_options_header(value): return '', {} parts = _tokenize(';' + value) - name = parts.next()[0] + name = next(parts)[0] extra = dict(parts) return name, extra diff --git a/cinder/cmd/rtstool.py b/cinder/cmd/rtstool.py index bd770d25a..cccbc0d4b 100644 --- a/cinder/cmd/rtstool.py +++ b/cinder/cmd/rtstool.py @@ -117,7 +117,7 @@ def _lookup_target(target_iqn, initiator_iqn): def add_initiator(target_iqn, initiator_iqn, userid, password): target = _lookup_target(target_iqn, initiator_iqn) - tpg = target.tpgs.next() # get the first one + tpg = next(target.tpgs) # get the first one for acl in tpg.node_acls: # See if this ACL configuration already exists if acl.node_wwn == initiator_iqn: @@ -133,7 +133,7 @@ def add_initiator(target_iqn, initiator_iqn, userid, password): def delete_initiator(target_iqn, initiator_iqn): target = _lookup_target(target_iqn, initiator_iqn) - tpg = target.tpgs.next() # get the first one + tpg = next(target.tpgs) # get the first one for acl in tpg.node_acls: if acl.node_wwn == initiator_iqn: acl.delete() diff --git a/cinder/image/glance.py b/cinder/image/glance.py index 42de65d77..d4e213176 100644 --- a/cinder/image/glance.py +++ b/cinder/image/glance.py @@ -148,7 +148,7 @@ class GlanceClientWrapper(object): """Create a client that will be used for one call.""" if self.api_servers is None: self.api_servers = get_api_servers() - self.netloc, self.use_ssl = self.api_servers.next() + self.netloc, self.use_ssl = next(self.api_servers) return _create_glance_client(context, self.netloc, self.use_ssl, version) diff --git a/cinder/tests/unit/api/openstack/test_wsgi.py b/cinder/tests/unit/api/openstack/test_wsgi.py index af5cb38d0..82f49ea78 100644 --- a/cinder/tests/unit/api/openstack/test_wsgi.py +++ b/cinder/tests/unit/api/openstack/test_wsgi.py @@ -815,9 +815,9 @@ class ResourceTest(test.TestCase): called.append(2) ext1 = extension1(None) - ext1.next() + next(ext1) ext2 = extension2(None) - ext2.next() + next(ext2) response = resource.post_process_extensions([ext2, ext1], None, None, {}) @@ -845,9 +845,9 @@ class ResourceTest(test.TestCase): yield 'foo' ext1 = extension1(None) - ext1.next() + next(ext1) ext2 = extension2(None) - ext2.next() + next(ext2) response = resource.post_process_extensions([ext2, ext1], None, None, {}) diff --git a/cinder/tests/unit/test_cmd.py b/cinder/tests/unit/test_cmd.py index feea1b322..435217fe4 100644 --- a/cinder/tests/unit/test_cmd.py +++ b/cinder/tests/unit/test_cmd.py @@ -897,8 +897,7 @@ class TestCinderRtstoolCmd(test.TestCase): [{'node_acls': mock.sentinel.initiator_iqn}] acl = mock.MagicMock(node_wwn=mock.sentinel.initiator_iqn) tpg = mock.MagicMock(node_acls=[acl]) - tpgs = mock.MagicMock() - tpgs.next.return_value = tpg + tpgs = iter([tpg]) target = mock.MagicMock(tpgs=tpgs, wwn=target_iqn) rtsroot.return_value = mock.MagicMock(targets=[target]) @@ -917,7 +916,8 @@ class TestCinderRtstoolCmd(test.TestCase): target_iqn.tpgs.return_value = \ [{'node_acls': mock.sentinel.initiator_iqn}] tpg = mock.MagicMock() - target = mock.MagicMock(tpgs=tpg, wwn=target_iqn) + tpgs = iter([tpg]) + target = mock.MagicMock(tpgs=tpgs, wwn=target_iqn) rtsroot.return_value = mock.MagicMock(targets=[target]) acl_new = mock.MagicMock(chap_userid=mock.sentinel.userid, @@ -928,7 +928,7 @@ class TestCinderRtstoolCmd(test.TestCase): mock.sentinel.initiator_iqn, mock.sentinel.userid, mock.sentinel.password) - node_acl.assert_called_once_with(tpg.next(), + node_acl.assert_called_once_with(tpg, mock.sentinel.initiator_iqn, mode='create') mapped_lun.assert_called_once_with(acl_new, 0, tpg_lun=0) diff --git a/cinder/volume/drivers/datera.py b/cinder/volume/drivers/datera.py index 276867f4d..7d024060a 100644 --- a/cinder/volume/drivers/datera.py +++ b/cinder/volume/drivers/datera.py @@ -182,7 +182,7 @@ class DateraDriver(san.SanISCSIDriver): # NOTE(thingee): Refer to the Datera test for a stub of what this # looks like. We're just going to pull the first IP that the Datera # cluster makes available for the portal. - iqn = export['targetIds'].itervalues().next()['ids'][0]['id'] + iqn = next(export['targetIds'].itervalues())['ids'][0]['id'] else: export = self._issue_api_request( 'export_configs', diff --git a/cinder/volume/drivers/lvm.py b/cinder/volume/drivers/lvm.py index 317d983df..c9578ad08 100644 --- a/cinder/volume/drivers/lvm.py +++ b/cinder/volume/drivers/lvm.py @@ -270,7 +270,7 @@ class LVMVolumeDriver(driver.VolumeDriver): vg_list = volutils.get_all_volume_groups( self.configuration.volume_group) vg_dict = \ - (vg for vg in vg_list if vg['name'] == self.vg.vg_name).next() + next(vg for vg in vg_list if vg['name'] == self.vg.vg_name) if vg_dict is None: message = (_("Volume Group %s does not exist") % self.configuration.volume_group) @@ -541,7 +541,7 @@ class LVMVolumeDriver(driver.VolumeDriver): if dest_vg != self.vg.vg_name: vg_list = volutils.get_all_volume_groups() try: - (vg for vg in vg_list if vg['name'] == dest_vg).next() + next(vg for vg in vg_list if vg['name'] == dest_vg) except StopIteration: LOG.error(_LE("Destination Volume Group %s does not exist"), dest_vg)