Fix using filter() to meet python2,3

As mentioned in link[1], if we need filter on python3,
Replace filter(lambda obj: test(obj), data) with:
[obj for obj in data if test(obj)].

[1] https://wiki.openstack.org/wiki/Python3

Change-Id: Ie484ccd7ef0428313a29e9ef6930ebb2646ee879
This commit is contained in:
Ha Van Tu 2016-08-29 19:00:12 +07:00
parent a5cc0be5c6
commit 3d9de244ce
4 changed files with 4 additions and 6 deletions

View File

@ -147,7 +147,7 @@ class _TestInstanceObject(object):
exp_cols.remove('migration_context')
exp_cols.remove('keypairs')
exp_cols.remove('device_metadata')
exp_cols = list(filter(lambda x: 'flavor' not in x, exp_cols))
exp_cols = [exp_col for exp_col in exp_cols if 'flavor' not in exp_col]
exp_cols.extend(['extra', 'extra.numa_topology', 'extra.pci_requests',
'extra.flavor', 'extra.vcpu_model',
'extra.migration_context', 'extra.keypairs',

View File

@ -255,8 +255,7 @@ class IptablesFirewallTestCase(test.NoDBTestCase):
self.fw.prepare_instance_filter(instance_ref, network_model)
self.fw.apply_instance_filter(instance_ref, network_model)
in_rules = filter(lambda l: not l.startswith('#'),
self.in_rules)
in_rules = [l for l in self.in_rules if not l.startswith('#')]
for rule in in_rules:
if 'nova' not in rule:
self.assertIn(rule, self.out_rules,

View File

@ -232,7 +232,7 @@ class ManagedObject(object):
def delete(self, attr):
"""Deletes an attribute."""
self.propSet = filter(lambda elem: elem.name != attr, self.propSet)
self.propSet = [elem for elem in self.propSet if elem.name != attr]
def __setattr__(self, attr, val):
# TODO(hartsocks): this is adds unnecessary complexity to the class

View File

@ -2728,8 +2728,7 @@ class XenAPIDom0IptablesFirewallTestCase(stubs.XenAPITestBase):
return secgroup
def _validate_security_group(self):
in_rules = filter(lambda l: not l.startswith('#'),
self._in_rules)
in_rules = [l for l in self._in_rules if not l.startswith('#')]
for rule in in_rules:
if 'nova' not in rule:
self.assertIn(rule, self._out_rules,