Merge "DVR: Use existing IPDevice to add address on FIP VETH"

This commit is contained in:
Jenkins 2016-05-05 17:29:28 +00:00 committed by Gerrit Code Review
commit f18db6f754
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

@ -564,12 +564,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

@ -798,6 +798,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],