diff options
Diffstat (limited to 'meta/lib/oeqa/runtime/context.py')
-rw-r--r-- | meta/lib/oeqa/runtime/context.py | 48 |
1 files changed, 19 insertions, 29 deletions
diff --git a/meta/lib/oeqa/runtime/context.py b/meta/lib/oeqa/runtime/context.py index 3826f27642..cb7227a8df 100644 --- a/meta/lib/oeqa/runtime/context.py +++ b/meta/lib/oeqa/runtime/context.py | |||
@@ -5,11 +5,11 @@ | |||
5 | # | 5 | # |
6 | 6 | ||
7 | import os | 7 | import os |
8 | import sys | ||
8 | 9 | ||
9 | from oeqa.core.context import OETestContext, OETestContextExecutor | 10 | from oeqa.core.context import OETestContext, OETestContextExecutor |
10 | from oeqa.core.target.ssh import OESSHTarget | 11 | from oeqa.core.target.ssh import OESSHTarget |
11 | from oeqa.core.target.qemu import OEQemuTarget | 12 | from oeqa.core.target.qemu import OEQemuTarget |
12 | from oeqa.utils.dump import HostDumper | ||
13 | 13 | ||
14 | from oeqa.runtime.loader import OERuntimeTestLoader | 14 | from oeqa.runtime.loader import OERuntimeTestLoader |
15 | 15 | ||
@@ -19,12 +19,11 @@ class OERuntimeTestContext(OETestContext): | |||
19 | os.path.dirname(os.path.abspath(__file__)), "files") | 19 | os.path.dirname(os.path.abspath(__file__)), "files") |
20 | 20 | ||
21 | def __init__(self, td, logger, target, | 21 | def __init__(self, td, logger, target, |
22 | host_dumper, image_packages, extract_dir): | 22 | image_packages, extract_dir): |
23 | super(OERuntimeTestContext, self).__init__(td, logger) | 23 | super(OERuntimeTestContext, self).__init__(td, logger) |
24 | 24 | ||
25 | self.target = target | 25 | self.target = target |
26 | self.image_packages = image_packages | 26 | self.image_packages = image_packages |
27 | self.host_dumper = host_dumper | ||
28 | self.extract_dir = extract_dir | 27 | self.extract_dir = extract_dir |
29 | self._set_target_cmds() | 28 | self._set_target_cmds() |
30 | 29 | ||
@@ -66,11 +65,11 @@ class OERuntimeTestContextExecutor(OETestContextExecutor): | |||
66 | % self.default_target_type) | 65 | % self.default_target_type) |
67 | runtime_group.add_argument('--target-ip', action='store', | 66 | runtime_group.add_argument('--target-ip', action='store', |
68 | default=self.default_target_ip, | 67 | default=self.default_target_ip, |
69 | help="IP address of device under test, default: %s" \ | 68 | 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) | 69 | % self.default_target_ip) |
71 | runtime_group.add_argument('--server-ip', action='store', | 70 | runtime_group.add_argument('--server-ip', action='store', |
72 | default=self.default_target_ip, | 71 | default=self.default_target_ip, |
73 | help="IP address of device under test, default: %s" \ | 72 | help="IP address of the test host from test target machine, default: %s" \ |
74 | % self.default_server_ip) | 73 | % self.default_server_ip) |
75 | 74 | ||
76 | runtime_group.add_argument('--host-dumper-dir', action='store', | 75 | runtime_group.add_argument('--host-dumper-dir', action='store', |
@@ -119,8 +118,7 @@ class OERuntimeTestContextExecutor(OETestContextExecutor): | |||
119 | # XXX: Don't base your targets on this code it will be refactored | 118 | # XXX: Don't base your targets on this code it will be refactored |
120 | # in the near future. | 119 | # in the near future. |
121 | # Custom target module loading | 120 | # Custom target module loading |
122 | target_modules_path = kwargs.get('target_modules_path', '') | 121 | controller = OERuntimeTestContextExecutor.getControllerModule(target_type) |
123 | controller = OERuntimeTestContextExecutor.getControllerModule(target_type, target_modules_path) | ||
124 | target = controller(logger, target_ip, server_ip, **kwargs) | 122 | target = controller(logger, target_ip, server_ip, **kwargs) |
125 | 123 | ||
126 | return target | 124 | return target |
@@ -130,15 +128,15 @@ class OERuntimeTestContextExecutor(OETestContextExecutor): | |||
130 | # AttributeError raised if not found. | 128 | # AttributeError raised if not found. |
131 | # ImportError raised if a provided module can not be imported. | 129 | # ImportError raised if a provided module can not be imported. |
132 | @staticmethod | 130 | @staticmethod |
133 | def getControllerModule(target, target_modules_path): | 131 | def getControllerModule(target): |
134 | controllerslist = OERuntimeTestContextExecutor._getControllerModulenames(target_modules_path) | 132 | controllerslist = OERuntimeTestContextExecutor._getControllerModulenames() |
135 | controller = OERuntimeTestContextExecutor._loadControllerFromName(target, controllerslist) | 133 | controller = OERuntimeTestContextExecutor._loadControllerFromName(target, controllerslist) |
136 | return controller | 134 | return controller |
137 | 135 | ||
138 | # Return a list of all python modules in lib/oeqa/controllers for each | 136 | # Return a list of all python modules in lib/oeqa/controllers for each |
139 | # layer in bbpath | 137 | # layer in bbpath |
140 | @staticmethod | 138 | @staticmethod |
141 | def _getControllerModulenames(target_modules_path): | 139 | def _getControllerModulenames(): |
142 | 140 | ||
143 | controllerslist = [] | 141 | controllerslist = [] |
144 | 142 | ||
@@ -153,9 +151,12 @@ class OERuntimeTestContextExecutor(OETestContextExecutor): | |||
153 | else: | 151 | else: |
154 | raise RuntimeError("Duplicate controller module found for %s. Layers should create unique controller module names" % module) | 152 | raise RuntimeError("Duplicate controller module found for %s. Layers should create unique controller module names" % module) |
155 | 153 | ||
156 | extpath = target_modules_path.split(':') | 154 | # sys.path can contain duplicate paths, but because of the login in |
157 | for p in extpath: | 155 | # add_controller_list this doesn't work and causes testimage to abort. |
158 | controllerpath = os.path.join(p, 'lib', 'oeqa', 'controllers') | 156 | # Remove duplicates using an intermediate dictionary to ensure this |
157 | # doesn't happen. | ||
158 | for p in list(dict.fromkeys(sys.path)): | ||
159 | controllerpath = os.path.join(p, 'oeqa', 'controllers') | ||
159 | if os.path.exists(controllerpath): | 160 | if os.path.exists(controllerpath): |
160 | add_controller_list(controllerpath) | 161 | add_controller_list(controllerpath) |
161 | return controllerslist | 162 | return controllerslist |
@@ -175,16 +176,12 @@ class OERuntimeTestContextExecutor(OETestContextExecutor): | |||
175 | # Search for and return a controller or None from given module name | 176 | # Search for and return a controller or None from given module name |
176 | @staticmethod | 177 | @staticmethod |
177 | def _loadControllerFromModule(target, modulename): | 178 | 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: | 179 | try: |
184 | obj = getattr(module, target) | 180 | import importlib |
185 | except: | 181 | module = importlib.import_module(modulename) |
186 | obj = None | 182 | return getattr(module, target) |
187 | return obj | 183 | except AttributeError: |
184 | return None | ||
188 | 185 | ||
189 | @staticmethod | 186 | @staticmethod |
190 | def readPackagesManifest(manifest): | 187 | def readPackagesManifest(manifest): |
@@ -200,10 +197,6 @@ class OERuntimeTestContextExecutor(OETestContextExecutor): | |||
200 | 197 | ||
201 | return image_packages | 198 | return image_packages |
202 | 199 | ||
203 | @staticmethod | ||
204 | def getHostDumper(cmds, directory): | ||
205 | return HostDumper(cmds, directory) | ||
206 | |||
207 | def _process_args(self, logger, args): | 200 | def _process_args(self, logger, args): |
208 | if not args.packages_manifest: | 201 | if not args.packages_manifest: |
209 | raise TypeError('Manifest file not provided') | 202 | raise TypeError('Manifest file not provided') |
@@ -216,9 +209,6 @@ class OERuntimeTestContextExecutor(OETestContextExecutor): | |||
216 | self.tc_kwargs['init']['target'] = \ | 209 | self.tc_kwargs['init']['target'] = \ |
217 | OERuntimeTestContextExecutor.getTarget(args.target_type, | 210 | OERuntimeTestContextExecutor.getTarget(args.target_type, |
218 | None, args.target_ip, args.server_ip, **target_kwargs) | 211 | 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'] = \ | 212 | self.tc_kwargs['init']['image_packages'] = \ |
223 | OERuntimeTestContextExecutor.readPackagesManifest( | 213 | OERuntimeTestContextExecutor.readPackagesManifest( |
224 | args.packages_manifest) | 214 | args.packages_manifest) |