dovetail tool: cleanup result directory before running 77/23677/3
authorxudan <xudan16@huawei.com>
Wed, 26 Oct 2016 02:27:12 +0000 (02:27 +0000)
committerxudan <xudan16@huawei.com>
Thu, 3 Nov 2016 02:00:05 +0000 (02:00 +0000)
JIRA: DOVETAIL-38

1. Do cleaning at the beginning of each run.
2. Since some files and folders have the 'root root' privilege,
   no command except cmd 'sudo rm -rf <results_dir>' can work.

Change-Id: If8cd5c8c9c35434af2a5fa38575c06f83f0afc4d
Signed-off-by: xudan <xudan16@huawei.com>
dovetail/utils/dovetail_logger.py

index bd13508..9cd8719 100644 (file)
 import logging
 import os
 
+from conf.dovetail_config import dovetail_config
+import dovetail_utils as dt_utils
+
+
+def clean_results_dir():
+    result_path = dovetail_config['result_dir']
+    if os.path.exists(result_path):
+        cmd = 'sudo rm -rf %s' % (result_path)
+        dt_utils.exec_cmd(cmd)
+
+clean_results_dir()
+
 
 class Logger:
     def __init__(self, logger_name):
@@ -44,9 +56,10 @@ class Logger:
             ch.setLevel(logging.INFO)
         self.logger.addHandler(ch)
 
-        if not os.path.exists('/home/opnfv/dovetail/results/'):
-            os.makedirs('/home/opnfv/dovetail/results/')
-        hdlr = logging.FileHandler('/home/opnfv/dovetail/results/dovetail.log')
+        result_path = dovetail_config['result_dir']
+        if not os.path.exists(result_path):
+            os.makedirs(result_path)
+        hdlr = logging.FileHandler(os.path.join(result_path, 'dovetail.log'))
         hdlr.setFormatter(formatter)
         hdlr.setLevel(logging.DEBUG)
         self.logger.addHandler(hdlr)