From 24521055df02bb2bdb0e0d984a5c101a9c0bad64 Mon Sep 17 00:00:00 2001 From: fumihiko kakuma Date: Thu, 16 Jul 2015 19:34:12 +0900 Subject: [PATCH] Python 3: Wrap map() in a list call map() returns an iterator in python 3. In a case that a list is expected, we wrap map() in a list call. Change-Id: I623d854c410176c8ec43b732dc8f4e087dadefd9 Blueprint: neutron-python3 --- neutron/agent/common/ovs_lib.py | 2 +- neutron/agent/linux/utils.py | 4 ++-- neutron/agent/windows/utils.py | 2 +- neutron/db/db_base_plugin_v2.py | 3 ++- neutron/db/migration/cli.py | 2 +- neutron/plugins/ml2/drivers/cisco/apic/apic_topology.py | 2 +- neutron/plugins/ml2/plugin.py | 3 ++- neutron/tests/api/test_routers.py | 2 +- neutron/tests/unit/agent/l3/test_agent.py | 4 ++-- neutron/tests/unit/plugins/ml2/test_security_group.py | 2 +- 10 files changed, 14 insertions(+), 12 deletions(-) diff --git a/neutron/agent/common/ovs_lib.py b/neutron/agent/common/ovs_lib.py index 49c7a6e9c..00e2de18c 100644 --- a/neutron/agent/common/ovs_lib.py +++ b/neutron/agent/common/ovs_lib.py @@ -557,7 +557,7 @@ class DeferredOVSBridge(object): key=operator.itemgetter(0)) itemgetter_1 = operator.itemgetter(1) for action, action_flow_list in grouped: - flows = map(itemgetter_1, action_flow_list) + flows = list(map(itemgetter_1, action_flow_list)) self.br.do_action_flows(action, flows) def __enter__(self): diff --git a/neutron/agent/linux/utils.py b/neutron/agent/linux/utils.py index b646aa8f4..3140adb4c 100644 --- a/neutron/agent/linux/utils.py +++ b/neutron/agent/linux/utils.py @@ -79,7 +79,7 @@ def create_process(cmd, run_as_root=False, addl_env=None): The return value will be a tuple of the process object and the list of command arguments used to create it. """ - cmd = map(str, addl_env_args(addl_env) + cmd) + cmd = list(map(str, addl_env_args(addl_env) + cmd)) if run_as_root: cmd = shlex.split(config.get_root_helper(cfg.CONF)) + cmd LOG.debug("Running command: %s", cmd) @@ -92,7 +92,7 @@ def create_process(cmd, run_as_root=False, addl_env=None): def execute_rootwrap_daemon(cmd, process_input, addl_env): - cmd = map(str, addl_env_args(addl_env) + cmd) + cmd = list(map(str, addl_env_args(addl_env) + cmd)) # NOTE(twilson) oslo_rootwrap.daemon will raise on filter match # errors, whereas oslo_rootwrap.cmd converts them to return codes. # In practice, no neutron code should be trying to execute something that diff --git a/neutron/agent/windows/utils.py b/neutron/agent/windows/utils.py index 8c878395a..5221534a6 100644 --- a/neutron/agent/windows/utils.py +++ b/neutron/agent/windows/utils.py @@ -25,7 +25,7 @@ LOG = logging.getLogger(__name__) def create_process(cmd, addl_env=None): - cmd = map(str, cmd) + cmd = list(map(str, cmd)) LOG.debug("Running command: %s", cmd) env = os.environ.copy() diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index d2b5f8997..e681bdfa7 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -612,7 +612,8 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon, in_(AUTO_DELETE_PORT_OWNERS))) network_ports = qry_network_ports.all() if network_ports: - map(context.session.delete, network_ports) + for port in network_ports: + context.session.delete(port) # Check if there are more IP allocations, unless # is_auto_address_subnet is True. In that case the check is # unnecessary. This additional check not only would be wasteful diff --git a/neutron/db/migration/cli.py b/neutron/db/migration/cli.py index 51b49508a..738fd6054 100644 --- a/neutron/db/migration/cli.py +++ b/neutron/db/migration/cli.py @@ -33,7 +33,7 @@ MIGRATION_BRANCHES = ('expand', 'contract') mods = repos.NeutronModules() -VALID_SERVICES = map(mods.alembic_name, mods.installed_list()) +VALID_SERVICES = list(map(mods.alembic_name, mods.installed_list())) _core_opts = [ diff --git a/neutron/plugins/ml2/drivers/cisco/apic/apic_topology.py b/neutron/plugins/ml2/drivers/cisco/apic/apic_topology.py index 8a1be65a1..a64eee1fd 100644 --- a/neutron/plugins/ml2/drivers/cisco/apic/apic_topology.py +++ b/neutron/plugins/ml2/drivers/cisco/apic/apic_topology.py @@ -167,7 +167,7 @@ class ApicTopologyAgent(manager.Manager): self.interfaces = {} self.lldpcmd = None self.peers = {} - self.port_desc_re = map(re.compile, ACI_PORT_DESCR_FORMATS) + self.port_desc_re = list(map(re.compile, ACI_PORT_DESCR_FORMATS)) self.service_agent = ApicTopologyServiceNotifierApi() self.state = None self.state_agent = None diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index 89a64609a..f965c6bbb 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -864,7 +864,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, allocated = qry_allocated.all() # Delete all the IPAllocation that can be auto-deleted if allocated: - map(session.delete, allocated) + for x in allocated: + session.delete(x) LOG.debug("Ports to auto-deallocate: %s", allocated) # Check if there are more IP allocations, unless # is_auto_address_subnet is True. In that case the check is diff --git a/neutron/tests/api/test_routers.py b/neutron/tests/api/test_routers.py index 6593f9799..4cde8fb82 100644 --- a/neutron/tests/api/test_routers.py +++ b/neutron/tests/api/test_routers.py @@ -189,7 +189,7 @@ class RoutersTest(base.BaseRouterTest): CONF.network.public_network_id) public_subnet_id = public_net_body['network']['subnets'][0] self.assertIn(public_subnet_id, - map(lambda x: x['subnet_id'], fixed_ips)) + [x['subnet_id'] for x in fixed_ips]) @test.attr(type='smoke') @test.idempotent_id('6cc285d8-46bf-4f36-9b1a-783e3008ba79') diff --git a/neutron/tests/unit/agent/l3/test_agent.py b/neutron/tests/unit/agent/l3/test_agent.py index 09416ba0a..159b2a11c 100644 --- a/neutron/tests/unit/agent/l3/test_agent.py +++ b/neutron/tests/unit/agent/l3/test_agent.py @@ -1520,7 +1520,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): ri.router = {'distributed': False} ri._handle_router_snat_rules(ex_gw_port, "iface", "add_rules") - nat_rules = map(str, ri.iptables_manager.ipv4['nat'].rules) + nat_rules = list(map(str, ri.iptables_manager.ipv4['nat'].rules)) wrap_name = ri.iptables_manager.wrap_name jump_float_rule = "-A %s-snat -j %s-float-snat" % (wrap_name, @@ -1539,7 +1539,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): self.assertThat(nat_rules.index(jump_float_rule), matchers.LessThan(nat_rules.index(snat_rule1))) - mangle_rules = map(str, ri.iptables_manager.ipv4['mangle'].rules) + mangle_rules = list(map(str, ri.iptables_manager.ipv4['mangle'].rules)) mangle_rule = ("-A %s-mark -i iface " "-j MARK --set-xmark 0x2/0xffffffff") % wrap_name self.assertIn(mangle_rule, mangle_rules) diff --git a/neutron/tests/unit/plugins/ml2/test_security_group.py b/neutron/tests/unit/plugins/ml2/test_security_group.py index 897cadf58..a9b922013 100644 --- a/neutron/tests/unit/plugins/ml2/test_security_group.py +++ b/neutron/tests/unit/plugins/ml2/test_security_group.py @@ -117,7 +117,7 @@ class TestMl2SecurityGroups(Ml2SecurityGroupsTestCase, plugin.get_ports_from_devices(self.ctx, ['%s%s' % (const.TAP_DEVICE_PREFIX, i) for i in range(ports_to_query)]) - all_call_args = map(lambda x: x[1][1], get_mock.mock_calls) + all_call_args = [x[1][1] for x in get_mock.mock_calls] last_call_args = all_call_args.pop() # all but last should be getting MAX_PORTS_PER_QUERY ports self.assertTrue( -- 2.45.2