Fixes Python 3 compatibility for filter results
Python 2.7 filter method result was a list, while for Python 3.4 the result is a "filter object". Trying to use it as a list will result in a TypeError. Enables some unit tests for gate-nova-python34. Partially implements blueprint: nova-python3-mitaka Change-Id: I681b084bc96fc293488ddbc03218b9c449555578
This commit is contained in:
parent
84952379e0
commit
1e447860d1
|
@ -105,8 +105,7 @@ class Controller(wsgi.Controller):
|
||||||
if 'server' not in robj.obj:
|
if 'server' not in robj.obj:
|
||||||
return robj
|
return robj
|
||||||
|
|
||||||
link = filter(lambda l: l['rel'] == 'self',
|
link = [l for l in robj.obj['server']['links'] if l['rel'] == 'self']
|
||||||
robj.obj['server']['links'])
|
|
||||||
if link:
|
if link:
|
||||||
robj['Location'] = utils.utf8(link[0]['href'])
|
robj['Location'] = utils.utf8(link[0]['href'])
|
||||||
|
|
||||||
|
|
|
@ -92,8 +92,7 @@ class ServersController(wsgi.Controller):
|
||||||
if 'server' not in robj.obj:
|
if 'server' not in robj.obj:
|
||||||
return robj
|
return robj
|
||||||
|
|
||||||
link = filter(lambda l: l['rel'] == 'self',
|
link = [l for l in robj.obj['server']['links'] if l['rel'] == 'self']
|
||||||
robj.obj['server']['links'])
|
|
||||||
if link:
|
if link:
|
||||||
robj['Location'] = utils.utf8(link[0]['href'])
|
robj['Location'] = utils.utf8(link[0]['href'])
|
||||||
|
|
||||||
|
|
|
@ -823,7 +823,7 @@ class API(base.Base):
|
||||||
return not (bdm.get('boot_index') == 0 and
|
return not (bdm.get('boot_index') == 0 and
|
||||||
bdm.get('source_type') == 'image')
|
bdm.get('source_type') == 'image')
|
||||||
|
|
||||||
block_device_mapping = (
|
block_device_mapping = list(
|
||||||
filter(not_image_and_root_bdm, block_device_mapping))
|
filter(not_image_and_root_bdm, block_device_mapping))
|
||||||
|
|
||||||
block_device_mapping = self._merge_bdms_lists(
|
block_device_mapping = self._merge_bdms_lists(
|
||||||
|
|
|
@ -251,8 +251,8 @@ class IptablesTable(object):
|
||||||
self.remove_chains.add(name)
|
self.remove_chains.add(name)
|
||||||
chain_set.remove(name)
|
chain_set.remove(name)
|
||||||
if not wrap:
|
if not wrap:
|
||||||
self.remove_rules += filter(lambda r: r.chain == name, self.rules)
|
self.remove_rules += [r for r in self.rules if r.chain == name]
|
||||||
self.rules = filter(lambda r: r.chain != name, self.rules)
|
self.rules = [r for r in self.rules if r.chain != name]
|
||||||
|
|
||||||
if wrap:
|
if wrap:
|
||||||
jump_snippet = '-j %s-%s' % (binary_name, name)
|
jump_snippet = '-j %s-%s' % (binary_name, name)
|
||||||
|
@ -260,9 +260,9 @@ class IptablesTable(object):
|
||||||
jump_snippet = '-j %s' % (name,)
|
jump_snippet = '-j %s' % (name,)
|
||||||
|
|
||||||
if not wrap:
|
if not wrap:
|
||||||
self.remove_rules += filter(lambda r: jump_snippet in r.rule,
|
self.remove_rules += [r for r in self.rules
|
||||||
self.rules)
|
if jump_snippet in r.rule]
|
||||||
self.rules = filter(lambda r: jump_snippet not in r.rule, self.rules)
|
self.rules = [r for r in self.rules if jump_snippet not in r.rule]
|
||||||
|
|
||||||
def add_rule(self, chain, rule, wrap=True, top=False):
|
def add_rule(self, chain, rule, wrap=True, top=False):
|
||||||
"""Add a rule to the table.
|
"""Add a rule to the table.
|
||||||
|
@ -319,7 +319,7 @@ class IptablesTable(object):
|
||||||
if isinstance(regex, six.string_types):
|
if isinstance(regex, six.string_types):
|
||||||
regex = re.compile(regex)
|
regex = re.compile(regex)
|
||||||
num_rules = len(self.rules)
|
num_rules = len(self.rules)
|
||||||
self.rules = filter(lambda r: not regex.match(str(r)), self.rules)
|
self.rules = [r for r in self.rules if not regex.match(str(r))]
|
||||||
removed = num_rules - len(self.rules)
|
removed = num_rules - len(self.rules)
|
||||||
if removed > 0:
|
if removed > 0:
|
||||||
self.dirty = True
|
self.dirty = True
|
||||||
|
@ -500,26 +500,26 @@ class IptablesManager(object):
|
||||||
current_lines = fake_table
|
current_lines = fake_table
|
||||||
|
|
||||||
# Remove any trace of our rules
|
# Remove any trace of our rules
|
||||||
new_filter = filter(lambda line: binary_name not in line,
|
new_filter = [line for line in current_lines
|
||||||
current_lines)
|
if binary_name not in line]
|
||||||
|
|
||||||
top_rules = []
|
top_rules = []
|
||||||
bottom_rules = []
|
bottom_rules = []
|
||||||
|
|
||||||
if CONF.iptables_top_regex:
|
if CONF.iptables_top_regex:
|
||||||
regex = re.compile(CONF.iptables_top_regex)
|
regex = re.compile(CONF.iptables_top_regex)
|
||||||
temp_filter = filter(lambda line: regex.search(line), new_filter)
|
temp_filter = [line for line in new_filter if regex.search(line)]
|
||||||
for rule_str in temp_filter:
|
for rule_str in temp_filter:
|
||||||
new_filter = filter(lambda s: s.strip() != rule_str.strip(),
|
new_filter = [s for s in new_filter
|
||||||
new_filter)
|
if s.strip() != rule_str.strip()]
|
||||||
top_rules = temp_filter
|
top_rules = temp_filter
|
||||||
|
|
||||||
if CONF.iptables_bottom_regex:
|
if CONF.iptables_bottom_regex:
|
||||||
regex = re.compile(CONF.iptables_bottom_regex)
|
regex = re.compile(CONF.iptables_bottom_regex)
|
||||||
temp_filter = filter(lambda line: regex.search(line), new_filter)
|
temp_filter = [line for line in new_filter if regex.search(line)]
|
||||||
for rule_str in temp_filter:
|
for rule_str in temp_filter:
|
||||||
new_filter = filter(lambda s: s.strip() != rule_str.strip(),
|
new_filter = [s for s in new_filter
|
||||||
new_filter)
|
if s.strip() != rule_str.strip()]
|
||||||
bottom_rules = temp_filter
|
bottom_rules = temp_filter
|
||||||
|
|
||||||
seen_chains = False
|
seen_chains = False
|
||||||
|
@ -552,12 +552,11 @@ class IptablesManager(object):
|
||||||
# ignore [packet:byte] counts at beginning of line
|
# ignore [packet:byte] counts at beginning of line
|
||||||
if rule_str.startswith('['):
|
if rule_str.startswith('['):
|
||||||
rule_str = rule_str.split(']', 1)[1]
|
rule_str = rule_str.split(']', 1)[1]
|
||||||
dup_filter = filter(lambda s: rule_str.strip() in s.strip(),
|
dup_filter = [s for s in new_filter
|
||||||
new_filter)
|
if rule_str.strip() in s.strip()]
|
||||||
|
|
||||||
new_filter = filter(lambda s:
|
new_filter = [s for s in new_filter
|
||||||
rule_str.strip() not in s.strip(),
|
if rule_str.strip() not in s.strip()]
|
||||||
new_filter)
|
|
||||||
# if no duplicates, use original rule
|
# if no duplicates, use original rule
|
||||||
if dup_filter:
|
if dup_filter:
|
||||||
# grab the last entry, if there is one
|
# grab the last entry, if there is one
|
||||||
|
@ -629,9 +628,11 @@ class IptablesManager(object):
|
||||||
# We filter duplicates, letting the *last* occurrence take
|
# We filter duplicates, letting the *last* occurrence take
|
||||||
# precedence. We also filter out anything in the "remove"
|
# precedence. We also filter out anything in the "remove"
|
||||||
# lists.
|
# lists.
|
||||||
|
new_filter = list(new_filter)
|
||||||
new_filter.reverse()
|
new_filter.reverse()
|
||||||
new_filter = filter(_weed_out_duplicates, new_filter)
|
new_filter = filter(_weed_out_duplicates, new_filter)
|
||||||
new_filter = filter(_weed_out_removes, new_filter)
|
new_filter = filter(_weed_out_removes, new_filter)
|
||||||
|
new_filter = list(new_filter)
|
||||||
new_filter.reverse()
|
new_filter.reverse()
|
||||||
|
|
||||||
# flush lists, just in case we didn't find something
|
# flush lists, just in case we didn't find something
|
||||||
|
|
|
@ -107,10 +107,8 @@ networks = [network_fields]
|
||||||
|
|
||||||
def fake_floating_ip_allocate_address(context, project_id, pool,
|
def fake_floating_ip_allocate_address(context, project_id, pool,
|
||||||
auto_assigned=False):
|
auto_assigned=False):
|
||||||
ips = filter(lambda i: i['fixed_ip_id'] is None and
|
ips = [i for i in floating_ips if i['fixed_ip_id'] is None and
|
||||||
i['project_id'] is None and
|
i['project_id'] is None and i['pool'] == pool]
|
||||||
i['pool'] == pool,
|
|
||||||
floating_ips)
|
|
||||||
if not ips:
|
if not ips:
|
||||||
raise exception.NoMoreFloatingIps()
|
raise exception.NoMoreFloatingIps()
|
||||||
ips[0]['project_id'] = project_id
|
ips[0]['project_id'] = project_id
|
||||||
|
@ -119,16 +117,14 @@ def fake_floating_ip_allocate_address(context, project_id, pool,
|
||||||
|
|
||||||
|
|
||||||
def fake_floating_ip_deallocate(context, address):
|
def fake_floating_ip_deallocate(context, address):
|
||||||
ips = filter(lambda i: i['address'] == address,
|
ips = [i for i in floating_ips if i['address'] == address]
|
||||||
floating_ips)
|
|
||||||
if ips:
|
if ips:
|
||||||
ips[0]['project_id'] = None
|
ips[0]['project_id'] = None
|
||||||
ips[0]['auto_assigned'] = False
|
ips[0]['auto_assigned'] = False
|
||||||
|
|
||||||
|
|
||||||
def fake_floating_ip_disassociate(context, address):
|
def fake_floating_ip_disassociate(context, address):
|
||||||
ips = filter(lambda i: i['address'] == address,
|
ips = [i for i in floating_ips if i['address'] == address]
|
||||||
floating_ips)
|
|
||||||
if ips:
|
if ips:
|
||||||
fixed_ip_address = None
|
fixed_ip_address = None
|
||||||
if ips[0]['fixed_ip']:
|
if ips[0]['fixed_ip']:
|
||||||
|
@ -140,10 +136,8 @@ def fake_floating_ip_disassociate(context, address):
|
||||||
|
|
||||||
def fake_floating_ip_fixed_ip_associate(context, floating_address,
|
def fake_floating_ip_fixed_ip_associate(context, floating_address,
|
||||||
fixed_address, host):
|
fixed_address, host):
|
||||||
float = filter(lambda i: i['address'] == floating_address,
|
float = [i for i in floating_ips if i['address'] == floating_address]
|
||||||
floating_ips)
|
fixed = [i for i in fixed_ips if i['address'] == fixed_address]
|
||||||
fixed = filter(lambda i: i['address'] == fixed_address,
|
|
||||||
fixed_ips)
|
|
||||||
if float and fixed:
|
if float and fixed:
|
||||||
float[0]['fixed_ip'] = fixed[0]
|
float[0]['fixed_ip'] = fixed[0]
|
||||||
float[0]['fixed_ip_id'] = fixed[0]['id']
|
float[0]['fixed_ip_id'] = fixed[0]['id']
|
||||||
|
@ -161,16 +155,14 @@ def fake_floating_ip_get_by_address(context, address):
|
||||||
if isinstance(address, FakeModel):
|
if isinstance(address, FakeModel):
|
||||||
# NOTE(tr3buchet): yo dawg, i heard you like addresses
|
# NOTE(tr3buchet): yo dawg, i heard you like addresses
|
||||||
address = address['address']
|
address = address['address']
|
||||||
ips = filter(lambda i: i['address'] == address,
|
ips = [i for i in floating_ips if i['address'] == address]
|
||||||
floating_ips)
|
|
||||||
if not ips:
|
if not ips:
|
||||||
raise exception.FloatingIpNotFoundForAddress(address=address)
|
raise exception.FloatingIpNotFoundForAddress(address=address)
|
||||||
return FakeModel(ips[0])
|
return FakeModel(ips[0])
|
||||||
|
|
||||||
|
|
||||||
def fake_fixed_ip_associate(context, address, instance_id):
|
def fake_fixed_ip_associate(context, address, instance_id):
|
||||||
ips = filter(lambda i: i['address'] == address,
|
ips = [i for i in fixed_ips if i['address'] == address]
|
||||||
fixed_ips)
|
|
||||||
if not ips:
|
if not ips:
|
||||||
raise exception.NoMoreFixedIps(net='fake_net')
|
raise exception.NoMoreFixedIps(net='fake_net')
|
||||||
ips[0]['instance'] = True
|
ips[0]['instance'] = True
|
||||||
|
@ -178,9 +170,8 @@ def fake_fixed_ip_associate(context, address, instance_id):
|
||||||
|
|
||||||
|
|
||||||
def fake_fixed_ip_associate_pool(context, network_id, instance_id):
|
def fake_fixed_ip_associate_pool(context, network_id, instance_id):
|
||||||
ips = filter(lambda i: (i['network_id'] == network_id or
|
ips = [i for i in fixed_ips if not i['instance'] and
|
||||||
i['network_id'] is None) and not i['instance'],
|
(i['network_id'] == network_id or i['network_id'] is None)]
|
||||||
fixed_ips)
|
|
||||||
if not ips:
|
if not ips:
|
||||||
raise exception.NoMoreFixedIps(net=network_id)
|
raise exception.NoMoreFixedIps(net=network_id)
|
||||||
ips[0]['instance'] = True
|
ips[0]['instance'] = True
|
||||||
|
@ -197,8 +188,7 @@ def fake_fixed_ip_create(context, values):
|
||||||
|
|
||||||
|
|
||||||
def fake_fixed_ip_disassociate(context, address):
|
def fake_fixed_ip_disassociate(context, address):
|
||||||
ips = filter(lambda i: i['address'] == address,
|
ips = [i for i in fixed_ips if i['address'] == address]
|
||||||
fixed_ips)
|
|
||||||
if ips:
|
if ips:
|
||||||
ips[0]['instance_id'] = None
|
ips[0]['instance_id'] = None
|
||||||
ips[0]['instance'] = None
|
ips[0]['instance'] = None
|
||||||
|
@ -215,28 +205,25 @@ def fake_fixed_ip_get_all(context):
|
||||||
|
|
||||||
|
|
||||||
def fake_fixed_ip_get_by_instance(context, instance_uuid):
|
def fake_fixed_ip_get_by_instance(context, instance_uuid):
|
||||||
ips = filter(lambda i: i['instance_uuid'] == instance_uuid,
|
ips = [i for i in fixed_ips if i['instance_uuid'] == instance_uuid]
|
||||||
fixed_ips)
|
|
||||||
return [FakeModel(i) for i in ips]
|
return [FakeModel(i) for i in ips]
|
||||||
|
|
||||||
|
|
||||||
def fake_fixed_ip_get_by_address(context, address):
|
def fake_fixed_ip_get_by_address(context, address):
|
||||||
ips = filter(lambda i: i['address'] == address,
|
ips = [i for i in fixed_ips if i['address'] == address]
|
||||||
fixed_ips)
|
|
||||||
if ips:
|
if ips:
|
||||||
return FakeModel(ips[0])
|
return FakeModel(ips[0])
|
||||||
|
|
||||||
|
|
||||||
def fake_fixed_ip_update(context, address, values):
|
def fake_fixed_ip_update(context, address, values):
|
||||||
ips = filter(lambda i: i['address'] == address,
|
ips = [i for i in fixed_ips if i['address'] == address]
|
||||||
fixed_ips)
|
|
||||||
fif = copy.deepcopy(fixed_ip_fields)
|
fif = copy.deepcopy(fixed_ip_fields)
|
||||||
if ips:
|
if ips:
|
||||||
for key in values:
|
for key in values:
|
||||||
ips[0][key] = values[key]
|
ips[0][key] = values[key]
|
||||||
if key == 'virtual_interface_id':
|
if key == 'virtual_interface_id':
|
||||||
vif = filter(lambda x: x['id'] == values[key],
|
vif = [v for v in virtual_interfacees
|
||||||
virtual_interfacees)
|
if v['id'] == values[key]]
|
||||||
if not vif:
|
if not vif:
|
||||||
continue
|
continue
|
||||||
fif['virtual_interface'] = FakeModel(vif[0])
|
fif['virtual_interface'] = FakeModel(vif[0])
|
||||||
|
@ -274,9 +261,8 @@ def fake_virtual_interface_get_by_instance(context, instance_id):
|
||||||
def fake_virtual_interface_get_by_instance_and_network(context,
|
def fake_virtual_interface_get_by_instance_and_network(context,
|
||||||
instance_id,
|
instance_id,
|
||||||
network_id):
|
network_id):
|
||||||
vif = filter(lambda m: m['instance_id'] == instance_id and
|
vif = [v for v in virtual_interfacees if v['instance_id'] == instance_id
|
||||||
m['network_id'] == network_id,
|
and v['network_id'] == network_id]
|
||||||
virtual_interfacees)
|
|
||||||
if not vif:
|
if not vif:
|
||||||
return None
|
return None
|
||||||
return FakeModel(vif[0])
|
return FakeModel(vif[0])
|
||||||
|
@ -291,7 +277,7 @@ def fake_network_create_safe(context, values):
|
||||||
|
|
||||||
|
|
||||||
def fake_network_get(context, network_id):
|
def fake_network_get(context, network_id):
|
||||||
net = filter(lambda n: n['id'] == network_id, networks)
|
net = [n for n in networks if n['id'] == network_id]
|
||||||
if not net:
|
if not net:
|
||||||
return None
|
return None
|
||||||
return FakeModel(net[0])
|
return FakeModel(net[0])
|
||||||
|
@ -302,19 +288,19 @@ def fake_network_get_all(context):
|
||||||
|
|
||||||
|
|
||||||
def fake_network_get_all_by_host(context, host):
|
def fake_network_get_all_by_host(context, host):
|
||||||
nets = filter(lambda n: n['host'] == host, networks)
|
nets = [n for n in networks if n['host'] == host]
|
||||||
return [FakeModel(n) for n in nets]
|
return [FakeModel(n) for n in nets]
|
||||||
|
|
||||||
|
|
||||||
def fake_network_set_host(context, network_id, host_id):
|
def fake_network_set_host(context, network_id, host_id):
|
||||||
nets = filter(lambda n: n['id'] == network_id, networks)
|
nets = [n for n in networks if n['id'] == network_id]
|
||||||
for net in nets:
|
for net in nets:
|
||||||
net['host'] = host_id
|
net['host'] = host_id
|
||||||
return host_id
|
return host_id
|
||||||
|
|
||||||
|
|
||||||
def fake_network_update(context, network_id, values):
|
def fake_network_update(context, network_id, values):
|
||||||
nets = filter(lambda n: n['id'] == network_id, networks)
|
nets = [n for n in networks if n['id'] == network_id]
|
||||||
for net in nets:
|
for net in nets:
|
||||||
for key in values:
|
for key in values:
|
||||||
net[key] = values[key]
|
net[key] = values[key]
|
||||||
|
|
|
@ -197,7 +197,8 @@ nova.tests.unit.keymgr.test_key.SymmetricKeyTestCase
|
||||||
nova.tests.unit.keymgr.test_mock_key_mgr.MockKeyManagerTestCase
|
nova.tests.unit.keymgr.test_mock_key_mgr.MockKeyManagerTestCase
|
||||||
nova.tests.unit.keymgr.test_single_key_mgr.SingleKeyManagerTestCase
|
nova.tests.unit.keymgr.test_single_key_mgr.SingleKeyManagerTestCase
|
||||||
nova.tests.unit.network.test_api.ApiTestCase
|
nova.tests.unit.network.test_api.ApiTestCase
|
||||||
nova.tests.unit.network.test_linux_net.LinuxNetworkTestCase
|
nova.tests.unit.network.test_linux_net.LinuxNetworkTestCase.test_get_dhcp_leases_for_nw00
|
||||||
|
nova.tests.unit.network.test_linux_net.LinuxNetworkTestCase.test_get_dhcp_leases_for_nw01
|
||||||
nova.tests.unit.network.test_manager.AllocateTestCase
|
nova.tests.unit.network.test_manager.AllocateTestCase
|
||||||
nova.tests.unit.network.test_manager.CommonNetworkTestCase
|
nova.tests.unit.network.test_manager.CommonNetworkTestCase
|
||||||
nova.tests.unit.network.test_manager.FlatDHCPNetworkTestCase
|
nova.tests.unit.network.test_manager.FlatDHCPNetworkTestCase
|
||||||
|
@ -229,7 +230,6 @@ nova.tests.unit.test_metadata.MetadataPasswordTestCase
|
||||||
nova.tests.unit.test_metadata.MetadataTestCase
|
nova.tests.unit.test_metadata.MetadataTestCase
|
||||||
nova.tests.unit.test_metadata.OpenStackMetadataTestCase
|
nova.tests.unit.test_metadata.OpenStackMetadataTestCase
|
||||||
nova.tests.unit.test_nova_manage.CellCommandsTestCase
|
nova.tests.unit.test_nova_manage.CellCommandsTestCase
|
||||||
nova.tests.unit.test_nova_manage.FixedIpCommandsTestCase
|
|
||||||
nova.tests.unit.test_objectstore.S3APITestCase
|
nova.tests.unit.test_objectstore.S3APITestCase
|
||||||
nova.tests.unit.test_pipelib.PipelibTest
|
nova.tests.unit.test_pipelib.PipelibTest
|
||||||
nova.tests.unit.test_policy.AdminRolePolicyTestCase
|
nova.tests.unit.test_policy.AdminRolePolicyTestCase
|
||||||
|
|
Loading…
Reference in New Issue