]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
run_tasks.py: allow _import to raise the right ImportError 1238/head
authorNathan Cutler <ncutler@suse.com>
Thu, 22 Nov 2018 11:59:48 +0000 (12:59 +0100)
committerNathan Cutler <ncutler@suse.com>
Fri, 23 Nov 2018 21:26:02 +0000 (22:26 +0100)
It turns out it's possible for a file qa/tasks/foo.py to exist,
yet importing it still raises an ImportError because it references a
non-existent symbol.

In this case, teuthology was clobbering the real ImportError with its
own bogus text.

Fixes: http://tracker.ceph.com/issues/37370
Signed-off-by: Nathan Cutler <ncutler@suse.com>
teuthology/run_tasks.py

index 6dba83300c7e73571c8364875e7528df461f5971..2c364572bbed0ad4e4ce038ea1e091d3b9620ac9 100644 (file)
@@ -23,12 +23,9 @@ def get_task(name):
 
     # First look for the tasks's module inside teuthology
     module = _import('teuthology.task', module_name, task_name)
-    # If it is not found, try ceph-qa-suite (if it is in sys.path)
+    # If it is not found, try qa/ directory (if it is in sys.path)
     if not module:
-        module = _import('tasks', module_name, task_name)
-    # If it is still not found, fail
-    if not module:
-        raise ImportError("Could not find task '{}'".format(name))
+        module = _import('tasks', module_name, task_name, fail_on_import_error=True)
     try:
         # Attempt to locate the task object inside the module
         task = getattr(module, task_name)
@@ -44,7 +41,7 @@ def get_task(name):
     return task
 
 
-def _import(from_package, module_name, task_name):
+def _import(from_package, module_name, task_name, fail_on_import_error=False):
     full_module_name = '.'.join([from_package, module_name])
     try:
         module = __import__(
@@ -55,7 +52,10 @@ def _import(from_package, module_name, task_name):
             0,
         )
     except ImportError:
-        return None
+        if fail_on_import_error:
+            raise
+        else:
+            return None
     return module