utils: make module import safer 55/35755/1
authorRoss Brattain <ross.b.brattain@intel.com>
Mon, 22 May 2017 04:08:49 +0000 (21:08 -0700)
committerRoss Brattain <ross.b.brattain@intel.com>
Fri, 2 Jun 2017 23:06:40 +0000 (16:06 -0700)
If a module fails to import, then ignore it
and try the next module.

This can help if certain module depenencies
aren't installed, e.g. TREX.

Change-Id: I2bc4384429fabd61cd430817489cb2f3c86fe9b2
Signed-off-by: Ross Brattain <ross.b.brattain@intel.com>
yardstick/common/utils.py

index f4def85..7aab469 100644 (file)
@@ -81,7 +81,10 @@ def import_modules_from_package(package):
                 continue
             new_package = ".".join(root.split(os.sep)).split("....")[1]
             module_name = "%s.%s" % (new_package, filename[:-3])
-            try_append_module(module_name, sys.modules)
+            try:
+                try_append_module(module_name, sys.modules)
+            except ImportError:
+                logger.exception("unable to import %s", module_name)
 
 
 def parse_yaml(file_path):