blob: 6d1ec4cb99b12b858eee03dfefa14a3183c0cd81 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: MIT
3#
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004# Enable other layers to have modules in the same named directory
5from pkgutil import extend_path
6__path__ = extend_path(__path__, __name__)
7
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008# Borrowed from CalledProcessError
9
10class CommandError(Exception):
11 def __init__(self, retcode, cmd, output = None):
12 self.retcode = retcode
13 self.cmd = cmd
14 self.output = output
15 def __str__(self):
16 return "Command '%s' returned non-zero exit status %d with output: %s" % (self.cmd, self.retcode, self.output)
17
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050018def avoid_paths_in_environ(paths):
19 """
20 Searches for every path in os.environ['PATH']
21 if found remove it.
22
23 Returns new PATH without avoided PATHs.
24 """
25 import os
26
27 new_path = ''
28 for p in os.environ['PATH'].split(':'):
29 avoid = False
30 for pa in paths:
31 if pa in p:
32 avoid = True
33 break
34 if avoid:
35 continue
36
37 new_path = new_path + p + ':'
38
39 new_path = new_path[:-1]
40 return new_path
Brad Bishop6e60e8b2018-02-01 10:27:11 -050041
42def make_logger_bitbake_compatible(logger):
43 import logging
44
45 """
Andrew Geisslerd1e89492021-02-12 15:35:20 -060046 We need to raise the log level of the info output so unittest
47 messages are visible on the console.
Brad Bishop6e60e8b2018-02-01 10:27:11 -050048 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -050049 def _bitbake_log_info(msg, *args, **kwargs):
50 logger.log(logging.INFO + 1, msg, *args, **kwargs)
51
Brad Bishop6e60e8b2018-02-01 10:27:11 -050052 logger.info = _bitbake_log_info
53
54 return logger
Brad Bishopd7bf8c12018-02-25 22:55:05 -050055
56def load_test_components(logger, executor):
57 import sys
58 import os
59 import importlib
60
61 from oeqa.core.context import OETestContextExecutor
62
63 components = {}
64
65 for path in sys.path:
66 base_dir = os.path.join(path, 'oeqa')
67 if os.path.exists(base_dir) and os.path.isdir(base_dir):
68 for file in os.listdir(base_dir):
69 comp_name = file
70 comp_context = os.path.join(base_dir, file, 'context.py')
71 if os.path.exists(comp_context):
72 comp_plugin = importlib.import_module('oeqa.%s.%s' % \
73 (comp_name, 'context'))
74 try:
75 if not issubclass(comp_plugin._executor_class,
76 OETestContextExecutor):
77 raise TypeError("Component %s in %s, _executor_class "\
78 "isn't derived from OETestContextExecutor."\
79 % (comp_name, comp_context))
80
81 if comp_plugin._executor_class._script_executor \
82 != executor:
83 continue
84
85 components[comp_name] = comp_plugin._executor_class()
86 except AttributeError:
87 raise AttributeError("Component %s in %s don't have "\
88 "_executor_class defined." % (comp_name, comp_context))
89
90 return components