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
This commit is contained in:
rajeev 2014-04-16 18:24:44 -04:00
parent 9a1af60ae0
commit c2e3c73693
2 changed files with 44 additions and 0 deletions

View File

@ -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'

View File

@ -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'))