]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
run_tasks: Do not mask missing task dependencies
authorZack Cerza <zack@redhat.com>
Fri, 1 Apr 2022 15:14:42 +0000 (11:14 -0400)
committerZack Cerza <zack@redhat.com>
Tue, 19 Apr 2022 21:31:07 +0000 (15:31 -0600)
While doing packaging work, I noticed that teuthology began claiming it
couldn't find the 'tests' task. After some slightly painful debugging I
realized the issue was that the task was trying to import pytest, which
wasn't installed. The ModuleNotFoundError that was being raised was
being confused with the exception that would be raised if the task
couldn't be found at all. With this change, we see the root cause.

Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/run_tasks.py

index 602559f7fb2c75e37a711e8e784ed85ca1ab02ea..598947c80761bb17a3e62ec3649227b6740cc0db 100644 (file)
@@ -1,3 +1,4 @@
+import importlib
 import jinja2
 import logging
 import os
@@ -60,6 +61,17 @@ def _import(from_package, module_name, task_name, fail_on_import_error=False):
         if fail_on_import_error:
             raise
         else:
+            if (
+                importlib.util.find_spec(from_package) is not None and
+                importlib.util.find_spec(full_module_name) is not None
+            ):
+                # If we get here, it means we could _find_ both the module and
+                # the package that contains it, but still got an ImportError.
+                # Typically that means the module failed to import because it
+                # could not find one of its dependencies; if we don't raise
+                # here it will look like we just could't find the module,
+                # making the dependency issue difficult to discover.
+                raise
             return None
     return module