From: Cyril Roelandt Date: Mon, 8 Jun 2015 16:09:49 +0000 (+0000) Subject: Python 3: use next() instead of iterator.next() X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=303f37f4e0c84f90e40b95731a828fc6ce8a0bbf;p=openstack-build%2Fneutron-build.git Python 3: use next() instead of iterator.next() 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 --- diff --git a/neutron/agent/linux/ip_lib.py b/neutron/agent/linux/ip_lib.py index ce5dec796..32fe1f9ac 100644 --- a/neutron/agent/linux/ip_lib.py +++ b/neutron/agent/linux/ip_lib.py @@ -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: diff --git a/neutron/db/model_base.py b/neutron/db/model_base.py index b613447d4..e1abbd553 100644 --- a/neutron/db/model_base.py +++ b/neutron/db/model_base.py @@ -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)) diff --git a/neutron/ipam/subnet_alloc.py b/neutron/ipam/subnet_alloc.py index 49b6eda2a..ff9b30c9a 100644 --- a/neutron/ipam/subnet_alloc.py +++ b/neutron/ipam/subnet_alloc.py @@ -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 diff --git a/neutron/plugins/ml2/drivers/type_tunnel.py b/neutron/plugins/ml2/drivers/type_tunnel.py index 12dce86f4..14904b31d 100644 --- a/neutron/plugins/ml2/drivers/type_tunnel.py +++ b/neutron/plugins/ml2/drivers/type_tunnel.py @@ -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) diff --git a/neutron/tests/tempest/common/glance_http.py b/neutron/tests/tempest/common/glance_http.py index 6cdbadc3b..0a6f985e7 100644 --- a/neutron/tests/tempest/common/glance_http.py +++ b/neutron/tests/tempest/common/glance_http.py @@ -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 diff --git a/neutron/tests/unit/agent/l3/test_agent.py b/neutron/tests/unit/agent/l3/test_agent.py index 577eef30c..aeec5c6f1 100644 --- a/neutron/tests/unit/agent/l3/test_agent.py +++ b/neutron/tests/unit/agent/l3/test_agent.py @@ -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 636a2a377..d7cf102ed 100644 --- 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