From: Ondrej Lichtner <olichtne(a)redhat.com>
Method calls should be passing Namespace objects instead of their names.
Except for the final rpc_call to the slave where the objects don't
exist.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Controller/Job.py | 2 +-
lnst/Controller/Machine.py | 10 +++++-----
lnst/Controller/Namespace.py | 5 ++---
lnst/Devices/RemoteDevice.py | 6 +++---
4 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/lnst/Controller/Job.py b/lnst/Controller/Job.py
index 1ed079f..6cd4a15 100644
--- a/lnst/Controller/Job.py
+++ b/lnst/Controller/Job.py
@@ -189,7 +189,7 @@ class Job(object):
attrs.append("command(%s)" % self._what)
if self._netns is not None:
- attrs.append("netns(%s)" % self._netns)
+ attrs.append("netns(%s)" % self._netns.name)
if not self._expect:
attrs.append("expecting FAIL")
diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py
index 67907be..f51798c 100644
--- a/lnst/Controller/Machine.py
+++ b/lnst/Controller/Machine.py
@@ -126,7 +126,7 @@ class Machine(object):
self._device_database[ret["ifindex"]] = dev
def remote_device_set_netns(self, dev, dst, src):
- self.rpc_call("set_dev_netns", dev, dst, netns=src)
+ self.rpc_call("set_dev_netns", dev, dst.name, netns=src)
def device_created(self, dev_data):
ifindex = dev_data["ifindex"]
@@ -175,11 +175,11 @@ class Machine(object):
return None
def rpc_call(self, method_name, *args, **kwargs):
- if "netns" in kwargs and kwargs["netns"] is not None:
+ if kwargs.get("netns") in self._namespaces:
netns = kwargs["netns"]
del kwargs["netns"]
msg = {"type": "to_netns",
- "netns": netns,
+ "netns": netns.name,
"data": {"type": "command",
"method_name": method_name,
"args": args,
@@ -366,7 +366,7 @@ class Machine(object):
if job._desc is not None:
logging.info("Job description: %s" % job._desc)
- res = self.rpc_call("run_job", job._to_dict(), netns=job.netns.name)
+ res = self.rpc_call("run_job", job._to_dict(), netns=job.netns)
self._recipe.current_run.add_result(JobStartResult(job, res))
return res
@@ -436,7 +436,7 @@ class Machine(object):
if job.id not in self._jobs:
raise MachineError("No job '%s' running on Machine %s" %
(job.id(), self._id))
- return self.rpc_call("kill_job", job.id, signal, netns=job.netns.name)
+ return self.rpc_call("kill_job", job.id, signal, netns=job.netns)
def get_hostname(self):
""" Get hostname/ip of the machine
diff --git a/lnst/Controller/Namespace.py b/lnst/Controller/Namespace.py
index 6b81d44..16458a0 100644
--- a/lnst/Controller/Namespace.py
+++ b/lnst/Controller/Namespace.py
@@ -146,8 +146,7 @@ class Namespace(object):
if value.ifindex is not None:
old_ns = value.netns
old_ns._unset(value)
- self._machine.remote_device_set_netns(value, self.name,
- old_ns.name)
+ self._machine.remote_device_set_netns(value, self, old_ns)
value.netns = self
self._objects[name] = value
return True
@@ -170,7 +169,7 @@ class Namespace(object):
else:
value._machine = self._machine
value.netns = self
- self._machine.remote_device_create(value, netns=self.name)
+ self._machine.remote_device_create(value, netns=self)
self._objects[name] = value
return True
diff --git a/lnst/Devices/RemoteDevice.py b/lnst/Devices/RemoteDevice.py
index 6e51977..ddd47f1 100644
--- a/lnst/Devices/RemoteDevice.py
+++ b/lnst/Devices/RemoteDevice.py
@@ -92,11 +92,11 @@ class RemoteDevice(object):
def dev_method(*args, **kwargs):
return self._machine.rpc_call("dev_method", self.ifindex,
name, args, kwargs,
- netns=self.netns.name)
+ netns=self.netns)
return dev_method
else:
return self._machine.rpc_call("dev_attr", self.ifindex, name,
- netns=self.netns.name)
+ netns=self.netns)
def __setattr__(self, name, value):
if not self._inited:
@@ -105,7 +105,7 @@ class RemoteDevice(object):
try:
getattr(self._dev_cls, name)
return self._machine.rpc_call("dev_set_attr", self.ifindex, name,
value,
- netns=self.netns.name)
+ netns=self.netns)
except AttributeError:
return super(RemoteDevice, self).__setattr__(name, value)
--
2.17.0