Merge "Linuxbridge agent: detect existing IP on bridge"

This commit is contained in:
Jenkins 2017-06-19 21:54:56 +00:00 committed by Gerrit Code Review
commit c4fd0317a3
2 changed files with 17 additions and 2 deletions

View File

@ -355,7 +355,10 @@ class LinuxBridgeManager(amb.CommonAgentManagerBase):
# Append IP's to bridge if necessary
if ips:
for ip in ips:
dst_device.addr.add(cidr=ip['cidr'])
# If bridge ip address already exists, then don't add
# otherwise will report error
if not dst_device.addr.list(to=ip['cidr']):
dst_device.addr.add(cidr=ip['cidr'])
if gateway:
# Ensure that the gateway can be updated by changing the metric

View File

@ -415,7 +415,19 @@ class TestLinuxBridgeManager(base.BaseTestCase):
ip_version=4,
dynamic=False)
with mock.patch.object(ip_lib.IpAddrCommand, 'add') as add_fn,\
mock.patch.object(ip_lib.IpAddrCommand, 'delete') as del_fn:
mock.patch.object(ip_lib.IpAddrCommand, 'delete') as del_fn,\
mock.patch.object(ip_lib.IpAddrCommand, 'list') as list_fn:
# 'list' actually returns a dict, but we're only simulating
# whether the device exists or not
list_fn.side_effect = [True, False]
self.lbm._update_interface_ip_details("br0", "eth0",
[ipdict], None)
self.assertFalse(add_fn.called)
self.assertTrue(del_fn.called)
add_fn.reset_mock()
del_fn.reset_mock()
self.lbm._update_interface_ip_details("br0", "eth0",
[ipdict], None)
self.assertTrue(add_fn.called)