DVR: Use existing IPDevice to add address on FIP VETH

create_rtr_2_fip_link() has IPDevice instances for each
end of the VETH pair it created, just use them to add the
link-local IP to each one.  Because this is a point-to-point
link, we don't add the broadcast address when we assign the IP,
so add a flag to IpAddrCommand() class to accomodate us.
This is also setup for a follow-on patch.

Partial-Bug: #1566383
Change-Id: I66d70afaf3c52861e0887d3f535d5327ea46b128
This commit is contained in:
Brian Haley 2016-04-22 16:09:07 -04:00
parent b9bec4be6b
commit 17cfffbbfa
3 changed files with 13 additions and 13 deletions

View File

@ -229,11 +229,8 @@ class FipNamespace(namespaces.Namespace):
ipd.route.add_route(gw_ip, scope='link')
ipd.route.add_gateway(gw_ip)
def _internal_ns_interface_added(self, ip_cidr,
interface_name, ns_name):
ip_wrapper = ip_lib.IPWrapper(namespace=ns_name)
ip_wrapper.netns.execute(['ip', 'addr', 'add',
ip_cidr, 'dev', interface_name])
def _add_cidr_to_device(self, device, ip_cidr):
device.addr.add(ip_cidr, add_broadcast=False)
def create_rtr_2_fip_link(self, ri):
"""Create interface between router and Floating IP namespace."""
@ -253,12 +250,8 @@ class FipNamespace(namespaces.Namespace):
rtr_2_fip_dev, fip_2_rtr_dev = ip_wrapper.add_veth(rtr_2_fip_name,
fip_2_rtr_name,
fip_ns_name)
self._internal_ns_interface_added(str(rtr_2_fip),
rtr_2_fip_name,
ri.ns_name)
self._internal_ns_interface_added(str(fip_2_rtr),
fip_2_rtr_name,
fip_ns_name)
self._add_cidr_to_device(rtr_2_fip_dev, str(rtr_2_fip))
self._add_cidr_to_device(fip_2_rtr_dev, str(fip_2_rtr))
mtu = (self.agent_conf.network_device_mtu or
ri.get_ex_gw_port().get('mtu'))
if mtu:

View File

@ -567,12 +567,12 @@ class IpLinkCommand(IpDeviceCommandBase):
class IpAddrCommand(IpDeviceCommandBase):
COMMAND = 'addr'
def add(self, cidr, scope='global'):
def add(self, cidr, scope='global', add_broadcast=True):
net = netaddr.IPNetwork(cidr)
args = ['add', cidr,
'scope', scope,
'dev', self.name]
if net.version == 4:
if add_broadcast and net.version == 4:
args += ['brd', str(net[-1])]
self._as_root([net.version], tuple(args))

View File

@ -813,6 +813,13 @@ class TestIpAddrCommand(TestIPCmdBase):
'dev', 'tap0',
'brd', '192.168.45.255'))
def test_add_address_no_broadcast(self):
self.addr_cmd.add('192.168.45.100/24', add_broadcast=False)
self._assert_sudo([4],
('add', '192.168.45.100/24',
'scope', 'global',
'dev', 'tap0'))
def test_del_address(self):
self.addr_cmd.delete('192.168.45.100/24')
self._assert_sudo([4],