Merge "Create veth pair devices using pyroute2"

This commit is contained in:
Zuul 2018-08-18 22:17:56 +00:00 committed by Gerrit Code Review
commit e05cc40617
2 changed files with 13 additions and 17 deletions

View File

@ -179,18 +179,16 @@ class IPWrapper(SubProcessBase):
return IPDevice(name, namespace=self.namespace)
def add_veth(self, name1, name2, namespace2=None):
# TODO(slaweq): switch to pyroute2 when issue
# https://github.com/svinota/pyroute2/issues/463
# will be closed
args = ['add', name1, 'type', 'veth', 'peer', 'name', name2]
peer = {'ifname': name2}
if namespace2 is None:
namespace2 = self.namespace
else:
self.ensure_namespace(namespace2)
args += ['netns', namespace2]
peer['net_ns_fd'] = namespace2
self._as_root([], 'link', tuple(args))
privileged.create_interface(
name1, self.namespace, 'veth', peer=peer)
return (IPDevice(name1, namespace=self.namespace),
IPDevice(name2, namespace=namespace2))

View File

@ -300,12 +300,11 @@ class TestIpWrapper(base.BaseTestCase):
ip_lib.IPWrapper().add_tuntap('tap0')
create.assert_called_once_with('tap0', None, 'tuntap', mode='tap')
def test_add_veth(self):
@mock.patch.object(priv_lib, 'create_interface')
def test_add_veth(self, create):
ip_lib.IPWrapper().add_veth('tap0', 'tap1')
self.execute.assert_called_once_with([], 'link',
('add', 'tap0', 'type', 'veth',
'peer', 'name', 'tap1'),
run_as_root=True, namespace=None)
create.assert_called_once_with(
'tap0', None, 'veth', peer={'ifname': 'tap1'})
@mock.patch.object(priv_lib, 'create_interface')
def test_add_macvtap(self, create):
@ -319,16 +318,15 @@ class TestIpWrapper(base.BaseTestCase):
ip_lib.IPWrapper().del_veth('fpr-1234')
delete.assert_called_once_with('fpr-1234', None)
def test_add_veth_with_namespaces(self):
@mock.patch.object(priv_lib, 'create_interface')
def test_add_veth_with_namespaces(self, create):
ns2 = 'ns2'
with mock.patch.object(ip_lib.IPWrapper, 'ensure_namespace') as en:
ip_lib.IPWrapper().add_veth('tap0', 'tap1', namespace2=ns2)
en.assert_has_calls([mock.call(ns2)])
self.execute.assert_called_once_with([], 'link',
('add', 'tap0', 'type', 'veth',
'peer', 'name', 'tap1',
'netns', ns2),
run_as_root=True, namespace=None)
create.assert_called_once_with(
'tap0', None, 'veth',
peer={'ifname': 'tap1', 'net_ns_fd': 'ns2'})
@mock.patch.object(priv_lib, 'create_interface')
def test_add_dummy(self, create):