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
This commit is contained in:
fumihiko kakuma 2015-07-16 19:34:12 +09:00
parent 99920097c6
commit 24521055df
10 changed files with 14 additions and 12 deletions

View File

@ -557,7 +557,7 @@ class DeferredOVSBridge(object):
key=operator.itemgetter(0)) key=operator.itemgetter(0))
itemgetter_1 = operator.itemgetter(1) itemgetter_1 = operator.itemgetter(1)
for action, action_flow_list in grouped: 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) self.br.do_action_flows(action, flows)
def __enter__(self): def __enter__(self):

View File

@ -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 The return value will be a tuple of the process object and the
list of command arguments used to create it. 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: if run_as_root:
cmd = shlex.split(config.get_root_helper(cfg.CONF)) + cmd cmd = shlex.split(config.get_root_helper(cfg.CONF)) + cmd
LOG.debug("Running command: %s", 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): 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 # NOTE(twilson) oslo_rootwrap.daemon will raise on filter match
# errors, whereas oslo_rootwrap.cmd converts them to return codes. # errors, whereas oslo_rootwrap.cmd converts them to return codes.
# In practice, no neutron code should be trying to execute something that # In practice, no neutron code should be trying to execute something that

View File

@ -25,7 +25,7 @@ LOG = logging.getLogger(__name__)
def create_process(cmd, addl_env=None): def create_process(cmd, addl_env=None):
cmd = map(str, cmd) cmd = list(map(str, cmd))
LOG.debug("Running command: %s", cmd) LOG.debug("Running command: %s", cmd)
env = os.environ.copy() env = os.environ.copy()

View File

@ -612,7 +612,8 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
in_(AUTO_DELETE_PORT_OWNERS))) in_(AUTO_DELETE_PORT_OWNERS)))
network_ports = qry_network_ports.all() network_ports = qry_network_ports.all()
if network_ports: 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 # Check if there are more IP allocations, unless
# is_auto_address_subnet is True. In that case the check is # is_auto_address_subnet is True. In that case the check is
# unnecessary. This additional check not only would be wasteful # unnecessary. This additional check not only would be wasteful

View File

@ -33,7 +33,7 @@ MIGRATION_BRANCHES = ('expand', 'contract')
mods = repos.NeutronModules() mods = repos.NeutronModules()
VALID_SERVICES = map(mods.alembic_name, mods.installed_list()) VALID_SERVICES = list(map(mods.alembic_name, mods.installed_list()))
_core_opts = [ _core_opts = [

View File

@ -167,7 +167,7 @@ class ApicTopologyAgent(manager.Manager):
self.interfaces = {} self.interfaces = {}
self.lldpcmd = None self.lldpcmd = None
self.peers = {} 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.service_agent = ApicTopologyServiceNotifierApi()
self.state = None self.state = None
self.state_agent = None self.state_agent = None

View File

@ -864,7 +864,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
allocated = qry_allocated.all() allocated = qry_allocated.all()
# Delete all the IPAllocation that can be auto-deleted # Delete all the IPAllocation that can be auto-deleted
if allocated: if allocated:
map(session.delete, allocated) for x in allocated:
session.delete(x)
LOG.debug("Ports to auto-deallocate: %s", allocated) LOG.debug("Ports to auto-deallocate: %s", allocated)
# Check if there are more IP allocations, unless # Check if there are more IP allocations, unless
# is_auto_address_subnet is True. In that case the check is # is_auto_address_subnet is True. In that case the check is

View File

@ -189,7 +189,7 @@ class RoutersTest(base.BaseRouterTest):
CONF.network.public_network_id) CONF.network.public_network_id)
public_subnet_id = public_net_body['network']['subnets'][0] public_subnet_id = public_net_body['network']['subnets'][0]
self.assertIn(public_subnet_id, 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.attr(type='smoke')
@test.idempotent_id('6cc285d8-46bf-4f36-9b1a-783e3008ba79') @test.idempotent_id('6cc285d8-46bf-4f36-9b1a-783e3008ba79')

View File

@ -1520,7 +1520,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
ri.router = {'distributed': False} ri.router = {'distributed': False}
ri._handle_router_snat_rules(ex_gw_port, "iface", "add_rules") 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 wrap_name = ri.iptables_manager.wrap_name
jump_float_rule = "-A %s-snat -j %s-float-snat" % (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), self.assertThat(nat_rules.index(jump_float_rule),
matchers.LessThan(nat_rules.index(snat_rule1))) 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 " mangle_rule = ("-A %s-mark -i iface "
"-j MARK --set-xmark 0x2/0xffffffff") % wrap_name "-j MARK --set-xmark 0x2/0xffffffff") % wrap_name
self.assertIn(mangle_rule, mangle_rules) self.assertIn(mangle_rule, mangle_rules)

View File

@ -117,7 +117,7 @@ class TestMl2SecurityGroups(Ml2SecurityGroupsTestCase,
plugin.get_ports_from_devices(self.ctx, plugin.get_ports_from_devices(self.ctx,
['%s%s' % (const.TAP_DEVICE_PREFIX, i) ['%s%s' % (const.TAP_DEVICE_PREFIX, i)
for i in range(ports_to_query)]) 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() last_call_args = all_call_args.pop()
# all but last should be getting MAX_PORTS_PER_QUERY ports # all but last should be getting MAX_PORTS_PER_QUERY ports
self.assertTrue( self.assertTrue(