Linuxbridge agent: detect existing IP on bridge

If bridge IP address already exists, when we try and add
it an error will be raised.  Check for the existence of
the IP to avoid the error.

Closes-Bug: #1697926
Change-Id: I9aae3b4f0fab053e8c215887f58b983d9549582d
This commit is contained in:
wlfightup 2017-06-14 17:45:25 +08:00 committed by Brian Haley
parent 044a06383b
commit ba5e846859
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)