summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/runtime/context.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/runtime/context.py')
-rw-r--r--meta/lib/oeqa/runtime/context.py60
1 files changed, 30 insertions, 30 deletions
diff --git a/meta/lib/oeqa/runtime/context.py b/meta/lib/oeqa/runtime/context.py
index 3826f27642..daabc44910 100644
--- a/meta/lib/oeqa/runtime/context.py
+++ b/meta/lib/oeqa/runtime/context.py
@@ -5,11 +5,12 @@
5# 5#
6 6
7import os 7import os
8import sys
8 9
9from oeqa.core.context import OETestContext, OETestContextExecutor 10from oeqa.core.context import OETestContext, OETestContextExecutor
11from oeqa.core.target.serial import OESerialTarget
10from oeqa.core.target.ssh import OESSHTarget 12from oeqa.core.target.ssh import OESSHTarget
11from oeqa.core.target.qemu import OEQemuTarget 13from oeqa.core.target.qemu import OEQemuTarget
12from oeqa.utils.dump import HostDumper
13 14
14from oeqa.runtime.loader import OERuntimeTestLoader 15from oeqa.runtime.loader import OERuntimeTestLoader
15 16
@@ -19,12 +20,11 @@ class OERuntimeTestContext(OETestContext):
19 os.path.dirname(os.path.abspath(__file__)), "files") 20 os.path.dirname(os.path.abspath(__file__)), "files")
20 21
21 def __init__(self, td, logger, target, 22 def __init__(self, td, logger, target,
22 host_dumper, image_packages, extract_dir): 23 image_packages, extract_dir):
23 super(OERuntimeTestContext, self).__init__(td, logger) 24 super(OERuntimeTestContext, self).__init__(td, logger)
24 25
25 self.target = target 26 self.target = target
26 self.image_packages = image_packages 27 self.image_packages = image_packages
27 self.host_dumper = host_dumper
28 self.extract_dir = extract_dir 28 self.extract_dir = extract_dir
29 self._set_target_cmds() 29 self._set_target_cmds()
30 30
@@ -61,16 +61,16 @@ class OERuntimeTestContextExecutor(OETestContextExecutor):
61 runtime_group = self.parser.add_argument_group('runtime options') 61 runtime_group = self.parser.add_argument_group('runtime options')
62 62
63 runtime_group.add_argument('--target-type', action='store', 63 runtime_group.add_argument('--target-type', action='store',
64 default=self.default_target_type, choices=['simpleremote', 'qemu'], 64 default=self.default_target_type, choices=['simpleremote', 'qemu', 'serial'],
65 help="Target type of device under test, default: %s" \ 65 help="Target type of device under test, default: %s" \
66 % self.default_target_type) 66 % self.default_target_type)
67 runtime_group.add_argument('--target-ip', action='store', 67 runtime_group.add_argument('--target-ip', action='store',
68 default=self.default_target_ip, 68 default=self.default_target_ip,
69 help="IP address of device under test, default: %s" \ 69 help="IP address and optionally ssh port (default 22) of device under test, for example '192.168.0.7:22'. Default: %s" \
70 % self.default_target_ip) 70 % self.default_target_ip)
71 runtime_group.add_argument('--server-ip', action='store', 71 runtime_group.add_argument('--server-ip', action='store',
72 default=self.default_target_ip, 72 default=self.default_target_ip,
73 help="IP address of device under test, default: %s" \ 73 help="IP address of the test host from test target machine, default: %s" \
74 % self.default_server_ip) 74 % self.default_server_ip)
75 75
76 runtime_group.add_argument('--host-dumper-dir', action='store', 76 runtime_group.add_argument('--host-dumper-dir', action='store',
@@ -109,6 +109,8 @@ class OERuntimeTestContextExecutor(OETestContextExecutor):
109 target = OESSHTarget(logger, target_ip, server_ip, **kwargs) 109 target = OESSHTarget(logger, target_ip, server_ip, **kwargs)
110 elif target_type == 'qemu': 110 elif target_type == 'qemu':
111 target = OEQemuTarget(logger, server_ip, **kwargs) 111 target = OEQemuTarget(logger, server_ip, **kwargs)
112 elif target_type == 'serial':
113 target = OESerialTarget(logger, target_ip, server_ip, **kwargs)
112 else: 114 else:
113 # XXX: This code uses the old naming convention for controllers and 115 # XXX: This code uses the old naming convention for controllers and
114 # targets, the idea it is to leave just targets as the controller 116 # targets, the idea it is to leave just targets as the controller
@@ -119,8 +121,7 @@ class OERuntimeTestContextExecutor(OETestContextExecutor):
119 # XXX: Don't base your targets on this code it will be refactored 121 # XXX: Don't base your targets on this code it will be refactored
120 # in the near future. 122 # in the near future.
121 # Custom target module loading 123 # Custom target module loading
122 target_modules_path = kwargs.get('target_modules_path', '') 124 controller = OERuntimeTestContextExecutor.getControllerModule(target_type)
123 controller = OERuntimeTestContextExecutor.getControllerModule(target_type, target_modules_path)
124 target = controller(logger, target_ip, server_ip, **kwargs) 125 target = controller(logger, target_ip, server_ip, **kwargs)
125 126
126 return target 127 return target
@@ -130,15 +131,15 @@ class OERuntimeTestContextExecutor(OETestContextExecutor):
130 # AttributeError raised if not found. 131 # AttributeError raised if not found.
131 # ImportError raised if a provided module can not be imported. 132 # ImportError raised if a provided module can not be imported.
132 @staticmethod 133 @staticmethod
133 def getControllerModule(target, target_modules_path): 134 def getControllerModule(target):
134 controllerslist = OERuntimeTestContextExecutor._getControllerModulenames(target_modules_path) 135 controllerslist = OERuntimeTestContextExecutor._getControllerModulenames()
135 controller = OERuntimeTestContextExecutor._loadControllerFromName(target, controllerslist) 136 controller = OERuntimeTestContextExecutor._loadControllerFromName(target, controllerslist)
136 return controller 137 return controller
137 138
138 # Return a list of all python modules in lib/oeqa/controllers for each 139 # Return a list of all python modules in lib/oeqa/controllers for each
139 # layer in bbpath 140 # layer in bbpath
140 @staticmethod 141 @staticmethod
141 def _getControllerModulenames(target_modules_path): 142 def _getControllerModulenames():
142 143
143 controllerslist = [] 144 controllerslist = []
144 145
@@ -153,9 +154,12 @@ class OERuntimeTestContextExecutor(OETestContextExecutor):
153 else: 154 else:
154 raise RuntimeError("Duplicate controller module found for %s. Layers should create unique controller module names" % module) 155 raise RuntimeError("Duplicate controller module found for %s. Layers should create unique controller module names" % module)
155 156
156 extpath = target_modules_path.split(':') 157 # sys.path can contain duplicate paths, but because of the login in
157 for p in extpath: 158 # add_controller_list this doesn't work and causes testimage to abort.
158 controllerpath = os.path.join(p, 'lib', 'oeqa', 'controllers') 159 # Remove duplicates using an intermediate dictionary to ensure this
160 # doesn't happen.
161 for p in list(dict.fromkeys(sys.path)):
162 controllerpath = os.path.join(p, 'oeqa', 'controllers')
159 if os.path.exists(controllerpath): 163 if os.path.exists(controllerpath):
160 add_controller_list(controllerpath) 164 add_controller_list(controllerpath)
161 return controllerslist 165 return controllerslist
@@ -175,16 +179,12 @@ class OERuntimeTestContextExecutor(OETestContextExecutor):
175 # Search for and return a controller or None from given module name 179 # Search for and return a controller or None from given module name
176 @staticmethod 180 @staticmethod
177 def _loadControllerFromModule(target, modulename): 181 def _loadControllerFromModule(target, modulename):
178 obj = None
179 # import module, allowing it to raise import exception
180 module = __import__(modulename, globals(), locals(), [target])
181 # look for target class in the module, catching any exceptions as it
182 # is valid that a module may not have the target class.
183 try: 182 try:
184 obj = getattr(module, target) 183 import importlib
185 except: 184 module = importlib.import_module(modulename)
186 obj = None 185 return getattr(module, target)
187 return obj 186 except AttributeError:
187 return None
188 188
189 @staticmethod 189 @staticmethod
190 def readPackagesManifest(manifest): 190 def readPackagesManifest(manifest):
@@ -200,25 +200,25 @@ class OERuntimeTestContextExecutor(OETestContextExecutor):
200 200
201 return image_packages 201 return image_packages
202 202
203 @staticmethod
204 def getHostDumper(cmds, directory):
205 return HostDumper(cmds, directory)
206
207 def _process_args(self, logger, args): 203 def _process_args(self, logger, args):
208 if not args.packages_manifest: 204 if not args.packages_manifest:
209 raise TypeError('Manifest file not provided') 205 raise TypeError('Manifest file not provided')
210 206
211 super(OERuntimeTestContextExecutor, self)._process_args(logger, args) 207 super(OERuntimeTestContextExecutor, self)._process_args(logger, args)
212 208
209 td = self.tc_kwargs['init']['td']
210
213 target_kwargs = {} 211 target_kwargs = {}
212 target_kwargs['machine'] = td.get("MACHINE") or None
214 target_kwargs['qemuboot'] = args.qemu_boot 213 target_kwargs['qemuboot'] = args.qemu_boot
214 target_kwargs['serialcontrol_cmd'] = td.get("TEST_SERIALCONTROL_CMD") or None
215 target_kwargs['serialcontrol_extra_args'] = td.get("TEST_SERIALCONTROL_EXTRA_ARGS") or ""
216 target_kwargs['serialcontrol_ps1'] = td.get("TEST_SERIALCONTROL_PS1") or None
217 target_kwargs['serialcontrol_connect_timeout'] = td.get("TEST_SERIALCONTROL_CONNECT_TIMEOUT") or None
215 218
216 self.tc_kwargs['init']['target'] = \ 219 self.tc_kwargs['init']['target'] = \
217 OERuntimeTestContextExecutor.getTarget(args.target_type, 220 OERuntimeTestContextExecutor.getTarget(args.target_type,
218 None, args.target_ip, args.server_ip, **target_kwargs) 221 None, args.target_ip, args.server_ip, **target_kwargs)
219 self.tc_kwargs['init']['host_dumper'] = \
220 OERuntimeTestContextExecutor.getHostDumper(None,
221 args.host_dumper_dir)
222 self.tc_kwargs['init']['image_packages'] = \ 222 self.tc_kwargs['init']['image_packages'] = \
223 OERuntimeTestContextExecutor.readPackagesManifest( 223 OERuntimeTestContextExecutor.readPackagesManifest(
224 args.packages_manifest) 224 args.packages_manifest)