commit 29c00b9c4dcd31337bd1c8d1e1bf62f9a3271684
Author: Jan Tluka <jtluka(a)redhat.com>
Date: Mon Sep 22 17:01:09 2014 +0200
Controller: add python task path to syspath
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>
Signed-off-by: Jiri Pirko <jiri(a)resnulli.us>
lnst/Controller/NetTestController.py | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
---
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
Show replies by date