summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2017-11-08 18:17:17 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2018-03-04 11:11:59 +0000
commit66f536ad57d00f05defbbbf8f7cc64822666ad82 (patch)
treef57c386c26a3951c6a255808033d174e10959ae6 /meta/lib
parenta71e71f9c4d8c64fb27a03b5a048710c8aee01c1 (diff)
downloadpoky-66f536ad57d00f05defbbbf8f7cc64822666ad82.tar.gz
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: ba8babc45141891d0624f9a181a580fa416e87ec) (From OE-Core rev: 22003f97ff7f53c32999dc466d26c1471ead9b6b) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> Signed-off-by: Armin Kuster <akuster@mvista.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> Signed-off-by: Armin Kuster <akuster808@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
-rw-r--r--meta/lib/oeqa/core/target/qemu.py2
-rw-r--r--meta/lib/oeqa/selftest/runqemu.py5
-rw-r--r--meta/lib/oeqa/targetcontrol.py25
-rw-r--r--meta/lib/oeqa/utils/commands.py25
-rw-r--r--meta/lib/oeqa/utils/qemurunner.py7
-rw-r--r--meta/lib/oeqa/utils/qemutinyrunner.py3
6 files changed, 26 insertions, 41 deletions
diff --git a/meta/lib/oeqa/core/target/qemu.py b/meta/lib/oeqa/core/target/qemu.py
index 2dc521c216..d359bf9fe3 100644
--- a/meta/lib/oeqa/core/target/qemu.py
+++ b/meta/lib/oeqa/core/target/qemu.py
@@ -31,7 +31,7 @@ class OEQemuTarget(OESSHTarget):
31 deploy_dir_image=dir_image, display=display, 31 deploy_dir_image=dir_image, display=display,
32 logfile=bootlog, boottime=boottime, 32 logfile=bootlog, boottime=boottime,
33 use_kvm=kvm, dump_dir=dump_dir, 33 use_kvm=kvm, dump_dir=dump_dir,
34 dump_host_cmds=dump_host_cmds) 34 dump_host_cmds=dump_host_cmds, logger=logger)
35 35
36 def start(self, params=None, extra_bootparams=None): 36 def start(self, params=None, extra_bootparams=None):
37 if self.runner.start(params, extra_bootparams=extra_bootparams): 37 if self.runner.start(params, extra_bootparams=extra_bootparams):
diff --git a/meta/lib/oeqa/selftest/runqemu.py b/meta/lib/oeqa/selftest/runqemu.py
index 58c6f96f98..89ee780115 100644
--- a/meta/lib/oeqa/selftest/runqemu.py
+++ b/meta/lib/oeqa/selftest/runqemu.py
@@ -3,7 +3,6 @@
3# 3#
4 4
5import re 5import re
6import logging
7 6
8from oeqa.selftest.base import oeSelfTest 7from oeqa.selftest.base import oeSelfTest
9from oeqa.utils.commands import bitbake, runqemu, get_bb_var 8from oeqa.utils.commands import bitbake, runqemu, get_bb_var
@@ -21,10 +20,6 @@ class RunqemuTests(oeSelfTest):
21 self.fstypes = "ext4 iso hddimg vmdk qcow2 vdi" 20 self.fstypes = "ext4 iso hddimg vmdk qcow2 vdi"
22 self.cmd_common = "runqemu nographic" 21 self.cmd_common = "runqemu nographic"
23 22
24 # Avoid emit the same record multiple times.
25 mainlogger = logging.getLogger("BitBake.Main")
26 mainlogger.propagate = False
27
28 self.write_config( 23 self.write_config(
29""" 24"""
30MACHINE = "%s" 25MACHINE = "%s"
diff --git a/meta/lib/oeqa/targetcontrol.py b/meta/lib/oeqa/targetcontrol.py
index e17c89552f..f63936c3ec 100644
--- a/meta/lib/oeqa/targetcontrol.py
+++ b/meta/lib/oeqa/targetcontrol.py
@@ -18,19 +18,18 @@ from oeqa.utils.dump import TargetDumper
18from oeqa.controllers.testtargetloader import TestTargetLoader 18from oeqa.controllers.testtargetloader import TestTargetLoader
19from abc import ABCMeta, abstractmethod 19from abc import ABCMeta, abstractmethod
20 20
21logger = logging.getLogger('BitBake.QemuRunner')
22
23class BaseTarget(object, metaclass=ABCMeta): 21class BaseTarget(object, metaclass=ABCMeta):
24 22
25 supported_image_fstypes = [] 23 supported_image_fstypes = []
26 24
27 def __init__(self, d): 25 def __init__(self, d, logger):
28 self.connection = None 26 self.connection = None
29 self.ip = None 27 self.ip = None
30 self.server_ip = None 28 self.server_ip = None
31 self.datetime = d.getVar('DATETIME') 29 self.datetime = d.getVar('DATETIME')
32 self.testdir = d.getVar("TEST_LOG_DIR") 30 self.testdir = d.getVar("TEST_LOG_DIR")
33 self.pn = d.getVar("PN") 31 self.pn = d.getVar("PN")
32 self.logger = logger
34 33
35 @abstractmethod 34 @abstractmethod
36 def deploy(self): 35 def deploy(self):
@@ -40,7 +39,7 @@ class BaseTarget(object, metaclass=ABCMeta):
40 if os.path.islink(sshloglink): 39 if os.path.islink(sshloglink):
41 os.unlink(sshloglink) 40 os.unlink(sshloglink)
42 os.symlink(self.sshlog, sshloglink) 41 os.symlink(self.sshlog, sshloglink)
43 logger.info("SSH log file: %s" % self.sshlog) 42 self.logger.info("SSH log file: %s" % self.sshlog)
44 43
45 @abstractmethod 44 @abstractmethod
46 def start(self, params=None, ssh=True, extra_bootparams=None): 45 def start(self, params=None, ssh=True, extra_bootparams=None):
@@ -90,7 +89,7 @@ class QemuTarget(BaseTarget):
90 89
91 supported_image_fstypes = ['ext3', 'ext4', 'cpio.gz', 'wic'] 90 supported_image_fstypes = ['ext3', 'ext4', 'cpio.gz', 'wic']
92 91
93 def __init__(self, d, image_fstype=None, logger=None): 92 def __init__(self, d, logger, image_fstype=None):
94 93
95 super(QemuTarget, self).__init__(d, logger) 94 super(QemuTarget, self).__init__(d, logger)
96 95
@@ -120,7 +119,7 @@ class QemuTarget(BaseTarget):
120 self.qemurunnerlog = os.path.join(self.testdir, 'qemurunner_log.%s' % self.datetime) 119 self.qemurunnerlog = os.path.join(self.testdir, 'qemurunner_log.%s' % self.datetime)
121 loggerhandler = logging.FileHandler(self.qemurunnerlog) 120 loggerhandler = logging.FileHandler(self.qemurunnerlog)
122 loggerhandler.setFormatter(logging.Formatter("%(levelname)s: %(message)s")) 121 loggerhandler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
123 logger.addHandler(loggerhandler) 122 self.logger.addHandler(loggerhandler)
124 oe.path.symlink(os.path.basename(self.qemurunnerlog), os.path.join(self.testdir, 'qemurunner_log'), force=True) 123 oe.path.symlink(os.path.basename(self.qemurunnerlog), os.path.join(self.testdir, 'qemurunner_log'), force=True)
125 124
126 if d.getVar("DISTRO") == "poky-tiny": 125 if d.getVar("DISTRO") == "poky-tiny":
@@ -131,7 +130,8 @@ class QemuTarget(BaseTarget):
131 display = d.getVar("BB_ORIGENV", False).getVar("DISPLAY"), 130 display = d.getVar("BB_ORIGENV", False).getVar("DISPLAY"),
132 logfile = self.qemulog, 131 logfile = self.qemulog,
133 kernel = self.kernel, 132 kernel = self.kernel,
134 boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT"))) 133 boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT")),
134 logger = logger)
135 else: 135 else:
136 self.runner = QemuRunner(machine=d.getVar("MACHINE"), 136 self.runner = QemuRunner(machine=d.getVar("MACHINE"),
137 rootfs=self.rootfs, 137 rootfs=self.rootfs,
@@ -142,7 +142,8 @@ class QemuTarget(BaseTarget):
142 boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT")), 142 boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT")),
143 use_kvm = use_kvm, 143 use_kvm = use_kvm,
144 dump_dir = dump_dir, 144 dump_dir = dump_dir,
145 dump_host_cmds = d.getVar("testimage_dump_host")) 145 dump_host_cmds = d.getVar("testimage_dump_host"),
146 logger = logger)
146 147
147 self.target_dumper = TargetDumper(dump_target_cmds, dump_dir, self.runner) 148 self.target_dumper = TargetDumper(dump_target_cmds, dump_dir, self.runner)
148 149
@@ -154,8 +155,8 @@ class QemuTarget(BaseTarget):
154 os.unlink(qemuloglink) 155 os.unlink(qemuloglink)
155 os.symlink(self.qemulog, qemuloglink) 156 os.symlink(self.qemulog, qemuloglink)
156 157
157 logger.info("rootfs file: %s" % self.rootfs) 158 self.logger.info("rootfs file: %s" % self.rootfs)
158 logger.info("Qemu log file: %s" % self.qemulog) 159 self.logger.info("Qemu log file: %s" % self.qemulog)
159 super(QemuTarget, self).deploy() 160 super(QemuTarget, self).deploy()
160 161
161 def start(self, params=None, ssh=True, extra_bootparams='', runqemuparams='', launch_cmd='', discard_writes=True): 162 def start(self, params=None, ssh=True, extra_bootparams='', runqemuparams='', launch_cmd='', discard_writes=True):
@@ -207,14 +208,14 @@ class SimpleRemoteTarget(BaseTarget):
207 self.port = addr.split(":")[1] 208 self.port = addr.split(":")[1]
208 except IndexError: 209 except IndexError:
209 self.port = None 210 self.port = None
210 logger.info("Target IP: %s" % self.ip) 211 self.logger.info("Target IP: %s" % self.ip)
211 self.server_ip = d.getVar("TEST_SERVER_IP") 212 self.server_ip = d.getVar("TEST_SERVER_IP")
212 if not self.server_ip: 213 if not self.server_ip:
213 try: 214 try:
214 self.server_ip = subprocess.check_output(['ip', 'route', 'get', self.ip ]).split("\n")[0].split()[-1] 215 self.server_ip = subprocess.check_output(['ip', 'route', 'get', self.ip ]).split("\n")[0].split()[-1]
215 except Exception as e: 216 except Exception as e:
216 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) 217 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)
217 logger.info("Server IP: %s" % self.server_ip) 218 self.logger.info("Server IP: %s" % self.server_ip)
218 219
219 def deploy(self): 220 def deploy(self):
220 super(SimpleRemoteTarget, self).deploy() 221 super(SimpleRemoteTarget, self).deploy()
diff --git a/meta/lib/oeqa/utils/commands.py b/meta/lib/oeqa/utils/commands.py
index 57286fcb10..ed925a4d92 100644
--- a/meta/lib/oeqa/utils/commands.py
+++ b/meta/lib/oeqa/utils/commands.py
@@ -233,6 +233,12 @@ def runqemu(pn, ssh=True, runqemuparams='', image_fstype=None, launch_cmd=None,
233 import bb.tinfoil 233 import bb.tinfoil
234 import bb.build 234 import bb.build
235 235
236 # Need a non-'BitBake' logger to capture the runner output
237 targetlogger = logging.getLogger('TargetRunner')
238 targetlogger.setLevel(logging.DEBUG)
239 handler = logging.StreamHandler(sys.stdout)
240 targetlogger.addHandler(handler)
241
236 tinfoil = bb.tinfoil.Tinfoil() 242 tinfoil = bb.tinfoil.Tinfoil()
237 tinfoil.prepare(config_only=False, quiet=True) 243 tinfoil.prepare(config_only=False, quiet=True)
238 try: 244 try:
@@ -250,31 +256,15 @@ def runqemu(pn, ssh=True, runqemuparams='', image_fstype=None, launch_cmd=None,
250 for key, value in overrides.items(): 256 for key, value in overrides.items():
251 recipedata.setVar(key, value) 257 recipedata.setVar(key, value)
252 258
253 # The QemuRunner log is saved out, but we need to ensure it is at the right
254 # log level (and then ensure that since it's a child of the BitBake logger,
255 # we disable propagation so we don't then see the log events on the console)
256 logger = logging.getLogger('BitBake.QemuRunner')
257 logger.setLevel(logging.DEBUG)
258 logger.propagate = False
259 logdir = recipedata.getVar("TEST_LOG_DIR") 259 logdir = recipedata.getVar("TEST_LOG_DIR")
260 260
261 qemu = oeqa.targetcontrol.QemuTarget(recipedata, image_fstype) 261 qemu = oeqa.targetcontrol.QemuTarget(recipedata, targetlogger, image_fstype)
262 finally: 262 finally:
263 # We need to shut down tinfoil early here in case we actually want 263 # We need to shut down tinfoil early here in case we actually want
264 # to run tinfoil-using utilities with the running QEMU instance. 264 # to run tinfoil-using utilities with the running QEMU instance.
265 # Luckily QemuTarget doesn't need it after the constructor. 265 # Luckily QemuTarget doesn't need it after the constructor.
266 tinfoil.shutdown() 266 tinfoil.shutdown()
267 267
268 # Setup bitbake logger as console handler is removed by tinfoil.shutdown
269 bblogger = logging.getLogger('BitBake')
270 bblogger.setLevel(logging.INFO)
271 console = logging.StreamHandler(sys.stdout)
272 bbformat = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
273 if sys.stdout.isatty():
274 bbformat.enable_color()
275 console.setFormatter(bbformat)
276 bblogger.addHandler(console)
277
278 try: 268 try:
279 qemu.deploy() 269 qemu.deploy()
280 try: 270 try:
@@ -289,6 +279,7 @@ def runqemu(pn, ssh=True, runqemuparams='', image_fstype=None, launch_cmd=None,
289 qemu.stop() 279 qemu.stop()
290 except: 280 except:
291 pass 281 pass
282 targetlogger.removeHandler(handler)
292 283
293def updateEnv(env_file): 284def updateEnv(env_file):
294 """ 285 """
diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py
index 12653931f4..7ca9f1c736 100644
--- a/meta/lib/oeqa/utils/qemurunner.py
+++ b/meta/lib/oeqa/utils/qemurunner.py
@@ -28,7 +28,7 @@ re_control_char = re.compile('[%s]' % re.escape("".join(control_chars)))
28 28
29class QemuRunner: 29class QemuRunner:
30 30
31 def __init__(self, machine, rootfs, display, tmpdir, deploy_dir_image, logfile, boottime, dump_dir, dump_host_cmds, use_kvm): 31 def __init__(self, machine, rootfs, display, tmpdir, deploy_dir_image, logfile, boottime, dump_dir, dump_host_cmds, use_kvm, logger):
32 32
33 # Popen object for runqemu 33 # Popen object for runqemu
34 self.runqemu = None 34 self.runqemu = None
@@ -57,9 +57,7 @@ class QemuRunner:
57 self.qemu_pidfile = 'pidfile_'+str(os.getpid()) 57 self.qemu_pidfile = 'pidfile_'+str(os.getpid())
58 self.host_dumper = HostDumper(dump_host_cmds, dump_dir) 58 self.host_dumper = HostDumper(dump_host_cmds, dump_dir)
59 59
60 self.logger = logging.getLogger("BitBake.QemuRunner") 60 self.logger = logger
61 self.handler = logging.StreamHandler(sys.stdout)
62 self.logger.addHandler(self.handler)
63 61
64 def create_socket(self): 62 def create_socket(self):
65 try: 63 try:
@@ -370,7 +368,6 @@ class QemuRunner:
370 self.ip = None 368 self.ip = None
371 if os.path.exists(self.qemu_pidfile): 369 if os.path.exists(self.qemu_pidfile):
372 os.remove(self.qemu_pidfile) 370 os.remove(self.qemu_pidfile)
373 self.logger.removeHandler(self.handler)
374 371
375 def stop_qemu_system(self): 372 def stop_qemu_system(self):
376 if self.qemupid: 373 if self.qemupid:
diff --git a/meta/lib/oeqa/utils/qemutinyrunner.py b/meta/lib/oeqa/utils/qemutinyrunner.py
index 1bf59007ff..63b5d1648b 100644
--- a/meta/lib/oeqa/utils/qemutinyrunner.py
+++ b/meta/lib/oeqa/utils/qemutinyrunner.py
@@ -17,7 +17,7 @@ from .qemurunner import QemuRunner
17 17
18class QemuTinyRunner(QemuRunner): 18class QemuTinyRunner(QemuRunner):
19 19
20 def __init__(self, machine, rootfs, display, tmpdir, deploy_dir_image, logfile, kernel, boottime): 20 def __init__(self, machine, rootfs, display, tmpdir, deploy_dir_image, logfile, kernel, boottime, logger):
21 21
22 # Popen object for runqemu 22 # Popen object for runqemu
23 self.runqemu = None 23 self.runqemu = None
@@ -40,6 +40,7 @@ class QemuTinyRunner(QemuRunner):
40 self.socketfile = "console.sock" 40 self.socketfile = "console.sock"
41 self.server_socket = None 41 self.server_socket = None
42 self.kernel = kernel 42 self.kernel = kernel
43 self.logger = logger
43 44
44 45
45 def create_socket(self): 46 def create_socket(self):