summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxudan <xudan16@huawei.com>2016-10-26 02:27:12 +0000
committerxudan <xudan16@huawei.com>2016-11-03 02:00:05 +0000
commit65a0b1dc65bc0df69c68b7fa176f5035e5b5511f (patch)
tree959284c8813cdf03b4cf545758191e5cf7d416fb
parentbb5d6a119196dcfeabf141cca23b6495fc5e386e (diff)
dovetail tool: cleanup result directory before running
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>
-rw-r--r--dovetail/utils/dovetail_logger.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/dovetail/utils/dovetail_logger.py b/dovetail/utils/dovetail_logger.py
index bd13508d..9cd8719b 100644
--- a/dovetail/utils/dovetail_logger.py
+++ b/dovetail/utils/dovetail_logger.py
@@ -24,6 +24,18 @@
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)