dovetail tool: add debug option to control the log level showing in screen 01/25301/2
authorxudan <xudan16@huawei.com>
Thu, 1 Dec 2016 06:38:51 +0000 (06:38 +0000)
committerxudan <xudan16@huawei.com>
Mon, 5 Dec 2016 00:56:41 +0000 (00:56 +0000)
1. add debug option in cmd_config.yml for controling log showing in screen.
2. rename existent DEBUG as CON_DEBUG because it is used for functest/yardstick
   container to control the log level.
3. fix the bug in function update_config_envs(). If one key is not in system's
   envs, os.environ[key] get an error with ErrorKey.

JIRA: DOVETAIL-148

Change-Id: If3d75109f51e2e91743b8f1134a76da42e57383a
Signed-off-by: xudan <xudan16@huawei.com>
dovetail/conf/cmd_config.yml
dovetail/conf/dovetail_config.py
dovetail/run.py

index 4e3d011..35c000e 100644 (file)
@@ -31,11 +31,11 @@ cli:
           - '--DEPLOY_TYPE'
           - '-T'
         help: 'DEPLOY_TYPE of the system under test (SUT).'
-      DEBUG:
+      CON_DEBUG:
         flags:
-          - '--DEBUG'
-          - '-d'
-        help: 'DEBUG for showing debug log.'
+          - '--CON_DEBUG'
+          - '-c'
+        help: 'True for showing debug log in functest/yardstick container.'
     non-envs:
       testsuite:
         flags:
@@ -52,3 +52,8 @@ cli:
           - '--tag'
           - '-o'
         help: 'Overwrite tags for each docker container (e.g. "functest:stable,yardstick:latest")'
+      debug:
+        flags:
+          - '--debug'
+          - '-d'
+        help: 'True for showing debug log in screen.'
index 14dc59a..452ed6d 100644 (file)
@@ -23,6 +23,12 @@ class DovetailConfig:
 
     dovetail_config = {}
 
+    CMD_NAME_TRANS = {
+        'SUT_TYPE': 'INSTALLER_TYPE',
+        'SUT_IP': 'INSTALLER_IP',
+        'CON_DEBUG': 'CI_DEBUG',
+    }
+
     @classmethod
     def load_config_files(cls):
         curr_path = os.path.dirname(os.path.abspath(__file__))
@@ -42,11 +48,7 @@ class DovetailConfig:
     @classmethod
     def cmd_name_trans(cls, cmd_name):
         key = cmd_name.upper()
-        if key == 'SUT_TYPE':
-            key = 'INSTALLER_TYPE'
-        if key == 'SUT_IP':
-            key = 'INSTALLER_IP'
-        return key
+        return cls.CMD_NAME_TRANS.get(key, key)
 
     @classmethod
     def update_envs(cls, options):
@@ -55,18 +57,16 @@ class DovetailConfig:
             if not options[item] and key in os.environ:
                 options[item] = os.environ[key]
             if options[item]:
-                cls.update_config_envs('functest', key)
-                cls.update_config_envs('yardstick', key)
+                cls.update_config_envs('functest', key, options[item])
+                cls.update_config_envs('yardstick', key, options[item])
 
     @classmethod
-    def update_config_envs(cls, script_type, key):
-        if key == 'DEBUG':
-            os.environ['CI_DEBUG'] = os.environ[key]
+    def update_config_envs(cls, script_type, key, value):
         envs = cls.dovetail_config[script_type]['envs']
         old_value = re.findall(r'\s+%s=(.*?)(\s+|$)' % key, envs)
         if old_value == []:
-            envs += ' -e ' + key + '=' + os.environ[key]
+            envs += ' -e ' + key + '=' + value
         else:
-            envs = envs.replace(old_value[0][0], os.environ[key])
+            envs = envs.replace(old_value[0][0], value)
         cls.dovetail_config[script_type]['envs'] = envs
         return envs
index 0c57b4e..17f476b 100755 (executable)
@@ -141,6 +141,8 @@ def clean_results_dir():
 def main(*args, **kwargs):
     """Dovetail compliance test entry!"""
     clean_results_dir()
+    if kwargs['debug']:
+        os.environ['DEBUG'] = kwargs['debug']
     create_logs()
     logger = dt_logger.Logger('run').getLogger()
     logger.info('================================================')