]> code.ossystems Code Review - openembedded-core.git/commitdiff
scripts/oe-test: Move load_test_components to oeqa.utils
authorAníbal Limón <anibal.limon@linux.intel.com>
Tue, 23 May 2017 20:04:57 +0000 (15:04 -0500)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Mon, 5 Jun 2017 16:59:40 +0000 (17:59 +0100)
In order to maintain compatibility with oe-selftest, the
load_test_components needs to be re-used, so the script
executor needs to pass to only load components supported
by certain script (oe-test, oe-selftest).

Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
meta/lib/oeqa/core/context.py
meta/lib/oeqa/utils/__init__.py
scripts/oe-test

index 5f399fdfccc98490983f1acb73ddc38630c740c6..0dbf5c353e510bed6740ea8b1fec6c36545bc9a4 100644 (file)
@@ -65,6 +65,7 @@ class OETestContext(object):
 
 class OETestContextExecutor(object):
     _context_class = OETestContext
+    _script_executor = 'oe-test'
 
     name = 'core'
     help = 'core test component example'
index 485de031a99175751e05bf9d7e18987346dc56ab..d38a323013c410bc6c2a06134cac9977894f5889 100644 (file)
@@ -2,7 +2,6 @@
 from pkgutil import extend_path
 __path__ = extend_path(__path__, __name__)
 
-
 # Borrowed from CalledProcessError
 
 class CommandError(Exception):
@@ -66,3 +65,39 @@ def make_logger_bitbake_compatible(logger):
     logger.info = _bitbake_log_info
 
     return logger
+
+def load_test_components(logger, executor):
+    import sys
+    import os
+    import importlib
+
+    from oeqa.core.context import OETestContextExecutor
+
+    components = {}
+
+    for path in sys.path:
+        base_dir = os.path.join(path, 'oeqa')
+        if os.path.exists(base_dir) and os.path.isdir(base_dir):
+            for file in os.listdir(base_dir):
+                comp_name = file
+                comp_context = os.path.join(base_dir, file, 'context.py')
+                if os.path.exists(comp_context):
+                    comp_plugin = importlib.import_module('oeqa.%s.%s' % \
+                            (comp_name, 'context'))
+                    try:
+                        if not issubclass(comp_plugin._executor_class,
+                                OETestContextExecutor):
+                            raise TypeError("Component %s in %s, _executor_class "\
+                                "isn't derived from OETestContextExecutor."\
+                                % (comp_name, comp_context))
+
+                        if comp_plugin._executor_class._script_executor \
+                                != executor:
+                            continue
+
+                        components[comp_name] = comp_plugin._executor_class()
+                    except AttributeError:
+                        raise AttributeError("Component %s in %s don't have "\
+                                "_executor_class defined." % (comp_name, comp_context))
+
+    return components
index f90d85b3dae93199060b3805caa766dc24020808..0a36b78ff72a225baa06350fd7cfcb3cd974b9c0 100755 (executable)
@@ -8,7 +8,6 @@
 import os
 import sys
 import argparse
-import importlib
 import logging
 
 scripts_path = os.path.dirname(os.path.realpath(__file__))
@@ -25,37 +24,11 @@ try:
 except ImportError:
     pass
 
-from oeqa.core.context import OETestContextExecutor
+from oeqa.utils import load_test_components
 from oeqa.core.exception import OEQAPreRun
 
 logger = scriptutils.logger_create('oe-test')
 
-def _load_test_components(logger):
-    components = {}
-
-    for path in sys.path:
-        base_dir = os.path.join(path, 'oeqa')
-        if os.path.exists(base_dir) and os.path.isdir(base_dir):
-            for file in os.listdir(base_dir):
-                comp_name = file
-                comp_context = os.path.join(base_dir, file, 'context.py')
-                if os.path.exists(comp_context):
-                    comp_plugin = importlib.import_module('oeqa.%s.%s' % \
-                            (comp_name, 'context'))
-                    try:
-                        if not issubclass(comp_plugin._executor_class,
-                                OETestContextExecutor):
-                            raise TypeError("Component %s in %s, _executor_class "\
-                                "isn't derived from OETestContextExecutor."\
-                                % (comp_name, comp_context))
-
-                        components[comp_name] = comp_plugin._executor_class()
-                    except AttributeError:
-                        raise AttributeError("Component %s in %s don't have "\
-                                "_executor_class defined." % (comp_name, comp_context))
-
-    return components
-
 def main():
     parser = argparse_oe.ArgumentParser(description="OpenEmbedded test tool",
                                         add_help=False,
@@ -74,7 +47,7 @@ def main():
     elif global_args.quiet:
         logger.setLevel(logging.ERROR)
 
-    components = _load_test_components(logger)
+    components = load_test_components(logger, 'oe-test')
 
     subparsers = parser.add_subparsers(dest="subparser_name", title='subcommands', metavar='<subcommand>')
     subparsers.add_subparser_group('components', 'Test components')