[oe-commits] [openembedded-core] 05/23: targetcontrol.py: use logger.info to replace of bb.note

git at git.openembedded.org git at git.openembedded.org
Sun Mar 26 12:17:26 UTC 2017


This is an automated email from the git hooks/post-receive script.

rpurdie pushed a commit to branch master-next
in repository openembedded-core.

commit b139790422bc8e0d80bad063bb78bc1632731bc1
Author: Robert Yang <liezhi.yang at windriver.com>
AuthorDate: Fri Mar 24 01:45:02 2017 -0700

    targetcontrol.py: use logger.info to replace of bb.note
    
    The bb.note prints multiple same lines when invoke this class again, but
    if we set mainlogger.propagate = False, nothing would be printed,
    according to logging's document:
    
    https://docs.python.org/3/library/logging.html
    Note
    If you attach a handler to a logger and one or more of its ancestors, it
    may emit the same record multiple times. In general, you should not need
    to attach a handler to more than one logger - if you just attach it to
    the appropriate logger which is highest in the logger hierarchy, then it
    will see all events logged by all descendant loggers, provided that
    their propagate setting is left set to True. A common scenario is to
    attach handlers only to the root logger, and to let propagation take
    care of the rest.
    
    We may need avoid using bb.note or bb.warn in oeqa since it attaches
    multiple log handlers which may cause confusions
    
    This patch only sets "mainlogger.propagate = False" in
    selftest/runqemu.py and use logger.info to replace bb.note in
    targetcontrol.py to minimize the impact.
    
    [YOCTO #10249]
    
    Signed-off-by: Robert Yang <liezhi.yang at windriver.com>
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
 meta/lib/oeqa/selftest/runqemu.py |  4 ++++
 meta/lib/oeqa/targetcontrol.py    | 13 +++++++------
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/meta/lib/oeqa/selftest/runqemu.py b/meta/lib/oeqa/selftest/runqemu.py
index c1d5c16..58c6f96 100644
--- a/meta/lib/oeqa/selftest/runqemu.py
+++ b/meta/lib/oeqa/selftest/runqemu.py
@@ -21,6 +21,10 @@ class RunqemuTests(oeSelfTest):
         self.fstypes = "ext4 iso hddimg vmdk qcow2 vdi"
         self.cmd_common = "runqemu nographic"
 
+        # Avoid emit the same record multiple times.
+        mainlogger = logging.getLogger("BitBake.Main")
+        mainlogger.propagate = False
+
         self.write_config(
 """
 MACHINE = "%s"
diff --git a/meta/lib/oeqa/targetcontrol.py b/meta/lib/oeqa/targetcontrol.py
index ea89538..40a2589 100644
--- a/meta/lib/oeqa/targetcontrol.py
+++ b/meta/lib/oeqa/targetcontrol.py
@@ -18,6 +18,8 @@ from oeqa.utils.dump import TargetDumper
 from oeqa.controllers.testtargetloader import TestTargetLoader
 from abc import ABCMeta, abstractmethod
 
+logger = logging.getLogger('BitBake.QemuRunner')
+
 def get_target_controller(d):
     testtarget = d.getVar("TEST_TARGET")
     # old, simple names
@@ -63,7 +65,7 @@ class BaseTarget(object, metaclass=ABCMeta):
         if os.path.islink(sshloglink):
             os.unlink(sshloglink)
         os.symlink(self.sshlog, sshloglink)
-        bb.note("SSH log file: %s" %  self.sshlog)
+        logger.info("SSH log file: %s" %  self.sshlog)
 
     @abstractmethod
     def start(self, params=None, ssh=True, extra_bootparams=None):
@@ -140,7 +142,6 @@ class QemuTarget(BaseTarget):
         import oe.path
         bb.utils.mkdirhier(self.testdir)
         self.qemurunnerlog = os.path.join(self.testdir, 'qemurunner_log.%s' % self.datetime)
-        logger = logging.getLogger('BitBake.QemuRunner')
         loggerhandler = logging.FileHandler(self.qemurunnerlog)
         loggerhandler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
         logger.addHandler(loggerhandler)
@@ -177,8 +178,8 @@ class QemuTarget(BaseTarget):
             os.unlink(qemuloglink)
         os.symlink(self.qemulog, qemuloglink)
 
-        bb.note("rootfs file: %s" %  self.rootfs)
-        bb.note("Qemu log file: %s" % self.qemulog)
+        logger.info("rootfs file: %s" %  self.rootfs)
+        logger.info("Qemu log file: %s" % self.qemulog)
         super(QemuTarget, self).deploy()
 
     def start(self, params=None, ssh=True, extra_bootparams='', runqemuparams='', launch_cmd=''):
@@ -230,14 +231,14 @@ class SimpleRemoteTarget(BaseTarget):
             self.port = addr.split(":")[1]
         except IndexError:
             self.port = None
-        bb.note("Target IP: %s" % self.ip)
+        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)
-        bb.note("Server IP: %s" % self.server_ip)
+        logger.info("Server IP: %s" % self.server_ip)
 
     def deploy(self):
         super(SimpleRemoteTarget, self).deploy()

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list