When a device is moved to a network namespace an RTM_NEWLINK netlink message is generated and handled by InterfaceManager. The InterfaceManager creates a new instance of a generic Device class instead of a specific device class (e.g. VethDevice). This device also remains in disabled state so no actions or configurations can be made.
This patch fixes that by following changes.
The InterfaceManager is extended with remap_device() method that creates a new instance of the specific device class that replaces the generic Device instance.
The SlaveMethods are extended with remap_device() method that serves as an rpc interface for calling InterfaceManager's method from the Controller.
The Machine.remote_device_set_netns() method is updated to include an explicit rpc_call to remap the device to proper type.
Signed-off-by: Jan Tluka jtluka@redhat.com --- lnst/Controller/Machine.py | 10 ++++++++++ lnst/Slave/InterfaceManager.py | 14 ++++++++++++++ lnst/Slave/NetTestSlave.py | 3 +++ 3 files changed, 27 insertions(+)
diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py index 3bee2a55..a4c724ba 100644 --- a/lnst/Controller/Machine.py +++ b/lnst/Controller/Machine.py @@ -141,6 +141,16 @@ class Machine(object):
def remote_device_set_netns(self, dev, dst, src): self.rpc_call("set_dev_netns", dev, dst.name, netns=src) + dev_clsname = dev._dev_cls.__name__ + dev_args = dev._dev_args + dev_kwargs = dev._dev_kwargs + + self.rpc_call("remap_device", + dev.ifindex, + clsname=dev_clsname, + args=dev_args, + kwargs=dev_kwargs, + netns=dst)
def remote_device_method(self, index, method_name, args, kwargs, netns): config_res = DeviceMethodCallResult( diff --git a/lnst/Slave/InterfaceManager.py b/lnst/Slave/InterfaceManager.py index 221d386f..4a653dd7 100644 --- a/lnst/Slave/InterfaceManager.py +++ b/lnst/Slave/InterfaceManager.py @@ -221,6 +221,20 @@ class InterfaceManager(object): else: raise DeviceError("Device creation failed")
+ def remap_device(self, ifindex, clsname, args=[], kwargs={}): + devcls = self._device_classes[clsname] + old_device = self.get_device(ifindex) + kwargs["name"] = old_device.name + + try: + remapped_device = devcls(self, *args, **kwargs) + except KeyError as e: + raise DeviceConfigError("%s is a mandatory argument" % e) + remapped_device._bulk_enabled = False + remapped_device.ifindex = ifindex + self.replace_dev(ifindex, remapped_device) + self.rescan_devices() + def replace_dev(self, if_id, dev): del self._devices[if_id] self._devices[if_id] = dev diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py index d3ff90bf..2164b9c5 100644 --- a/lnst/Slave/NetTestSlave.py +++ b/lnst/Slave/NetTestSlave.py @@ -646,6 +646,9 @@ class SlaveMethods: #TODO check if device appeared in the destination namespace return True
+ def remap_device(self, ifindex, clsname, args=[], kwargs={}): + self._if_manager.remap_device(ifindex, clsname, args, kwargs) + # def return_if_netns(self, if_id): # device = self._if_manager.get_mapped_device(if_id) # if device.get_netns() == None:
pushed, thanks.
-Ondrej
On Thu, May 13, 2021 at 08:09:58PM +0200, Jan Tluka wrote:
When a device is moved to a network namespace an RTM_NEWLINK netlink message is generated and handled by InterfaceManager. The InterfaceManager creates a new instance of a generic Device class instead of a specific device class (e.g. VethDevice). This device also remains in disabled state so no actions or configurations can be made.
This patch fixes that by following changes.
The InterfaceManager is extended with remap_device() method that creates a new instance of the specific device class that replaces the generic Device instance.
The SlaveMethods are extended with remap_device() method that serves as an rpc interface for calling InterfaceManager's method from the Controller.
The Machine.remote_device_set_netns() method is updated to include an explicit rpc_call to remap the device to proper type.
Signed-off-by: Jan Tluka jtluka@redhat.com
lnst/Controller/Machine.py | 10 ++++++++++ lnst/Slave/InterfaceManager.py | 14 ++++++++++++++ lnst/Slave/NetTestSlave.py | 3 +++ 3 files changed, 27 insertions(+)
diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py index 3bee2a55..a4c724ba 100644 --- a/lnst/Controller/Machine.py +++ b/lnst/Controller/Machine.py @@ -141,6 +141,16 @@ class Machine(object):
def remote_device_set_netns(self, dev, dst, src): self.rpc_call("set_dev_netns", dev, dst.name, netns=src)
dev_clsname = dev._dev_cls.__name__
dev_args = dev._dev_args
dev_kwargs = dev._dev_kwargs
self.rpc_call("remap_device",
dev.ifindex,
clsname=dev_clsname,
args=dev_args,
kwargs=dev_kwargs,
netns=dst)
def remote_device_method(self, index, method_name, args, kwargs, netns): config_res = DeviceMethodCallResult(
diff --git a/lnst/Slave/InterfaceManager.py b/lnst/Slave/InterfaceManager.py index 221d386f..4a653dd7 100644 --- a/lnst/Slave/InterfaceManager.py +++ b/lnst/Slave/InterfaceManager.py @@ -221,6 +221,20 @@ class InterfaceManager(object): else: raise DeviceError("Device creation failed")
- def remap_device(self, ifindex, clsname, args=[], kwargs={}):
devcls = self._device_classes[clsname]
old_device = self.get_device(ifindex)
kwargs["name"] = old_device.name
try:
remapped_device = devcls(self, *args, **kwargs)
except KeyError as e:
raise DeviceConfigError("%s is a mandatory argument" % e)
remapped_device._bulk_enabled = False
remapped_device.ifindex = ifindex
self.replace_dev(ifindex, remapped_device)
self.rescan_devices()
- def replace_dev(self, if_id, dev): del self._devices[if_id] self._devices[if_id] = dev
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py index d3ff90bf..2164b9c5 100644 --- a/lnst/Slave/NetTestSlave.py +++ b/lnst/Slave/NetTestSlave.py @@ -646,6 +646,9 @@ class SlaveMethods: #TODO check if device appeared in the destination namespace return True
- def remap_device(self, ifindex, clsname, args=[], kwargs={}):
self._if_manager.remap_device(ifindex, clsname, args, kwargs)
- # def return_if_netns(self, if_id): # device = self._if_manager.get_mapped_device(if_id) # if device.get_netns() == None:
-- 2.26.3 _______________________________________________ LNST-developers mailing list -- lnst-developers@lists.fedorahosted.org To unsubscribe send an email to lnst-developers-leave@lists.fedorahosted.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/lnst-developers@lists.fedorahos... Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure
lnst-developers@lists.fedorahosted.org