Remove lambda usage, fix pep8 E731 violation
Our pep8 is now checking E731 and failing. This stops passing the lambda in questino around and instead just does the work in-line. Change-Id: I47c44a559f5e912386a004bf7655732e13e844d3
This commit is contained in:
parent
0b3358b85f
commit
9f9b7d0fde
@ -205,21 +205,21 @@ class IPManager(base.Manager):
|
||||
|
||||
add = functools.partial(_gen_cmd, 'add')
|
||||
delete = functools.partial(_gen_cmd, 'del')
|
||||
mutator = lambda a: (a.ip, a.prefixlen)
|
||||
|
||||
self._update_set(real_ifname, interface, old_interface,
|
||||
'all_addresses', add, delete, mutator)
|
||||
'all_addresses', add, delete)
|
||||
|
||||
def _update_set(self, real_ifname, interface, old_interface, attribute,
|
||||
fmt_args_add, fmt_args_delete, mutator=lambda x: x):
|
||||
fmt_args_add, fmt_args_delete):
|
||||
"""
|
||||
Compare the set of addresses (the current set and the desired set)
|
||||
for an interface and generate a series of `ip addr add` and `ip addr
|
||||
del` commands.
|
||||
"""
|
||||
|
||||
next_set = set(mutator(i) for i in getattr(interface, attribute))
|
||||
prev_set = set(mutator(i) for i in getattr(old_interface, attribute))
|
||||
next_set = set((i.ip, i.prefixlen)
|
||||
for i in getattr(interface, attribute))
|
||||
prev_set = set((i.ip, i.prefixlen)
|
||||
for i in getattr(old_interface, attribute))
|
||||
|
||||
if next_set == prev_set:
|
||||
return
|
||||
|
@ -237,7 +237,6 @@ class IPTestCase(TestCase):
|
||||
'all_addresses',
|
||||
mock.ANY,
|
||||
mock.ANY,
|
||||
mock.ANY
|
||||
)
|
||||
|
||||
def test_address_add(self):
|
||||
@ -299,14 +298,13 @@ class IPTestCase(TestCase):
|
||||
|
||||
add = lambda g: ('addr', 'add', '/'.join(map(str, g)), 'dev', 'em0')
|
||||
delete = lambda g: ('addr', 'del', '/'.join(map(str, g)), 'dev', 'em0')
|
||||
mutator = lambda x: (x.ip, x.prefixlen)
|
||||
|
||||
mgr = ip.IPManager()
|
||||
with mock.patch.object(
|
||||
mgr, 'generic_to_host', lambda x: x.replace('ge', 'em')
|
||||
):
|
||||
mgr._update_set('em0', iface, old_iface, 'all_addresses', add,
|
||||
delete, mutator=mutator)
|
||||
delete)
|
||||
|
||||
assert self.mock_execute.call_args_list == [
|
||||
mock.call([
|
||||
@ -322,11 +320,13 @@ class IPTestCase(TestCase):
|
||||
]
|
||||
|
||||
def test_update_set_no_diff(self):
|
||||
a = netaddr.IPNetwork('192.168.101.2/24')
|
||||
b = netaddr.IPNetwork('192.168.102.2/24')
|
||||
iface = mock.Mock()
|
||||
iface.all_addresses = ['a', 'b']
|
||||
iface.all_addresses = [a, b]
|
||||
|
||||
old_iface = mock.Mock()
|
||||
old_iface.all_addresses = ['a', 'b']
|
||||
old_iface.all_addresses = [a, b]
|
||||
|
||||
add = lambda g: ('em0', 'add', g)
|
||||
delete = lambda g: ('em0', 'del', g)
|
||||
|
Loading…
Reference in New Issue
Block a user