From 0ab7733f7f02514c923ed007a2b2934a81337f55 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Tue, 27 Feb 2018 10:58:42 +0100 Subject: [PATCH] lib: topogen support for link_enable on other netns In the case where vrf backend is based on NETNS, the link enable command switches from context so as to perform the command. Signed-off-by: Philippe Guibert --- tests/topotests/lib/topogen.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/topotests/lib/topogen.py b/tests/topotests/lib/topogen.py index 8340d9187b..dbfd1414c0 100644 --- a/tests/topotests/lib/topogen.py +++ b/tests/topotests/lib/topogen.py @@ -449,7 +449,7 @@ class TopoGear(object): """ self.tgen.add_link(self, node, myif, nodeif) - def link_enable(self, myif, enabled=True): + def link_enable(self, myif, enabled=True, netns=None): """ Set this node interface administrative state. myif: this node interface name @@ -466,9 +466,12 @@ class TopoGear(object): logger.info('setting node "{}" link "{}" to state "{}"'.format( self.name, myif, operation )) - return self.run('ip link set dev {} {}'.format(myif, operation)) + extract='' + if netns is not None: + extract = 'ip netns exec {} '.format(netns) + return self.run('{}ip link set dev {} {}'.format(extract, myif, operation)) - def peer_link_enable(self, myif, enabled=True): + def peer_link_enable(self, myif, enabled=True, netns=None): """ Set the peer interface administrative state. myif: this node interface name @@ -481,7 +484,7 @@ class TopoGear(object): raise KeyError('interface doesn\'t exists') node, nodeif = self.links[myif] - node.link_enable(nodeif, enabled) + node.link_enable(nodeif, enabled, netns) def new_link(self): """