summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
authorJuro Bystricky <juro.bystricky@intel.com>2017-02-06 09:49:37 -0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-02-15 09:29:55 -0800
commitb1f99066bd8ff787c126ed26ab71fa67b30f15d5 (patch)
tree9bee8cfc26015976d2c0732272f74584a14c1324 /meta
parent124f689569c687070c70b73fc9b7eeee4c730208 (diff)
downloadpoky-b1f99066bd8ff787c126ed26ab71fa67b30f15d5.tar.gz
testimage: Implement custom target loading
This patch implements custom target loading for testimage, currently missing due to major changes to the test framework. Custom targets can be defined in various meta-layers, so we need an extra path information in order to find them. Any other additional info is retrieved as usual via the variables TEST_TARGET and TEST_SUITES (From OE-Core rev: 1dc8010afd71fe46fb28bb86fb7c07a5fbd3d7cf) Signed-off-by: Juro Bystricky <juro.bystricky@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r--meta/classes/testimage.bbclass2
-rw-r--r--meta/lib/oeqa/runtime/context.py74
2 files changed, 72 insertions, 4 deletions
diff --git a/meta/classes/testimage.bbclass b/meta/classes/testimage.bbclass
index c6e4cec426..366c6f5d7b 100644
--- a/meta/classes/testimage.bbclass
+++ b/meta/classes/testimage.bbclass
@@ -238,7 +238,7 @@ def testimage_main(d):
238 238
239 # the robot dance 239 # the robot dance
240 target = OERuntimeTestContextExecutor.getTarget( 240 target = OERuntimeTestContextExecutor.getTarget(
241 d.getVar("TEST_TARGET"), None, d.getVar("TEST_TARGET_IP"), 241 d.getVar("TEST_TARGET"), d.getVar("BBPATH"), None, d.getVar("TEST_TARGET_IP"),
242 d.getVar("TEST_SERVER_IP"), **target_kwargs) 242 d.getVar("TEST_SERVER_IP"), **target_kwargs)
243 243
244 # test context 244 # test context
diff --git a/meta/lib/oeqa/runtime/context.py b/meta/lib/oeqa/runtime/context.py
index e5e0141c2a..ea1b4a643e 100644
--- a/meta/lib/oeqa/runtime/context.py
+++ b/meta/lib/oeqa/runtime/context.py
@@ -89,7 +89,7 @@ class OERuntimeTestContextExecutor(OETestContextExecutor):
89 help="Qemu boot configuration, only needed when target_type is QEMU.") 89 help="Qemu boot configuration, only needed when target_type is QEMU.")
90 90
91 @staticmethod 91 @staticmethod
92 def getTarget(target_type, logger, target_ip, server_ip, **kwargs): 92 def getTarget(target_type, target_modules_path, logger, target_ip, server_ip, **kwargs):
93 target = None 93 target = None
94 94
95 if target_type == 'simpleremote': 95 if target_type == 'simpleremote':
@@ -97,11 +97,79 @@ class OERuntimeTestContextExecutor(OETestContextExecutor):
97 elif target_type == 'qemu': 97 elif target_type == 'qemu':
98 target = OEQemuTarget(logger, target_ip, server_ip, **kwargs) 98 target = OEQemuTarget(logger, target_ip, server_ip, **kwargs)
99 else: 99 else:
100 # TODO: Implement custom target module loading 100 # Custom target module loading
101 raise TypeError("target_type %s isn't supported" % target_type) 101 try:
102 controller = OERuntimeTestContextExecutor.getControllerModule(target_type, target_modules_path)
103 target = controller(logger, target_ip, server_ip, **kwargs)
104 except ImportError as e:
105 raise TypeError("Failed to import %s from available controller modules" % target_type)
102 106
103 return target 107 return target
104 108
109 # Search oeqa.controllers module directory for and return a controller
110 # corresponding to the given target name.
111 # AttributeError raised if not found.
112 # ImportError raised if a provided module can not be imported.
113 @staticmethod
114 def getControllerModule(target, target_modules_path):
115 controllerslist = OERuntimeTestContextExecutor._getControllerModulenames(target_modules_path)
116 controller = OERuntimeTestContextExecutor._loadControllerFromName(target, controllerslist)
117 return controller
118
119 # Return a list of all python modules in lib/oeqa/controllers for each
120 # layer in bbpath
121 @staticmethod
122 def _getControllerModulenames(target_modules_path):
123
124 controllerslist = []
125
126 def add_controller_list(path):
127 if not os.path.exists(os.path.join(path, '__init__.py')):
128 raise OSError('Controllers directory %s exists but is missing __init__.py' % path)
129 files = sorted([f for f in os.listdir(path) if f.endswith('.py') and not f.startswith('_')])
130 for f in files:
131 module = 'oeqa.controllers.' + f[:-3]
132 if module not in controllerslist:
133 controllerslist.append(module)
134 else:
135 raise RuntimeError("Duplicate controller module found for %s. Layers should create unique controller module names" % module)
136
137 extpath = target_modules_path.split(':')
138 for p in extpath:
139 controllerpath = os.path.join(p, 'lib', 'oeqa', 'controllers')
140 if os.path.exists(controllerpath):
141 add_controller_list(controllerpath)
142 return controllerslist
143
144 # Search for and return a controller from given target name and
145 # set of module names.
146 # Raise AttributeError if not found.
147 # Raise ImportError if a provided module can not be imported
148 @staticmethod
149 def _loadControllerFromName(target, modulenames):
150 for name in modulenames:
151 obj = OERuntimeTestContextExecutor._loadControllerFromModule(target, name)
152 if obj:
153 return obj
154 raise AttributeError("Unable to load {0} from available modules: {1}".format(target, str(modulenames)))
155
156 # Search for and return a controller or None from given module name
157 @staticmethod
158 def _loadControllerFromModule(target, modulename):
159 obj = None
160 # import module, allowing it to raise import exception
161 try:
162 module = __import__(modulename, globals(), locals(), [target])
163 except Exception as e:
164 return obj
165 # look for target class in the module, catching any exceptions as it
166 # is valid that a module may not have the target class.
167 try:
168 obj = getattr(module, target)
169 except:
170 obj = None
171 return obj
172
105 @staticmethod 173 @staticmethod
106 def readPackagesManifest(manifest): 174 def readPackagesManifest(manifest):
107 if not manifest or not os.path.exists(manifest): 175 if not manifest or not os.path.exists(manifest):