From: rajeev Date: Wed, 16 Apr 2014 22:24:44 +0000 (-0400) Subject: Add 'ip neigh' to ip_lib X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=c2e3c73693b1003bcf1e60f73740b41ca90373ff;p=openstack-build%2Fneutron-build.git Add 'ip neigh' to ip_lib This change adds 'ip neigh add' and 'ip neigh delete' as Ip Device commands Partially-Implements: blueprint neutron-ovs-dvr Change-Id: I59428e2fe28c6a632c232b47cc46c097c281f253 --- diff --git a/neutron/agent/linux/ip_lib.py b/neutron/agent/linux/ip_lib.py index 9b259a163..c040362fd 100644 --- a/neutron/agent/linux/ip_lib.py +++ b/neutron/agent/linux/ip_lib.py @@ -192,6 +192,7 @@ class IPDevice(SubProcessBase): self.link = IpLinkCommand(self) self.addr = IpAddrCommand(self) self.route = IpRouteCommand(self) + self.neigh = IpNeighCommand(self) def __eq__(self, other): return (other is not None and self.name == other.name @@ -439,6 +440,30 @@ class IpRouteCommand(IpDeviceCommandBase): 'dev', device) +class IpNeighCommand(IpDeviceCommandBase): + COMMAND = 'neigh' + + def add(self, ip_version, ip_address, mac_address): + self._as_root('add', + ip_address, + 'lladdr', + mac_address, + 'nud', + 'permanent', + 'dev', + self.name, + options=[ip_version]) + + def delete(self, ip_version, ip_address, mac_address): + self._as_root('del', + ip_address, + 'lladdr', + mac_address, + 'dev', + self.name, + options=[ip_version]) + + class IpNetnsCommand(IpCommandBase): COMMAND = 'netns' diff --git a/neutron/tests/unit/test_linux_ip_lib.py b/neutron/tests/unit/test_linux_ip_lib.py index c0ae7f4a9..59fe4223c 100644 --- a/neutron/tests/unit/test_linux_ip_lib.py +++ b/neutron/tests/unit/test_linux_ip_lib.py @@ -799,3 +799,22 @@ class TestDeviceExists(base.BaseTestCase): # device doesn't exists ip_lib_mock.link.set_up.side_effect = RuntimeError self.assertFalse(ip_lib.ensure_device_is_ready("eth0")) + + +class TestIpNeighCommand(TestIPCmdBase): + def setUp(self): + super(TestIpNeighCommand, self).setUp() + self.parent.name = 'tap0' + self.command = 'neigh' + self.neigh_cmd = ip_lib.IpNeighCommand(self.parent) + + def test_add_entry(self): + self.neigh_cmd.add(4, '192.168.45.100', 'cc:dd:ee:ff:ab:cd') + self._assert_sudo([4], ('add', '192.168.45.100', 'lladdr', + 'cc:dd:ee:ff:ab:cd', 'nud', 'permanent', + 'dev', 'tap0')) + + def test_delete_entry(self): + self.neigh_cmd.delete(4, '192.168.45.100', 'cc:dd:ee:ff:ab:cd') + self._assert_sudo([4], ('del', '192.168.45.100', 'lladdr', + 'cc:dd:ee:ff:ab:cd', 'dev', 'tap0'))