]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Python 3: use next() instead of iterator.next()
authorCyril Roelandt <cyril@redhat.com>
Mon, 8 Jun 2015 16:09:49 +0000 (16:09 +0000)
committerCyril Roelandt <cyril@redhat.com>
Tue, 9 Jun 2015 18:26:09 +0000 (20:26 +0200)
The latter only works in Python 2.

Also define a __next__ method in the classes that define a next method.

Change-Id: Iaa1a1e500facab50d8bcdffda39ccad3f2e4e9bb
Blueprint: neutron-python3

neutron/agent/linux/ip_lib.py
neutron/db/model_base.py
neutron/ipam/subnet_alloc.py
neutron/plugins/ml2/drivers/type_tunnel.py
neutron/tests/tempest/common/glance_http.py
neutron/tests/unit/agent/l3/test_agent.py
tox.ini

index ce5dec796d113e6d3138c85c0fa40bd47c21753e..32fe1f9ac84b8bcb590517471c6a08b1a17e6efc 100644 (file)
@@ -557,13 +557,13 @@ class IpRouteCommand(IpDeviceCommandBase):
                                                 ).split('\n')
             for subnet_route_line in subnet_route_list_lines:
                 i = iter(subnet_route_line.split())
-                while(i.next() != 'dev'):
+                while(next(i) != 'dev'):
                     pass
-                device = i.next()
+                device = next(i)
                 try:
-                    while(i.next() != 'src'):
+                    while(next(i) != 'src'):
                         pass
-                    src = i.next()
+                    src = next(i)
                 except Exception:
                     src = ''
                 if device != interface_name:
index b613447d4a8c816fde5e962bbd95e94913fce95d..e1abbd5533a504b1369c940ad1f7a94acb52d5c0 100644 (file)
@@ -28,9 +28,11 @@ class NeutronBase(models.ModelBase):
         return self
 
     def next(self):
-        n = self._i.next().name
+        n = next(self._i).name
         return n, getattr(self, n)
 
+    __next__ = next
+
     def __repr__(self):
         """sqlalchemy based automatic __repr__ method."""
         items = ['%s=%r' % (col.name, getattr(self, col.name))
index 49b6eda2ab5a94a89747f4f94a5324d1b9799171..ff9b30c9a5829f72380550f45f901d49ae6c5cfd 100644 (file)
@@ -93,7 +93,7 @@ class SubnetAllocator(driver.Pool):
             prefix_pool = self._get_available_prefix_list()
             for prefix in prefix_pool:
                 if request.prefixlen >= prefix.prefixlen:
-                    subnet = prefix.subnet(request.prefixlen).next()
+                    subnet = next(prefix.subnet(request.prefixlen))
                     gateway_ip = request.gateway_ip
                     if not gateway_ip:
                         gateway_ip = subnet.network + 1
index 12dce86f48fd42e262fddf41e68bae18cef8609f..14904b31d8a84375001b897e65010c4b8399e408 100644 (file)
@@ -40,7 +40,7 @@ class TunnelTypeDriver(helpers.SegmentTypeDriver):
 
     def __init__(self, model):
         super(TunnelTypeDriver, self).__init__(model)
-        self.segmentation_key = iter(self.primary_keys).next()
+        self.segmentation_key = next(iter(self.primary_keys))
 
     @abc.abstractmethod
     def sync_allocations(self):
@@ -203,7 +203,7 @@ class EndpointTunnelTypeDriver(TunnelTypeDriver):
     def __init__(self, segment_model, endpoint_model):
         super(EndpointTunnelTypeDriver, self).__init__(segment_model)
         self.endpoint_model = endpoint_model
-        self.segmentation_key = iter(self.primary_keys).next()
+        self.segmentation_key = next(iter(self.primary_keys))
 
     def get_endpoint_by_host(self, host):
         LOG.debug("get_endpoint_by_host() called for host %s", host)
index 6cdbadc3bab6c4bd2dffb72a057f1e43b0007922..0a6f985e7c640dfd209c9b18e0b68e5010e0ac70 100644 (file)
@@ -367,7 +367,7 @@ class ResponseBodyIterator(object):
 
     def __iter__(self):
         while True:
-            yield self.next()
+            yield next(self)
 
     def next(self):
         chunk = self.resp.read(CHUNKSIZE)
@@ -375,3 +375,5 @@ class ResponseBodyIterator(object):
             return chunk
         else:
             raise StopIteration()
+
+    __next__ = next
index 577eef30c7535df099867ca62e71978642414dc7..aeec5c6f1c2db38ca9820ed1b4e0f31b47d3c8df 100644 (file)
@@ -136,8 +136,8 @@ def router_append_subnet(router, count=1, ip_version=4,
     interfaces = copy.deepcopy(router.get(l3_constants.INTERFACE_KEY, []))
     if interface_id:
         try:
-            interface = (i for i in interfaces
-                         if i['id'] == interface_id).next()
+            interface = next(i for i in interfaces
+                         if i['id'] == interface_id)
         except StopIteration:
             raise ValueError("interface_id not found")
 
diff --git a/tox.ini b/tox.ini
index 636a2a3773900a1db21c8e69ae54417ebb72fca8..d7cf102ed1e0dfd25e72b05229932be695518f53 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -113,6 +113,8 @@ commands = python -m testtools.run \
     neutron.tests.unit.plugins.ml2.drivers.ext_test \
     neutron.tests.unit.plugins.ml2.drivers.mech_sriov.test_mech_sriov_nic_switch \
     neutron.tests.unit.plugins.ml2.drivers.mech_fake_agent \
+    neutron.tests.unit.plugins.ml2.drivers.test_type_vxlan \
+    neutron.tests.unit.plugins.ml2.drivers.test_type_gre \
     neutron.tests.unit.plugins.ml2.drivers.arista.test_mechanism_arista \
     neutron.tests.unit.plugins.ml2.drivers.test_type_local \
     neutron.tests.unit.plugins.ml2.drivers.mechanism_logger \
@@ -151,6 +153,7 @@ commands = python -m testtools.run \
     neutron.tests.unit.agent.l3.test_dvr_fip_ns \
     neutron.tests.unit.agent.common.test_config \
     neutron.tests.unit.agent.common.test_polling \
+    neutron.tests.unit.agent.linux.test_ip_lib \
     neutron.tests.unit.agent.linux.test_keepalived \
     neutron.tests.unit.agent.linux.test_ipset_manager \
     neutron.tests.unit.agent.linux.test_ebtables_manager \
@@ -176,6 +179,7 @@ commands = python -m testtools.run \
     neutron.tests.unit.cmd.test_netns_cleanup \
     neutron.tests.unit.ipam.drivers.neutrondb_ipam.test_db_api \
     neutron.tests.unit.ipam.drivers.neutrondb_ipam.test_driver \
+    neutron.tests.unit.ipam.test_subnet_alloc \
     neutron.tests.unit.notifiers.test_nova \
     neutron.tests.unit.notifiers.test_batch_notifier