oeqa: Clean up logger handling

The logger handling in oeqa was confused at best. This patch:

a) Passes in a logger through various qemu runner pieces
b) Uses that logger consistently in the code
c) Creates a logger for QemuRunner outside the bitbake namespace
   meaning we don't conflict with the tinfoil logging changes

The result of this is more consistency. For runtime tests in testimage,
the logs always contain the debug info, nothing is shwon on the console.
For the oe-selftests, logs are intercepted and only shown if the test
fails.

(From OE-Core rev: 4ff678137a55b93c9ba2cbffda34335ba859f704)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Purdie
2017-11-08 18:17:17 +00:00
parent 7608f33f0f
commit 0e198a7311
6 changed files with 26 additions and 41 deletions

View File

@@ -18,19 +18,18 @@ from oeqa.utils.dump import TargetDumper
from oeqa.controllers.testtargetloader import TestTargetLoader
from abc import ABCMeta, abstractmethod
logger = logging.getLogger('BitBake.QemuRunner')
class BaseTarget(object, metaclass=ABCMeta):
supported_image_fstypes = []
def __init__(self, d):
def __init__(self, d, logger):
self.connection = None
self.ip = None
self.server_ip = None
self.datetime = d.getVar('DATETIME')
self.testdir = d.getVar("TEST_LOG_DIR")
self.pn = d.getVar("PN")
self.logger = logger
@abstractmethod
def deploy(self):
@@ -40,7 +39,7 @@ class BaseTarget(object, metaclass=ABCMeta):
if os.path.islink(sshloglink):
os.unlink(sshloglink)
os.symlink(self.sshlog, sshloglink)
logger.info("SSH log file: %s" % self.sshlog)
self.logger.info("SSH log file: %s" % self.sshlog)
@abstractmethod
def start(self, params=None, ssh=True, extra_bootparams=None):
@@ -90,7 +89,7 @@ class QemuTarget(BaseTarget):
supported_image_fstypes = ['ext3', 'ext4', 'cpio.gz', 'wic']
def __init__(self, d, image_fstype=None, logger=None):
def __init__(self, d, logger, image_fstype=None):
super(QemuTarget, self).__init__(d, logger)
@@ -120,7 +119,7 @@ class QemuTarget(BaseTarget):
self.qemurunnerlog = os.path.join(self.testdir, 'qemurunner_log.%s' % self.datetime)
loggerhandler = logging.FileHandler(self.qemurunnerlog)
loggerhandler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
logger.addHandler(loggerhandler)
self.logger.addHandler(loggerhandler)
oe.path.symlink(os.path.basename(self.qemurunnerlog), os.path.join(self.testdir, 'qemurunner_log'), force=True)
if d.getVar("DISTRO") == "poky-tiny":
@@ -131,7 +130,8 @@ class QemuTarget(BaseTarget):
display = d.getVar("BB_ORIGENV", False).getVar("DISPLAY"),
logfile = self.qemulog,
kernel = self.kernel,
boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT")))
boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT")),
logger = logger)
else:
self.runner = QemuRunner(machine=d.getVar("MACHINE"),
rootfs=self.rootfs,
@@ -142,7 +142,8 @@ class QemuTarget(BaseTarget):
boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT")),
use_kvm = use_kvm,
dump_dir = dump_dir,
dump_host_cmds = d.getVar("testimage_dump_host"))
dump_host_cmds = d.getVar("testimage_dump_host"),
logger = logger)
self.target_dumper = TargetDumper(dump_target_cmds, dump_dir, self.runner)
@@ -154,8 +155,8 @@ class QemuTarget(BaseTarget):
os.unlink(qemuloglink)
os.symlink(self.qemulog, qemuloglink)
logger.info("rootfs file: %s" % self.rootfs)
logger.info("Qemu log file: %s" % self.qemulog)
self.logger.info("rootfs file: %s" % self.rootfs)
self.logger.info("Qemu log file: %s" % self.qemulog)
super(QemuTarget, self).deploy()
def start(self, params=None, ssh=True, extra_bootparams='', runqemuparams='', launch_cmd='', discard_writes=True):
@@ -207,14 +208,14 @@ class SimpleRemoteTarget(BaseTarget):
self.port = addr.split(":")[1]
except IndexError:
self.port = None
logger.info("Target IP: %s" % self.ip)
self.logger.info("Target IP: %s" % self.ip)
self.server_ip = d.getVar("TEST_SERVER_IP")
if not self.server_ip:
try:
self.server_ip = subprocess.check_output(['ip', 'route', 'get', self.ip ]).split("\n")[0].split()[-1]
except Exception as e:
bb.fatal("Failed to determine the host IP address (alternatively you can set TEST_SERVER_IP with the IP address of this machine): %s" % e)
logger.info("Server IP: %s" % self.server_ip)
self.logger.info("Server IP: %s" % self.server_ip)
def deploy(self):
super(SimpleRemoteTarget, self).deploy()