If a task python is ran and it has some dependency on a module
located
in the same directory as the task then the run will fail because the
PYTHONPATH does not contain the task directory.
The patch appends the task directory to the system path variable before
loading python task code and removes it from it afterwards.
An example:
$ ls ~/my_recipes
task.py
ciphers.py
$ cat ~/my_recipes/task.py
from lnst.Controller.Task import ctl
import ciphers
...
$ lnst-ctl run ~/my_recipes/task.py
...
File "/root/lnst/lnst/Controller/NetTestController.py", line 664, in
_run_python_task
module = imp.load_source(name, task_path.resolve())
File "/root/testplans/my_recipes/task.py", line 21, in <module>
import ciphers
ImportError: No module named ciphers
Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
---
lnst/Controller/NetTestController.py | 3 +++
1 file changed, 3 insertions(+)
diff --git a/lnst/Controller/NetTestController.py b/lnst/Controller/NetTestController.py
index 04c67da..2830682 100644
--- a/lnst/Controller/NetTestController.py
+++ b/lnst/Controller/NetTestController.py
@@ -19,6 +19,7 @@ import cPickle
import tempfile
import imp
import copy
+import sys
from time import sleep
from xmlrpclib import Binary
from lnst.Common.NetUtils import MacPool
@@ -661,7 +662,9 @@ class NetTestController:
task_path = task["python"]
name = os.path.basename(task_path.abs_path()).split(".")[0]
+ sys.path.append(os.path.dirname(task_path.resolve()))
module = imp.load_source(name, task_path.resolve())
+ sys.path.remove(os.path.dirname(task_path.resolve()))
#restore resource table
self._resource_table = res_table_bkp
--
1.9.3
_______________________________________________
LNST-developers mailing list
LNST-developers(a)lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/lnst-developers