]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Replace it.next() with next(it) for py3 compat
authorVictor Stinner <vstinner@redhat.com>
Wed, 10 Jun 2015 12:55:52 +0000 (14:55 +0200)
committerVictor Stinner <vstinner@redhat.com>
Thu, 11 Jun 2015 16:28:48 +0000 (18:28 +0200)
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

cinder/api/openstack/wsgi.py
cinder/api/urlmap.py
cinder/cmd/rtstool.py
cinder/image/glance.py
cinder/tests/unit/api/openstack/test_wsgi.py
cinder/tests/unit/test_cmd.py
cinder/volume/drivers/datera.py
cinder/volume/drivers/lvm.py

index c72da755d4b9ad94a199b90dfefaa92ff4780fae..c38caa1e7bd9e03fca4302ec6dad08dcd2f0354c 100644 (file)
@@ -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
 
index 0fdf41161217271a682c07ed3ea07f9168668e6a..2d5a264aff349e0ad6b926cd7c94800c936ff988 100644 (file)
@@ -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
 
index bd770d25aea44db09ec3941b6f787efe7506e72d..cccbc0d4bb8d6db78c3717618f12d69ab9f92687 100644 (file)
@@ -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()
index 42de65d77e34aa5fc792d4126457e39e077fd956..d4e213176b92e293d51496326a168e8faf51157f 100644 (file)
@@ -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)
index af5cb38d09ba49b941503750f2c2c79feecee208..82f49ea78245699ed913cbfcc69b0f3632083530 100644 (file)
@@ -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, {})
index feea1b32281b2be36224a9461742b487f9e01257..435217fe44c36ceca600fb4d10522e1dc0796482 100644 (file)
@@ -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)
index 276867f4d76a2fbc72596e2d063b58f5297267e0..7d024060a0fba9acc156af45ebd76be383214d9f 100644 (file)
@@ -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',
index 317d983df3084f245a31bd3f0903cbeeed97d107..c9578ad08ad39a6c8fa64ac0d9737d06663a1420 100644 (file)
@@ -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)