test suite reviews and discussions
 help / color / mirror / Atom feed
From: "Jiajia, Sun" <sunx.jiajia@intel.com>
To: dts@dpdk.org
Subject: [dts] [PATCH v2 11/19] Add some codes to support virtual test log
Date: Fri, 22 May 2015 17:04:04 +0800	[thread overview]
Message-ID: <1432285452-14286-12-git-send-email-sunx.jiajia@intel.com> (raw)
In-Reply-To: <1432285452-14286-1-git-send-email-sunx.jiajia@intel.com>

From: sjiajiax <sunx.jiajia@intel.com>

Signed-off-by: sjiajiax <sunx.jiajia@intel.com>
---
 framework/logger.py | 69 +++++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 59 insertions(+), 10 deletions(-)

diff --git a/framework/logger.py b/framework/logger.py
index 1829e18..5597e33 100644
--- a/framework/logger.py
+++ b/framework/logger.py
@@ -35,6 +35,9 @@ import sys
 import inspect
 import re
 
+from settings import LOG_NAME_SEP
+from utils import RED
+
 """
 DTS logger module with several log level. DTS framwork and TestSuite log
 will saved into different log files.
@@ -58,6 +61,9 @@ logging.SUITE_TESTER_OUTPUT = logging.DEBUG + 4
 logging.DTS_IXIA_CMD = logging.INFO + 5
 logging.DTS_IXIA_OUTPUT = logging.DEBUG + 5
 
+logging.DTS_VIRTDUT_CMD = logging.INFO + 6
+logging.DTS_VIRTDUT_OUTPUT = logging.DEBUG + 6
+
 logging.addLevelName(logging.DTS_DUT_CMD, 'DTS_DUT_CMD')
 logging.addLevelName(logging.DTS_DUT_OUTPUT, 'DTS_DUT_OUTPUT')
 logging.addLevelName(logging.DTS_DUT_RESULT, 'DTS_DUT_RESUTL')
@@ -66,6 +72,12 @@ logging.addLevelName(logging.DTS_TESTER_CMD, 'DTS_TESTER_CMD')
 logging.addLevelName(logging.DTS_TESTER_OUTPUT, 'DTS_TESTER_OUTPUT')
 logging.addLevelName(logging.DTS_TESTER_RESULT, 'DTS_TESTER_RESULT')
 
+logging.addLevelName(logging.DTS_IXIA_CMD, 'DTS_IXIA_CMD')
+logging.addLevelName(logging.DTS_IXIA_OUTPUT, 'DTS_IXIA_OUTPUT')
+
+logging.addLevelName(logging.DTS_VIRTDUT_CMD, 'VIRTDUT_CMD')
+logging.addLevelName(logging.DTS_VIRTDUT_OUTPUT, 'VIRTDUT_OUTPUT')
+
 logging.addLevelName(logging.SUITE_DUT_CMD, 'SUITE_DUT_CMD')
 logging.addLevelName(logging.SUITE_DUT_OUTPUT, 'SUITE_DUT_OUTPUT')
 
@@ -82,15 +94,18 @@ stream_fmt = '%(color)s%(levelname)20s: %(message)s' + RESET_COLOR
 log_dir = None
 
 
-def RED(text):
-    return "\x1B[" + "31;1m" + text + "\x1B[" + "0m"
-
-
 def set_verbose():
     global verbose
     verbose = True
 
 
+def add_salt(salt, msg):
+    if not salt:
+        return msg
+    else:
+        return '[%s] ' % salt + str(msg)
+
+
 class BaseLoggerAdapter(logging.LoggerAdapter):
     """
     Upper layer of original logging module.
@@ -132,6 +147,12 @@ class BaseLoggerAdapter(logging.LoggerAdapter):
     def dts_ixia_output(self, msg, *args, **kwargs):
         self.log(logging.DTS_IXIA_OUTPUT, msg, *args, **kwargs)
 
+    def dts_virtdut_cmd(self, msg, *args, **kwargs):
+        self.log(logging.DTS_VIRTDUT_CMD, msg, *args, **kwargs)
+
+    def dts_virtdut_output(self, msg, *args, **kwargs):
+        self.log(logging.DTS_VIRTDUT_OUTPUT, msg, *args, **kwargs)
+
 
 class ColorHandler(logging.StreamHandler):
     """
@@ -150,6 +171,8 @@ class ColorHandler(logging.StreamHandler):
         logging.SUITE_TESTER_CMD: '',  # SYSTEM
         logging.DTS_IXIA_CMD: '',  # SYSTEM
         logging.DTS_IXIA_OUTPUT: '',  # SYSTEM
+        logging.DTS_VIRTDUT_CMD: '',  # SYSTEM
+        logging.DTS_VIRTDUT_OUTPUT: '',  # SYSTEM
         logging.WARN: '\033[01;33m',  # BOLD YELLOW
         logging.DTS_DUT_RESULT: '\033[01;34m',  # BOLD BLUE
         logging.DTS_TESTER_RESULT: '\033[01;34m',  # BOLD BLUE
@@ -189,6 +212,8 @@ class DTSLOG(BaseLoggerAdapter):
         self.crb = crb
         super(DTSLOG, self).__init__(self.logger, dict(crb=self.crb))
 
+        self.salt = ''
+
         self.fh = None
         self.ch = None
 
@@ -221,24 +246,28 @@ class DTSLOG(BaseLoggerAdapter):
         """
         DTS warnning level log function.
         """
+        message = add_salt(self.salt, message)
         self.logger.log(self.warn_lvl, message)
 
     def info(self, message):
         """
         DTS information level log function.
         """
+        message = add_salt(self.salt, message)
         self.logger.log(self.info_lvl, message)
 
     def error(self, message):
         """
         DTS error level log function.
         """
+        message = add_salt(self.salt, message)
         self.logger.log(self.error_lvl, message)
 
     def debug(self, message):
         """
         DTS debug level log function.
         """
+        message = add_salt(self.salt, message)
         self.logger.log(self.debug_lvl, message)
 
     def set_logfile_path(self, path):
@@ -270,17 +299,34 @@ class DTSLOG(BaseLoggerAdapter):
         ch = ColorHandler()
         self.__log_hander(fh, ch)
 
-        if crb == "dut":
+        def set_salt(crb, start_flag):
+            if LOG_NAME_SEP in crb:
+                old = '%s%s' % (start_flag, LOG_NAME_SEP)
+                if not self.salt:
+                    self.salt = crb.replace(old, '', 1)
+
+        if crb.startswith('dut'):
             self.info_lvl = logging.DTS_DUT_CMD
             self.debug_lvl = logging.DTS_DUT_OUTPUT
             self.warn_lvl = logging.DTS_DUT_RESULT
-        elif crb == "tester":
+
+            set_salt(crb, 'dut')
+        elif crb.startswith('tester'):
             self.info_lvl = logging.DTS_TESTER_CMD
             self.debug_lvl = logging.DTS_TESTER_OUTPUT
             self.warn_lvl = logging.DTS_TESTER_RESULT
-        elif crb == "ixia":
+
+            set_salt(crb, 'tester')
+        elif crb.startswith('ixia'):
             self.info_lvl = logging.DTS_IXIA_CMD
             self.debug_lvl = logging.DTS_IXIA_OUTPUT
+
+            set_salt(crb, 'ixia')
+        elif crb.startswith('virtdut'):
+            self.info_lvl = logging.DTS_VIRTDUT_CMD
+            self.debug_lvl = logging.DTS_VIRTDUT_OUTPUT
+
+            set_salt(crb, 'virtdut')
         else:
             self.error_lvl = logging.ERROR
             self.warn_lvl = logging.WARNING
@@ -296,15 +342,18 @@ class DTSLOG(BaseLoggerAdapter):
         ch = ColorHandler()
         self.__log_hander(fh, ch)
 
-        if crb == "dut":
+        if crb == 'dut':
             self.info_lvl = logging.SUITE_DUT_CMD
             self.debug_lvl = logging.SUITE_DUT_OUTPUT
-        elif crb == "tester":
+        elif crb == 'tester':
             self.info_lvl = logging.SUITE_TESTER_CMD
             self.debug_lvl = logging.SUITE_TESTER_OUTPUT
-        elif crb == "ixia":
+        elif crb == 'ixia':
             self.info_lvl = logging.DTS_IXIA_CMD
             self.debug_lvl = logging.DTS_IXIA_OUTPUT
+        elif crb == 'virtdut':
+            self.info_lvl = logging.DTS_VIRTDUT_CMD
+            self.debug_lvl = logging.DTS_VIRTDUT_OUTPUT
 
     def logger_exit(self):
         """
-- 
1.9.3

  parent reply	other threads:[~2015-05-22  9:04 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-22  9:03 [dts] [PATCH v2 00/19] *** Enable virtualization test for dts framework *** Jiajia, Sun
2015-05-22  9:03 ` [dts] [PATCH v2 01/19] Abstract the NIC device as the single class NetDevice Jiajia, Sun
2015-05-22  9:03 ` [dts] [PATCH v2 02/19] Add a base module for virtual test Jiajia, Sun
2015-05-22  9:03 ` [dts] [PATCH v2 03/19] Add QEMU KVM module based on virt_base module for KVM test cases Jiajia, Sun
2015-05-22  9:03 ` [dts] [PATCH v2 04/19] Add a module to manage the host resource Jiajia, Sun
2015-05-22  9:03 ` [dts] [PATCH v2 05/19] Add a module to instantiate the VM Jiajia, Sun
2015-05-25  6:10   ` Qiu, Michael
2015-05-25  9:14     ` Jiajia, SunX
2015-05-26  9:07       ` Qiu, Michael
2015-05-27  1:36         ` Jiajia, SunX
2015-05-22  9:03 ` [dts] [PATCH v2 06/19] Add a third-party module of qemu-guest-agent to manage VM Jiajia, Sun
2015-05-22  9:04 ` [dts] [PATCH v2 07/19] Move some general functions from dts.py to utils.py and settings.py Jiajia, Sun
2015-05-22  9:04 ` [dts] [PATCH v2 08/19] Add and move some functions because of the virtual tests and network device instantiation Jiajia, Sun
2015-05-22  9:04 ` [dts] [PATCH v2 09/19] Change and add some functions to support virtual test Jiajia, Sun
2015-05-22  9:04 ` [dts] [PATCH v2 10/19] add some exceptions to support framwork to handle virtual test exceptions Jiajia, Sun
2015-05-22  9:04 ` Jiajia, Sun [this message]
2015-05-22  9:04 ` [dts] [PATCH v2 12/19] Add some codes to make session to support virtual test Jiajia, Sun
2015-05-22  9:04 ` [dts] [PATCH v2 13/19] Add some base functions to get the device info in the testpmd Jiajia, Sun
2015-05-22  9:04 ` [dts] [PATCH v2 14/19] Change some codes to support network device instantiation and virtualization test Jiajia, Sun
2015-05-22  9:04 ` [dts] [PATCH v2 15/19] Add some codes to support network instantiation in the tester module Jiajia, Sun
2015-05-22  9:04 ` [dts] [PATCH v2 16/19] Make test_case know its suite name Jiajia, Sun
2015-05-22  9:04 ` [dts] [PATCH v2 17/19] Add a global virtualization config and a config related to SRIOV KVM suite Jiajia, Sun
2015-05-22  9:04 ` [dts] [PATCH v2 18/19] Add a test plan of how to test SRIOV on the KVM ENV Jiajia, Sun
2015-05-22  9:04 ` [dts] [PATCH v2 19/19] Add a test suite to verify the SRIOV feature " Jiajia, Sun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1432285452-14286-12-git-send-email-sunx.jiajia@intel.com \
    --to=sunx.jiajia@intel.com \
    --cc=dts@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).