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.py81
1 files changed, 36 insertions, 45 deletions
diff --git a/meta/lib/oeqa/runtime/context.py b/meta/lib/oeqa/runtime/context.py
index 0294003fc7..cb7227a8df 100644
--- a/meta/lib/oeqa/runtime/context.py
+++ b/meta/lib/oeqa/runtime/context.py
@@ -1,12 +1,15 @@
+#
# Copyright (C) 2016 Intel Corporation
-# Released under the MIT license (see COPYING.MIT)
+#
+# SPDX-License-Identifier: MIT
+#
import os
+import sys
from oeqa.core.context import OETestContext, OETestContextExecutor
from oeqa.core.target.ssh import OESSHTarget
from oeqa.core.target.qemu import OEQemuTarget
-from oeqa.utils.dump import HostDumper
from oeqa.runtime.loader import OERuntimeTestLoader
@@ -16,12 +19,11 @@ class OERuntimeTestContext(OETestContext):
os.path.dirname(os.path.abspath(__file__)), "files")
def __init__(self, td, logger, target,
- host_dumper, image_packages, extract_dir):
+ image_packages, extract_dir):
super(OERuntimeTestContext, self).__init__(td, logger)
self.target = target
self.image_packages = image_packages
- self.host_dumper = host_dumper
self.extract_dir = extract_dir
self._set_target_cmds()
@@ -44,12 +46,12 @@ class OERuntimeTestContextExecutor(OETestContextExecutor):
default_data = None
default_test_data = 'data/testdata.json'
default_tests = ''
+ default_json_result_dir = '%s-results' % name
default_target_type = 'simpleremote'
default_manifest = 'data/manifest'
default_server_ip = '192.168.7.1'
default_target_ip = '192.168.7.2'
- default_host_dumper_dir = '/tmp/oe-saved-tests'
default_extract_dir = 'packages/extracted'
def register_commands(self, logger, subparsers):
@@ -63,21 +65,19 @@ class OERuntimeTestContextExecutor(OETestContextExecutor):
% self.default_target_type)
runtime_group.add_argument('--target-ip', action='store',
default=self.default_target_ip,
- help="IP address of device under test, default: %s" \
+ help="IP address and optionally ssh port (default 22) of device under test, for example '192.168.0.7:22'. Default: %s" \
% self.default_target_ip)
runtime_group.add_argument('--server-ip', action='store',
default=self.default_target_ip,
- help="IP address of device under test, default: %s" \
+ help="IP address of the test host from test target machine, default: %s" \
% self.default_server_ip)
runtime_group.add_argument('--host-dumper-dir', action='store',
- default=self.default_host_dumper_dir,
- help="Directory where host status is dumped, if tests fails, default: %s" \
- % self.default_host_dumper_dir)
+ help="Directory where host status is dumped, if tests fails")
runtime_group.add_argument('--packages-manifest', action='store',
default=self.default_manifest,
- help="Package manifest of the image under testi, default: %s" \
+ help="Package manifest of the image under test, default: %s" \
% self.default_manifest)
runtime_group.add_argument('--extract-dir', action='store',
@@ -98,10 +98,16 @@ class OERuntimeTestContextExecutor(OETestContextExecutor):
target_ip = target_ip_port[0]
kwargs['port'] = target_ip_port[1]
+ if server_ip:
+ server_ip_port = server_ip.split(':')
+ if len(server_ip_port) == 2:
+ server_ip = server_ip_port[0]
+ kwargs['server_port'] = int(server_ip_port[1])
+
if target_type == 'simpleremote':
target = OESSHTarget(logger, target_ip, server_ip, **kwargs)
elif target_type == 'qemu':
- target = OEQemuTarget(logger, target_ip, server_ip, **kwargs)
+ target = OEQemuTarget(logger, server_ip, **kwargs)
else:
# XXX: This code uses the old naming convention for controllers and
# targets, the idea it is to leave just targets as the controller
@@ -112,12 +118,8 @@ class OERuntimeTestContextExecutor(OETestContextExecutor):
# XXX: Don't base your targets on this code it will be refactored
# in the near future.
# Custom target module loading
- try:
- target_modules_path = kwargs.get('target_modules_path', '')
- controller = OERuntimeTestContextExecutor.getControllerModule(target_type, target_modules_path)
- target = controller(logger, target_ip, server_ip, **kwargs)
- except ImportError as e:
- raise TypeError("Failed to import %s from available controller modules" % target_type)
+ controller = OERuntimeTestContextExecutor.getControllerModule(target_type)
+ target = controller(logger, target_ip, server_ip, **kwargs)
return target
@@ -126,22 +128,22 @@ class OERuntimeTestContextExecutor(OETestContextExecutor):
# AttributeError raised if not found.
# ImportError raised if a provided module can not be imported.
@staticmethod
- def getControllerModule(target, target_modules_path):
- controllerslist = OERuntimeTestContextExecutor._getControllerModulenames(target_modules_path)
+ def getControllerModule(target):
+ controllerslist = OERuntimeTestContextExecutor._getControllerModulenames()
controller = OERuntimeTestContextExecutor._loadControllerFromName(target, controllerslist)
return controller
# Return a list of all python modules in lib/oeqa/controllers for each
# layer in bbpath
@staticmethod
- def _getControllerModulenames(target_modules_path):
+ def _getControllerModulenames():
controllerslist = []
def add_controller_list(path):
if not os.path.exists(os.path.join(path, '__init__.py')):
raise OSError('Controllers directory %s exists but is missing __init__.py' % path)
- files = sorted([f for f in os.listdir(path) if f.endswith('.py') and not f.startswith('_')])
+ files = sorted([f for f in os.listdir(path) if f.endswith('.py') and not f.startswith('_') and not f.startswith('.#')])
for f in files:
module = 'oeqa.controllers.' + f[:-3]
if module not in controllerslist:
@@ -149,9 +151,12 @@ class OERuntimeTestContextExecutor(OETestContextExecutor):
else:
raise RuntimeError("Duplicate controller module found for %s. Layers should create unique controller module names" % module)
- extpath = target_modules_path.split(':')
- for p in extpath:
- controllerpath = os.path.join(p, 'lib', 'oeqa', 'controllers')
+ # sys.path can contain duplicate paths, but because of the login in
+ # add_controller_list this doesn't work and causes testimage to abort.
+ # Remove duplicates using an intermediate dictionary to ensure this
+ # doesn't happen.
+ for p in list(dict.fromkeys(sys.path)):
+ controllerpath = os.path.join(p, 'oeqa', 'controllers')
if os.path.exists(controllerpath):
add_controller_list(controllerpath)
return controllerslist
@@ -171,20 +176,13 @@ class OERuntimeTestContextExecutor(OETestContextExecutor):
# Search for and return a controller or None from given module name
@staticmethod
def _loadControllerFromModule(target, modulename):
- obj = None
- # import module, allowing it to raise import exception
- try:
- module = __import__(modulename, globals(), locals(), [target])
- except Exception as e:
- return obj
- # look for target class in the module, catching any exceptions as it
- # is valid that a module may not have the target class.
try:
- obj = getattr(module, target)
- except:
- obj = None
- return obj
-
+ import importlib
+ module = importlib.import_module(modulename)
+ return getattr(module, target)
+ except AttributeError:
+ return None
+
@staticmethod
def readPackagesManifest(manifest):
if not manifest or not os.path.exists(manifest):
@@ -199,10 +197,6 @@ class OERuntimeTestContextExecutor(OETestContextExecutor):
return image_packages
- @staticmethod
- def getHostDumper(cmds, directory):
- return HostDumper(cmds, directory)
-
def _process_args(self, logger, args):
if not args.packages_manifest:
raise TypeError('Manifest file not provided')
@@ -215,9 +209,6 @@ class OERuntimeTestContextExecutor(OETestContextExecutor):
self.tc_kwargs['init']['target'] = \
OERuntimeTestContextExecutor.getTarget(args.target_type,
None, args.target_ip, args.server_ip, **target_kwargs)
- self.tc_kwargs['init']['host_dumper'] = \
- OERuntimeTestContextExecutor.getHostDumper(None,
- args.host_dumper_dir)
self.tc_kwargs['init']['image_packages'] = \
OERuntimeTestContextExecutor.readPackagesManifest(
args.packages_manifest)