Merge "Do not raise an error deleting neighbour entry"

This commit is contained in:
Jenkins 2017-01-31 21:13:46 +00:00 committed by Gerrit Code Review
commit eeeee06bf0
3 changed files with 32 additions and 7 deletions

View File

@ -16,6 +16,7 @@ import socket
import pyroute2
from pyroute2.netlink import rtnl
from pyroute2.netlink.rtnl import ndmsg
from pyroute2 import NetlinkError
from neutron._i18n import _
from neutron import privileged
@ -132,13 +133,19 @@ def delete_neigh_entry(ip_version, ip_address, mac_address, device, namespace,
:param namespace: The name of the namespace in which to delete the entry
"""
family = _IP_VERSION_FAMILY_MAP[ip_version]
_run_iproute('delete',
device,
namespace,
dst=ip_address,
lladdr=mac_address,
family=family,
**kwargs)
try:
_run_iproute('delete',
device,
namespace,
dst=ip_address,
lladdr=mac_address,
family=family,
**kwargs)
except NetlinkError as e:
# trying to delete a non-existent entry shouldn't raise an error
if e.code == errno.ENOENT:
return
raise
@privileged.default.entrypoint

View File

@ -261,6 +261,16 @@ class IpLibTestCase(IpLibTestFramework):
ip_lib.dump_neigh_entries(4, device="nosuchdevice",
namespace=attr.namespace)
def test_delete_neigh_entries(self):
attr = self.generate_device_details(
ip_cidrs=["%s/24" % TEST_IP, "fd00::1/64"]
)
mac_address = utils.get_random_mac('fa:16:3e:00:00:00'.split(':'))
device = self.manage_device(attr)
# trying to delete a non-existent entry shouldn't raise an error
device.neigh.delete(TEST_IP_NEIGH, mac_address)
def _check_for_device_name(self, ip, name, should_exist):
exist = any(d for d in ip.get_devices() if d.name == name)
self.assertEqual(should_exist, exist)

View File

@ -20,12 +20,14 @@ import netaddr
from neutron_lib import exceptions
import pyroute2
from pyroute2.netlink.rtnl import ndmsg
from pyroute2 import NetlinkError
import testtools
from neutron.agent.common import utils # noqa
from neutron.agent.linux import ip_lib
from neutron.common import exceptions as n_exc
from neutron import privileged
from neutron.privileged.agent.linux import ip_lib as priv_lib
from neutron.tests import base
NETNS_SAMPLE = [
@ -1642,6 +1644,12 @@ class TestIpNeighCommand(TestIPCmdBase):
family=2,
ifindex=1)
@mock.patch.object(priv_lib, '_run_iproute')
def test_delete_entry_not_exist(self, mock_run_iproute):
# trying to delete a non-existent entry shouldn't raise an error
mock_run_iproute.side_effect = NetlinkError(errno.ENOENT, None)
self.neigh_cmd.delete('192.168.45.100', 'cc:dd:ee:ff:ab:cd')
@mock.patch.object(pyroute2, 'NetNS')
def test_dump_entries(self, mock_netns):
mock_netns_instance = mock_netns.return_value