]> code.ossystems Code Review - openembedded-core.git/commitdiff
lib/oeqa: allow a layer to provide it's own TEST_TARGET class
authorStefan Stanacar <stefanx.stanacar@intel.com>
Thu, 16 Jan 2014 12:48:59 +0000 (14:48 +0200)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 16 Jan 2014 23:40:43 +0000 (23:40 +0000)
Allows a layer to define new classes in <layer>/lib/oeqa/utils/controllers.py
and completely control or extend deployment of a target. (core currently
has QemuTarget and SimpleRemoteTarget).
The value of TEST_TARGET must be the name of the new class.

Signed-off-by: Stefan Stanacar <stefanx.stanacar@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/lib/oeqa/targetcontrol.py
meta/lib/oeqa/utils/__init__.py

index dee38ec1d6c1086f0a28035b67f2884e4b877084..757f9d3d5096f44bc1548796882dacf435c0a897 100644 (file)
@@ -8,18 +8,33 @@ import os
 import shutil
 import subprocess
 import bb
-
+import traceback
 from oeqa.utils.sshcontrol import SSHControl
 from oeqa.utils.qemurunner import QemuRunner
 
 
 def get_target_controller(d):
-    if d.getVar("TEST_TARGET", True) == "qemu":
+    testtarget = d.getVar("TEST_TARGET", True)
+    # old, simple names
+    if testtarget == "qemu":
         return QemuTarget(d)
-    elif d.getVar("TEST_TARGET", True) == "simpleremote":
+    elif testtarget == "simpleremote":
         return SimpleRemoteTarget(d)
     else:
-        bb.fatal("Please set a valid TEST_TARGET")
+        # use the class name
+        try:
+            # is it a core class defined here?
+            controller = getattr(__name__, testtarget)
+        except AttributeError:
+            # nope, perhaps a layer defined one
+            try:
+                module = __import__("oeqa.utils.controllers", globals(), locals(), [testtarget])
+                controller = getattr(module, testtarget)
+            except ImportError as e:
+                bb.fatal("Failed to import oeqa.utils.controllers:\n%s" % traceback.format_exc())
+            except AttributeError:
+                bb.fatal("\"%s\" is not a valid value for TEST_TARGET" % testtarget)
+        return controller(d)
 
 
 class BaseTarget(object):
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..8eda92763c5a2052e2332a4368dcaddf473cf806 100644 (file)
@@ -0,0 +1,3 @@
+# Enable other layers to have modules in the same named directory
+from pkgutil import extend_path
+__path__ = extend_path(__path__, __name__)