diff --git a/neutron/agent/l3/dvr_fip_ns.py b/neutron/agent/l3/dvr_fip_ns.py index 5d09c2fffa2..f4a4f4c7eb3 100644 --- a/neutron/agent/l3/dvr_fip_ns.py +++ b/neutron/agent/l3/dvr_fip_ns.py @@ -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: diff --git a/neutron/agent/linux/ip_lib.py b/neutron/agent/linux/ip_lib.py index 1159943bf8b..03d6b4cc8a2 100644 --- a/neutron/agent/linux/ip_lib.py +++ b/neutron/agent/linux/ip_lib.py @@ -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)) diff --git a/neutron/tests/unit/agent/linux/test_ip_lib.py b/neutron/tests/unit/agent/linux/test_ip_lib.py index 3a9f63c525e..bdacc9415ec 100644 --- a/neutron/tests/unit/agent/linux/test_ip_lib.py +++ b/neutron/tests/unit/agent/linux/test_ip_lib.py @@ -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],