Improved utils.import_site_symbol (and thus its
import_site_class/function users) to not assume that if the site
specific file exists and is not empty then we must be able to find the
symbol in it. Thus we now support site specific files that don't
override all the names from the base one. Still if there are code errors
that make the import fail these will be exposed.
Signed-off-by: Mihai Rusu <dizzy@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@3216 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/common_lib/utils.py b/client/common_lib/utils.py
index 02cbe45..769e9fe 100644
--- a/client/common_lib/utils.py
+++ b/client/common_lib/utils.py
@@ -852,12 +852,22 @@
except os.error:
site_exists = False
+ msg = None
if site_exists:
+ # special unique value to tell us if the symbol can't be imported
+ cant_import = object()
+
# return the object from the imported module
- obj = getattr(__import__(module, {}, {}, [short_module]), name)
+ obj = getattr(__import__(module, {}, {}, [short_module]), name,
+ cant_import)
+ if obj is cant_import:
+ msg = ("unable to import site symbol '%s', using non-site "
+ "implementation") % name
else:
msg = "unable to import site module '%s', using non-site implementation"
msg %= modulefile
+
+ if msg:
logging.info(msg)
obj = dummy