From: Mariano Lopez <mariano.lo...@linux.intel.com> This adds a way to register targets that can be used with runtime testing. To do this just decorate a target class with registerTarget, and set "targetName" attribute to the name that will be used by TEST_TARGET variable.
Signed-off-by: Mariano Lopez <mariano.lo...@linux.intel.com> --- meta/lib/oeqa/core/target/base.py | 23 +++++++++++++++++++++++ meta/lib/oeqa/core/target/qemu.py | 5 +++++ meta/lib/oeqa/core/target/ssh.py | 6 +++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/meta/lib/oeqa/core/target/base.py b/meta/lib/oeqa/core/target/base.py index d2468bc..c886491 100644 --- a/meta/lib/oeqa/core/target/base.py +++ b/meta/lib/oeqa/core/target/base.py @@ -1,8 +1,31 @@ # Copyright (C) 2016 Intel Corporation # Released under the MIT license (see COPYING.MIT) +import os +import sys +import importlib from abc import abstractmethod +# Used to keep record of registered targets, it +# uses class' targetName as the key to the class. +targetClasses = {} + +def registerTarget(obj): + """ Use as decorator to register targets for runtime testing """ + + if (obj.targetName in targetClasses and + obj.__name__ != targetClasses[obj.targetName].__name__): + + msg = ('Tried to register %s as "%s" that is used by %s' % + (obj, obj.targetName, targetClasses[obj.targetName])) + raise ImportError(msg) + + if not issubclass(obj, OETarget): + raise TypeError('%s must inherit from OETarget' % obj) + + targetClasses[obj.targetName] = obj + return obj + class OETarget(object): def __init__(self, logger, *args, **kwargs): diff --git a/meta/lib/oeqa/core/target/qemu.py b/meta/lib/oeqa/core/target/qemu.py index 261c466..d1b6bf5 100644 --- a/meta/lib/oeqa/core/target/qemu.py +++ b/meta/lib/oeqa/core/target/qemu.py @@ -6,12 +6,17 @@ import sys import signal import time +from oeqa.core.target.base import registerTarget from oeqa.core.target.ssh import OESSHTarget from oeqa.utils.qemurunner import QemuRunner supported_fstypes = ['ext3', 'ext4', 'cpio.gz', 'wic', 'elf'] +@registerTarget class OEQemuTarget(OESSHTarget): + + targetName = 'qemu' + def __init__(self, logger, ip, server_ip, timeout=300, user='root', port=None, machine='', rootfs='', kernel='', kvm=False, dump_dir='', dump_host_cmds='', display='', bootlog='', diff --git a/meta/lib/oeqa/core/target/ssh.py b/meta/lib/oeqa/core/target/ssh.py index 035965a..d973058 100644 --- a/meta/lib/oeqa/core/target/ssh.py +++ b/meta/lib/oeqa/core/target/ssh.py @@ -7,9 +7,13 @@ import select import logging import subprocess -from oeqa.core.target.base import OETarget +from oeqa.core.target.base import OETarget, registerTarget +@registerTarget class OESSHTarget(OETarget): + + targetName = 'simpleremote' + def __init__(self, logger, ip, server_ip, timeout=300, user='root', port=None, **kwargs): if not logger: -- 2.10.2 -- _______________________________________________ Openembedded-core mailing list Openembedded-core@lists.openembedded.org http://lists.openembedded.org/mailman/listinfo/openembedded-core