diff --git a/neutron/agent/linux/ip_lib.py b/neutron/agent/linux/ip_lib.py index 05a9b3ee287..b1ffef65941 100644 --- a/neutron/agent/linux/ip_lib.py +++ b/neutron/agent/linux/ip_lib.py @@ -16,6 +16,7 @@ import os import re +from debtcollector import removals import eventlet import netaddr from neutron_lib import constants @@ -847,6 +848,9 @@ class IpNeighCommand(IpDeviceCommandBase): self._parent.namespace, **kwargs) + @removals.remove( + version='Ocata', removal_version='Pike', + message="Use 'dump' in IpNeighCommand() class instead") def show(self, ip_version): options = [ip_version] return self._as_root(options, diff --git a/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py b/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py index 18901f4b80a..8a1f19b9f08 100644 --- a/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py +++ b/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py @@ -34,7 +34,6 @@ from six import moves from neutron._i18n import _LE, _LI, _LW from neutron.agent.linux import bridge_lib from neutron.agent.linux import ip_lib -from neutron.agent.linux import utils from neutron.api.rpc.handlers import securitygroups_rpc as sg_rpc from neutron.common import config as common_config from neutron.common import exceptions @@ -667,10 +666,10 @@ class LinuxBridgeManager(amb.CommonAgentManagerBase): LOG.debug('Using %s VXLAN mode', self.vxlan_mode) def fdb_ip_entry_exists(self, mac, ip, interface): - entries = utils.execute(['ip', 'neigh', 'show', 'to', ip, - 'dev', interface], - run_as_root=True) - return mac in entries + ip_version = ip_lib.get_ip_version(ip) + entry = ip_lib.dump_neigh_entries(ip_version, interface, dst=ip, + lladdr=mac) + return entry != [] def fdb_bridge_entry_exists(self, mac, interface, agent_ip=None): entries = bridge_lib.FdbInterface.show(interface) @@ -681,11 +680,11 @@ class LinuxBridgeManager(amb.CommonAgentManagerBase): def add_fdb_ip_entry(self, mac, ip, interface): if cfg.CONF.VXLAN.arp_responder: - ip_lib.IPDevice(interface).neigh.add(ip, mac) + ip_lib.add_neigh_entry(ip, mac, interface) def remove_fdb_ip_entry(self, mac, ip, interface): if cfg.CONF.VXLAN.arp_responder: - ip_lib.IPDevice(interface).neigh.delete(ip, mac) + ip_lib.delete_neigh_entry(ip, mac, interface) def add_fdb_entries(self, agent_ip, ports, interface): for mac, ip in ports: diff --git a/neutron/tests/functional/agent/l3/test_dvr_router.py b/neutron/tests/functional/agent/l3/test_dvr_router.py index 71af3bef51d..e63ad395f81 100644 --- a/neutron/tests/functional/agent/l3/test_dvr_router.py +++ b/neutron/tests/functional/agent/l3/test_dvr_router.py @@ -805,9 +805,11 @@ class TestDvrRouter(framework.L3AgentTestFramework): router1 = self.manage_router(self.agent, router_info) internal_device = router1.get_internal_device_name( router_info['_interfaces'][0]['id']) - neighbors = ip_lib.IPDevice(internal_device, router1.ns_name).neigh - self.assertEqual(expected_neighbor, - neighbors.show(ip_version=4).split()[0]) + neighbor = ip_lib.dump_neigh_entries(4, internal_device, + router1.ns_name, + dst=expected_neighbor) + self.assertNotEqual([], neighbor) + self.assertEqual(expected_neighbor, neighbor[0]['dst']) def _assert_rfp_fpr_mtu(self, router, expected_mtu=1500): dev_mtu = self.get_device_mtu( diff --git a/neutron/tests/functional/agent/l3/test_keepalived_state_change.py b/neutron/tests/functional/agent/l3/test_keepalived_state_change.py index d1f22850d30..413cf576e77 100644 --- a/neutron/tests/functional/agent/l3/test_keepalived_state_change.py +++ b/neutron/tests/functional/agent/l3/test_keepalived_state_change.py @@ -14,7 +14,6 @@ import functools import os -import re import eventlet import mock @@ -30,26 +29,12 @@ from neutron.tests.common import machine_fixtures as mf from neutron.tests.common import net_helpers from neutron.tests.functional import base -IPV4_NEIGH_REGEXP = re.compile( - r'(?P(\d{1,3}\.){3}\d{1,3}) ' - '.*(?P([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]){2}).*') - - -def get_arp_ip_mac_pairs(device_name, namespace): - """Generate (ip, mac) pairs from device's ip neigh. - - Each neigh entry has following format: - 192.168.0.1 lladdr fa:16:3e:01:ba:d3 STALE - """ - device = ip_lib.IPDevice(device_name, namespace) - for entry in device.neigh.show(ip_version=4).splitlines(): - match = IPV4_NEIGH_REGEXP.match(entry) - if match: - yield match.group('ip'), match.group('mac') - def has_expected_arp_entry(device_name, namespace, ip, mac): - return (ip, mac) in get_arp_ip_mac_pairs(device_name, namespace) + ip_version = ip_lib.get_ip_version(ip) + entry = ip_lib.dump_neigh_entries(ip_version, device_name, namespace, + dst=ip, lladdr=mac) + return entry != [] class TestKeepalivedStateChange(base.BaseSudoTestCase): diff --git a/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/agent/test_linuxbridge_neutron_agent.py b/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/agent/test_linuxbridge_neutron_agent.py index 87de488e9ae..6f3a735e89c 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/agent/test_linuxbridge_neutron_agent.py +++ b/neutron/tests/unit/plugins/ml2/drivers/linuxbridge/agent/test_linuxbridge_neutron_agent.py @@ -953,7 +953,7 @@ class TestLinuxBridgeRpcCallbacks(base.BaseTestCase): with mock.patch.object(utils, 'execute', return_value='') as execute_fn, \ - mock.patch.object(ip_lib.IpNeighCommand, 'add', + mock.patch.object(ip_lib, 'add_neigh_entry', return_value='') as add_fn: self.lb_rpc.fdb_add(None, fdb_entries) @@ -972,7 +972,7 @@ class TestLinuxBridgeRpcCallbacks(base.BaseTestCase): ] execute_fn.assert_has_calls(expected) if proxy_enabled: - add_fn.assert_called_with('port_ip', 'port_mac') + add_fn.assert_called_with('port_ip', 'port_mac', 'vxlan-1') else: add_fn.assert_not_called() @@ -1022,7 +1022,7 @@ class TestLinuxBridgeRpcCallbacks(base.BaseTestCase): with mock.patch.object(utils, 'execute', return_value='') as execute_fn, \ - mock.patch.object(ip_lib.IpNeighCommand, 'delete', + mock.patch.object(ip_lib, 'delete_neigh_entry', return_value='') as del_fn: self.lb_rpc.fdb_remove(None, fdb_entries) @@ -1039,7 +1039,7 @@ class TestLinuxBridgeRpcCallbacks(base.BaseTestCase): ] execute_fn.assert_has_calls(expected) if proxy_enabled: - del_fn.assert_called_with('port_ip', 'port_mac') + del_fn.assert_called_with('port_ip', 'port_mac', 'vxlan-1') else: del_fn.assert_not_called() @@ -1057,15 +1057,15 @@ class TestLinuxBridgeRpcCallbacks(base.BaseTestCase): {'before': [['port_mac', 'port_ip_1']], 'after': [['port_mac', 'port_ip_2']]}}}} - with mock.patch.object(ip_lib.IpNeighCommand, 'add', + with mock.patch.object(ip_lib, 'add_neigh_entry', return_value='') as add_fn, \ - mock.patch.object(ip_lib.IpNeighCommand, 'delete', + mock.patch.object(ip_lib, 'delete_neigh_entry', return_value='') as del_fn: self.lb_rpc.fdb_update(None, fdb_entries) if proxy_enabled: - del_fn.assert_called_with('port_ip_1', 'port_mac') - add_fn.assert_called_with('port_ip_2', 'port_mac') + del_fn.assert_called_with('port_ip_1', 'port_mac', 'vxlan-1') + add_fn.assert_called_with('port_ip_2', 'port_mac', 'vxlan-1') else: del_fn.assert_not_called() add_fn.assert_not_called()