On Mon, Apr 19, 2021 at 02:47:41PM +0200, Jan Tluka wrote:
To use the test modules in network namespaces, the test module
synchronization must be network namespace aware.
This patch extends the send_class() and sync_resource() methods with netns
argument to specify to which network namespace the module should be sent.
The patch also includes additional fix for the run_job() method. The
problem is that this method is called with an instance of a test module
as argument, this instance is pickled and sent to the slave where it's
unpickled. If the test module is sent to a network namespace the
ConnectionHandler in the initial namespace attempts to unpickle the message
which fails with ModuleNotFound error. This is because the test module
has been synchronized only for the network namespace. To fix this,
additional send_class call must be done for the initial namespace.
Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
---
lnst/Controller/Machine.py | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py
index ec0b1e6e..c0a4d8ef 100644
--- a/lnst/Controller/Machine.py
+++ b/lnst/Controller/Machine.py
@@ -324,7 +324,7 @@ class Machine(object):
module_name = cls.__module__
self.rpc_call("map_device_class", cls_name, module_name)
- def send_class(self, cls):
+ def send_class(self, cls, netns=None):
classes = [cls]
classes.extend(self._get_base_classes(cls))
@@ -340,8 +340,8 @@ class Machine(object):
if filename[-3:] == "pyc":
filename = filename[:-1]
- res_hash = self.sync_resource(module_name, filename)
- self.rpc_call("load_cached_module", module_name, res_hash)
+ res_hash = self.sync_resource(module_name, filename, netns=netns)
+ self.rpc_call("load_cached_module", module_name, res_hash,
netns=netns)
def is_git_version(self, version):
try:
@@ -401,7 +401,11 @@ class Machine(object):
self._jobs[job.id] = job
if job.type == "module":
- self.send_class(job._what.__class__)
+ # we need to send the class also into the root net namespace
+ # so that the Slave instance can unpickle the message
+ if job.netns is not None:
+ self.send_class(job._what.__class__, netns=None)
+ self.send_class(job._what.__class__, netns=job.netns)
logging.debug("Host %s executing job %d: %s" %
(self._id, job.id, str(job)))
@@ -551,18 +555,18 @@ class Machine(object):
local_file.close()
self.rpc_call("finish_copy_from", remote_path)
- def sync_resource(self, res_name, file_path):
+ def sync_resource(self, res_name, file_path, netns=None):
digest = sha256sum(file_path)
- if not self.rpc_call("has_resource", digest):
+ if not self.rpc_call("has_resource", digest, netns=netns):
msg = "Transfering %s to machine %s as '%s'" %
(file_path,
self.get_id(),
res_name)
logging.debug(msg)
- remote_path = self.copy_file_to_machine(file_path)
+ remote_path = self.copy_file_to_machine(file_path, netns=netns)
self.rpc_call("add_resource_to_cache",
- "file", remote_path, res_name)
+ "file", remote_path, res_name, netns=netns)
return digest
def init_remote_class(self, cls, *args, **kwargs):
@@ -598,4 +602,4 @@ class Machine(object):
state['_msg_dispatcher'] = None
if self.get_libvirt_domain():
state['_domain_ctl'] = None
- return state
\ No newline at end of file
+ return state
the two actual lines are identical so I assume this fixes the "no
newline" issue for this file? I'm always a little confused about how
this works for diffs...
-Ondrej
--
2.26.3
_______________________________________________
LNST-developers mailing list -- lnst-developers(a)lists.fedorahosted.org
To unsubscribe send an email to lnst-developers-leave(a)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.fedora...
Do not reply to spam on the list, report it:
https://pagure.io/fedora-infrastructure