From 65a0b1dc65bc0df69c68b7fa176f5035e5b5511f Mon Sep 17 00:00:00 2001 From: xudan Date: Wed, 26 Oct 2016 02:27:12 +0000 Subject: 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 ' can work. Change-Id: If8cd5c8c9c35434af2a5fa38575c06f83f0afc4d Signed-off-by: xudan --- dovetail/utils/dovetail_logger.py | 19 ++++++++++++++++--- 1 file 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) -- cgit 1.2.3-korg