commit 49b3b7a8b05d5f5a048676eba4814d4b276e88e4
Author: Jan Tluka <jtluka(a)redhat.com>
Date: Wed Jun 11 10:52:45 2014 +0200
Fix module-tool dependency issue during resource synchronization
Version 2 of the patch. The change is that an user does not need to
specify the used tools they're retrieved from python-parsed source of
the test module.
Tested on TCPConnection module, works fine.
Original issue description:
We have currently two test modules that have dependency on a test_tool,
TCPConnection and Multicast which are wrappers around tcp_conn and
multicast test tools.
Reduced synchronization feature introduced a dependency bug. Since the
test module used in an lnst recipe does not have any information about
required test tool such tool will not be synchronized to lnst slave and
will end with an Exception like this:
Exception: CommandException: Tools 'tcp_conn' not found
Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
Signed-off-by: Jiri Pirko <jiri(a)resnulli.us>
lnst/Common/Utils.py | 23 +++++++++++++++++++++++
lnst/Controller/NetTestController.py | 11 ++++++++++-
2 files changed, 33 insertions(+), 1 deletions(-)
---
diff --git a/lnst/Common/Utils.py b/lnst/Common/Utils.py
index 3b00afb..d7dcda3 100644
--- a/lnst/Common/Utils.py
+++ b/lnst/Common/Utils.py
@@ -17,6 +17,8 @@ import hashlib
import tempfile
import subprocess
import errno
+import ast
+from _ast import Call, Attribute
from lnst.Common.ExecCmd import exec_cmd
def die_when_parent_die():
@@ -167,3 +169,24 @@ def mkdir_p(path):
pass
else:
raise
+
+def get_module_tools(module_path):
+ tools = []
+
+ f = open(module_path)
+
+ asttree = ast.parse(f.read())
+
+ for node in ast.walk(asttree):
+ if isinstance (node, Call):
+ fn = getattr(node, 'func')
+ if isinstance(fn, Attribute):
+ val = getattr(fn, 'value')
+ if ('self' == getattr(val, 'id')):
+ if ( 'exec_from' == getattr(fn, 'attr')):
+ tool = getattr((getattr(node, 'args')[0]), 's')
+ tools.append(tool)
+
+ f.close()
+
+ return tools
diff --git a/lnst/Controller/NetTestController.py b/lnst/Controller/NetTestController.py
index 400cd19..527c640 100644
--- a/lnst/Controller/NetTestController.py
+++ b/lnst/Controller/NetTestController.py
@@ -23,7 +23,7 @@ from time import sleep
from xmlrpclib import Binary
from lnst.Common.NetUtils import MacPool
from lnst.Common.Utils import wait_for, md5sum, dir_md5sum, create_tar_archive
-from lnst.Common.Utils import check_process_running, bool_it
+from lnst.Common.Utils import check_process_running, bool_it, get_module_tools
from lnst.Common.NetTestCommand import NetTestCommandContext, NetTestCommand
from lnst.Common.NetTestCommand import str_command, CommandException
from lnst.Controller.RecipeParser import RecipeParser, RecipeError
@@ -242,6 +242,15 @@ class NetTestController:
mod = cmd['module']
if mod in res_table['module']:
sync_table['module'][mod] = res_table['module'][mod]
+ # check if test module uses some test tools
+ mod_path = res_table['module'][mod]["path"]
+ mod_tools = get_module_tools(mod_path)
+ for t in mod_tools:
+ if t in sync_table['tools']:
+ continue
+ logging.debug("Adding '%s' tool as dependency\
+ of %s test module" % (t, mod))
+ sync_table['tools'][t] = res_table['tools'][t]
else:
msg = "Module '%s' not found on the controller"\
% mod