commit eeaafdf71ce2b3b57d76558281fa27a97c9375b2 Author: Ondrej Lichtner olichtne@redhat.com Date: Thu Aug 21 14:25:31 2014 +0200
NetTestSlave: make return_if_netns method recursive
This patch makes the 'return_if_netns' slave method recursive - the controller always calls it in the root namespace which will reroute the method to the specific namespace that the device was moved into. In addition the InterfaceManager class will not remove Device objects if they're moved to a namespace (_netns attribute != None) or if they have a configuration object associated with them. This works around a bug on older kernels that generate RTM_DELLINK messages for slave devices when removing the master device (e.g. bridge).
Signed-off-by: Ondrej Lichtner olichtne@redhat.com Signed-off-by: Jiri Pirko jiri@resnulli.us
lnst/Controller/Machine.py | 3 +-- lnst/Slave/InterfaceManager.py | 3 +-- lnst/Slave/NetTestSlave.py | 20 ++++++++++++++++---- 3 files changed, 18 insertions(+), 8 deletions(-) --- diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py index 94d4fbd..7bacad1 100644 --- a/lnst/Controller/Machine.py +++ b/lnst/Controller/Machine.py @@ -621,8 +621,7 @@ class Interface(object): if self._netns != None: self._machine._rpc_call_to_netns(self._netns, "deconfigure_interface", self.get_id()) - self._machine._rpc_call_to_netns(self._netns, - "return_if_netns", self.get_id()) + self._machine._rpc_call_to("return_if_netns", self.get_id()) else: self._machine._rpc_call("deconfigure_interface", self.get_id()) self._configured = False diff --git a/lnst/Slave/InterfaceManager.py b/lnst/Slave/InterfaceManager.py index 78cc46b..16eba2d 100644 --- a/lnst/Slave/InterfaceManager.py +++ b/lnst/Slave/InterfaceManager.py @@ -101,7 +101,7 @@ class InterfaceManager(object): elif msg['header']['type'] == RTM_DELLINK: if msg['index'] in self._devices: dev = self._devices[msg['index']] - if dev.get_netns() != None: + if dev.get_netns() == None and dev.get_conf_dict() == None: dev.del_link() del self._devices[msg['index']] else: @@ -230,7 +230,6 @@ class Device(object): self._state = nl_msg.get_attr("IFLA_OPERSTATE") self._ip = None #TODO self.set_master(nl_msg.get_attr("IFLA_MASTER"), primary=True) - self._netns = None
link = nl_msg.get_attr("IFLA_LINK") if link != None: diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py index e7d620c..d331818 100644 --- a/lnst/Slave/NetTestSlave.py +++ b/lnst/Slave/NetTestSlave.py @@ -468,10 +468,22 @@ class SlaveMethods:
def return_if_netns(self, if_id): device = self._if_manager.get_mapped_device(if_id) - dev_name = device.get_name() - ppid = os.getppid() - exec_cmd("ip link set %s netns %d" % (dev_name, ppid)) - return True + if device.get_netns() == None: + dev_name = device.get_name() + ppid = os.getppid() + exec_cmd("ip link set %s netns %d" % (dev_name, ppid)) + return True + else: + netns = device.get_netns() + msg = {"type": "command", "method_name": "return_if_netns", + "args": [if_id]} + self._server_handler.send_data_to_netns(netns, msg) + result = self._slave_server.wait_for_result(netns) + if result["result"] != True: + raise Exception("Return from netns failed.") + + device.set_netns(None) + return True
class ServerHandler(object): def __init__(self, addr):
lnst-developers@lists.fedorahosted.org