Merge "Update in-tree code to use new neighbour functions"
This commit is contained in:
commit
d142f25689
@ -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,
|
||||
|
@ -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:
|
||||
|
@ -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(
|
||||
|
@ -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<ip>(\d{1,3}\.){3}\d{1,3}) '
|
||||
'.*(?P<mac>([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):
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user