diff options
Diffstat (limited to 'meta/lib/oeqa')
-rw-r--r-- | meta/lib/oeqa/controllers/__init__.py | 3 | ||||
-rw-r--r-- | meta/lib/oeqa/controllers/testtargetloader.py | 69 | ||||
-rw-r--r-- | meta/lib/oeqa/targetcontrol.py | 13 |
3 files changed, 79 insertions, 6 deletions
diff --git a/meta/lib/oeqa/controllers/__init__.py b/meta/lib/oeqa/controllers/__init__.py new file mode 100644 index 0000000000..8eda92763c --- /dev/null +++ b/meta/lib/oeqa/controllers/__init__.py | |||
@@ -0,0 +1,3 @@ | |||
1 | # Enable other layers to have modules in the same named directory | ||
2 | from pkgutil import extend_path | ||
3 | __path__ = extend_path(__path__, __name__) | ||
diff --git a/meta/lib/oeqa/controllers/testtargetloader.py b/meta/lib/oeqa/controllers/testtargetloader.py new file mode 100644 index 0000000000..019bbfd840 --- /dev/null +++ b/meta/lib/oeqa/controllers/testtargetloader.py | |||
@@ -0,0 +1,69 @@ | |||
1 | import types | ||
2 | import bb | ||
3 | |||
4 | # This class is responsible for loading a test target controller | ||
5 | class TestTargetLoader: | ||
6 | |||
7 | # Search oeqa.controllers module directory for and return a controller | ||
8 | # corresponding to the given target name. | ||
9 | # AttributeError raised if not found. | ||
10 | # ImportError raised if a provided module can not be imported. | ||
11 | def get_controller_module(self, target, bbpath): | ||
12 | controllerslist = self.get_controller_modulenames(bbpath) | ||
13 | bb.note("Available controller modules: %s" % str(controllerslist)) | ||
14 | controller = self.load_controller_from_name(target, controllerslist) | ||
15 | return controller | ||
16 | |||
17 | # Return a list of all python modules in lib/oeqa/controllers for each | ||
18 | # layer in bbpath | ||
19 | def get_controller_modulenames(self, bbpath): | ||
20 | |||
21 | controllerslist = [] | ||
22 | |||
23 | def add_controller_list(path): | ||
24 | if not os.path.exists(os.path.join(path, '__init__.py')): | ||
25 | bb.fatal('Controllers directory %s exists but is missing __init__.py' % path) | ||
26 | files = sorted([f for f in os.listdir(path) if f.endswith('.py') and not f.startswith('_')]) | ||
27 | for f in files: | ||
28 | module = 'oeqa.controllers.' + f[:-3] | ||
29 | if module not in controllerslist: | ||
30 | controllerslist.append(module) | ||
31 | else: | ||
32 | bb.warn("Duplicate controller module found for %s, only one added. Layers should create unique controller module names" % module) | ||
33 | |||
34 | for p in bbpath: | ||
35 | controllerpath = os.path.join(p, 'lib', 'oeqa', 'controllers') | ||
36 | bb.debug(2, 'Searching for target controllers in %s' % controllerpath) | ||
37 | if os.path.exists(controllerpath): | ||
38 | add_controller_list(controllerpath) | ||
39 | return controllerslist | ||
40 | |||
41 | # Search for and return a controller from given target name and | ||
42 | # set of module names. | ||
43 | # Raise AttributeError if not found. | ||
44 | # Raise ImportError if a provided module can not be imported | ||
45 | def load_controller_from_name(self, target, modulenames): | ||
46 | for name in modulenames: | ||
47 | obj = self.load_controller_from_module(target, name) | ||
48 | if obj: | ||
49 | return obj | ||
50 | raise AttributeError("Unable to load {0} from available modules: {1}".format(target, str(modulenames))) | ||
51 | |||
52 | # Search for and return a controller or None from given module name | ||
53 | def load_controller_from_module(self, target, modulename): | ||
54 | obj = None | ||
55 | # import module, allowing it to raise import exception | ||
56 | module = __import__(modulename, globals(), locals(), [target]) | ||
57 | # look for target class in the module, catching any exceptions as it | ||
58 | # is valid that a module may not have the target class. | ||
59 | try: | ||
60 | obj = getattr(module, target) | ||
61 | if obj: | ||
62 | from oeqa.targetcontrol import BaseTarget | ||
63 | if (not isinstance(obj, (type, types.ClassType))): | ||
64 | bb.warn("Target {0} found, but not of type Class".format(target)) | ||
65 | if( not issubclass(obj, BaseTarget)): | ||
66 | bb.warn("Target {0} found, but subclass is not BaseTarget".format(target)) | ||
67 | except: | ||
68 | obj = None | ||
69 | return obj | ||
diff --git a/meta/lib/oeqa/targetcontrol.py b/meta/lib/oeqa/targetcontrol.py index 757f9d3d50..ba5e6e5dc1 100644 --- a/meta/lib/oeqa/targetcontrol.py +++ b/meta/lib/oeqa/targetcontrol.py | |||
@@ -11,7 +11,7 @@ import bb | |||
11 | import traceback | 11 | import traceback |
12 | from oeqa.utils.sshcontrol import SSHControl | 12 | from oeqa.utils.sshcontrol import SSHControl |
13 | from oeqa.utils.qemurunner import QemuRunner | 13 | from oeqa.utils.qemurunner import QemuRunner |
14 | 14 | from oeqa.controllers.testtargetloader import TestTargetLoader | |
15 | 15 | ||
16 | def get_target_controller(d): | 16 | def get_target_controller(d): |
17 | testtarget = d.getVar("TEST_TARGET", True) | 17 | testtarget = d.getVar("TEST_TARGET", True) |
@@ -28,12 +28,13 @@ def get_target_controller(d): | |||
28 | except AttributeError: | 28 | except AttributeError: |
29 | # nope, perhaps a layer defined one | 29 | # nope, perhaps a layer defined one |
30 | try: | 30 | try: |
31 | module = __import__("oeqa.utils.controllers", globals(), locals(), [testtarget]) | 31 | bbpath = d.getVar("BBPATH", True).split(':') |
32 | controller = getattr(module, testtarget) | 32 | testtargetloader = TestTargetLoader() |
33 | controller = testtargetloader.get_controller_module(testtarget, bbpath) | ||
33 | except ImportError as e: | 34 | except ImportError as e: |
34 | bb.fatal("Failed to import oeqa.utils.controllers:\n%s" % traceback.format_exc()) | 35 | bb.fatal("Failed to import {0} from available controller modules:\n{1}".format(testtarget,traceback.format_exc())) |
35 | except AttributeError: | 36 | except AttributeError as e: |
36 | bb.fatal("\"%s\" is not a valid value for TEST_TARGET" % testtarget) | 37 | bb.fatal("Invalid TEST_TARGET - " + str(e)) |
37 | return controller(d) | 38 | return controller(d) |
38 | 39 | ||
39 | 40 | ||