summaryrefslogtreecommitdiffstats
path: root/dovetail/report.py
diff options
context:
space:
mode:
authorxudan <xudan16@huawei.com>2016-11-08 11:43:28 +0000
committerxudan <xudan16@huawei.com>2016-11-29 01:56:00 +0000
commit75dd45462f46c711f950c96aac783932cb7ec1a4 (patch)
treeb197eaae13bec2b83abe4e778fce1a0d4a965657 /dovetail/report.py
parentcd94a6e124ae98f85bc2f7c3c26e052bb3f5e549 (diff)
dovetail tool: package all logger initialization
1. For container.py, parser.py, report.py and testcase.py, they use functions in classes to create loggers. So each class will have its own logger. 2. run.py will create all the loggers by create_logs() function before the use of them. So logs will not be initialized until the call of create_logs(). 3. Move logger in run.py into function main(). JIRA: DOVETAIL-56 Change-Id: I53de090df270cc7a34762ff99cbc9115cfb09465 Signed-off-by: xudan <xudan16@huawei.com>
Diffstat (limited to 'dovetail/report.py')
-rw-r--r--dovetail/report.py78
1 files changed, 53 insertions, 25 deletions
diff --git a/dovetail/report.py b/dovetail/report.py
index 2e544ad3..52c8ebf9 100644
--- a/dovetail/report.py
+++ b/dovetail/report.py
@@ -16,8 +16,6 @@ import utils.dovetail_logger as dt_logger
from conf.dovetail_config import DovetailConfig as dt_config
from testcase import Testcase
-logger = dt_logger.Logger('report.py').getLogger()
-
def get_pass_str(passed):
if passed:
@@ -30,6 +28,12 @@ class Report:
results = {'functest': {}, 'yardstick': {}}
+ logger = None
+
+ @classmethod
+ def create_log(cls):
+ cls.logger = dt_logger.Logger(__name__+'.Report').getLogger()
+
@staticmethod
def check_result(testcase, db_result):
checker = CheckerFactory.create(testcase.script_type())
@@ -66,7 +70,7 @@ class Report:
testcase.sub_testcase_passed(sub_test))
})
report_obj['testcases_list'].append(testcase_in_rpt)
- logger.info(json.dumps(report_obj))
+ cls.logger.info(json.dumps(report_obj))
return report_obj
@classmethod
@@ -91,21 +95,21 @@ class Report:
(sub_test['name'], sub_test['result'])
rpt_text += split_line
- logger.info(rpt_text)
+ cls.logger.info(rpt_text)
cls.save(rpt_text)
return rpt_text
# save to disk as default
- @staticmethod
- def save(report):
+ @classmethod
+ def save(cls, report):
report_file_name = dt_config.dovetail_config['report_file']
try:
with open(os.path.join(dt_config.dovetail_config['result_dir'],
report_file_name), 'w') as report_file:
report_file.write(report)
- logger.info('save report to %s' % report_file_name)
+ cls.logger.info('save report to %s' % report_file_name)
except Exception:
- logger.error('Failed to save: %s' % report_file_name)
+ cls.logger.error('Failed to save: %s' % report_file_name)
@classmethod
def get_result(cls, testcase):
@@ -121,11 +125,12 @@ class Report:
if result is not None:
cls.results[type][script_testcase] = result
testcase.script_result_acquired(True)
- logger.debug('testcase: %s -> result acquired' % script_testcase)
+ cls.logger.debug('testcase: %s -> result acquired' %
+ script_testcase)
else:
retry = testcase.increase_retry()
- logger.debug('testcase: %s -> result acquired retry:%d' %
- (script_testcase, retry))
+ cls.logger.debug('testcase: %s -> result acquired retry:%d' %
+ (script_testcase, retry))
return result
@@ -144,9 +149,15 @@ class CrawlerFactory:
class FunctestCrawler:
+ logger = None
+
def __init__(self):
self.type = 'functest'
+ @classmethod
+ def create_log(cls):
+ cls.logger = dt_logger.Logger(__name__+'.FunctestCrawler').getLogger()
+
def crawl(self, testcase=None):
store_type = \
dt_config.dovetail_config[self.type]['result']['store_type']
@@ -162,7 +173,7 @@ class FunctestCrawler:
os.path.join(dovetail_config['result_dir'],
dovetail_config[self.type]['result']['file_path'])
if not os.path.exists(file_path):
- logger.info('result file not found: %s' % file_path)
+ self.logger.info('result file not found: %s' % file_path)
return None
try:
@@ -184,31 +195,37 @@ class FunctestCrawler:
"duration": int(dur_sec_int),
"tests": int(num_tests), "failures": failed_num,
"errors": error_logs}}
- logger.debug('Results: %s' % str(json_results))
+ self.logger.debug('Results: %s' % str(json_results))
return json_results
except Exception as e:
- logger.error('Cannot read content from the file: %s, exception: %s'
- % (file_path, e))
+ self.logger.error('Cannot read content from the file: %s, '
+ 'exception: %s' % (file_path, e))
return None
def crawl_from_url(self, testcase=None):
url = \
dt_config.dovetail_config[self.type]['result']['db_url'] % testcase
- logger.debug("Query to rest api: %s" % url)
+ self.logger.debug("Query to rest api: %s" % url)
try:
data = json.load(urllib2.urlopen(url))
return data['results'][0]
except Exception as e:
- logger.error("Cannot read content from the url: %s, exception: %s"
- % (url, e))
+ self.logger.error("Cannot read content from the url: %s, "
+ "exception: %s" % (url, e))
return None
class YardstickCrawler:
+ logger = None
+
def __init__(self):
self.type = 'yardstick'
+ @classmethod
+ def create_log(cls):
+ cls.logger = dt_logger.Logger(__name__+'.YardstickCrawler').getLogger()
+
def crawl(self, testcase=None):
store_type = \
dt_config.dovetail_config[self.type]['result']['store_type']
@@ -222,18 +239,18 @@ class YardstickCrawler:
file_path = os.path.join(dt_config.dovetail_config['result_dir'],
testcase+'.out')
if not os.path.exists(file_path):
- logger.info('result file not found: %s' % file_path)
+ self.logger.info('result file not found: %s' % file_path)
return None
try:
with open(file_path, 'r') as myfile:
myfile.read()
criteria = 'PASS'
json_results = {'criteria': criteria}
- logger.debug('Results: %s' % str(json_results))
+ self.logger.debug('Results: %s' % str(json_results))
return json_results
except Exception as e:
- logger.error('Cannot read content from the file: %s, exception: %s'
- % (file_path, e))
+ self.logger.error('Cannot read content from the file: %s, '
+ 'exception: %s' % (file_path, e))
return None
def crawl_from_url(self, testcase=None):
@@ -262,8 +279,13 @@ class ResultChecker:
class FunctestChecker:
- @staticmethod
- def check(testcase, db_result):
+ logger = None
+
+ @classmethod
+ def create_log(cls):
+ cls.logger = dt_logger.Logger(__name__+'.FunctestChecker').getLogger()
+
+ def check(self, testcase, db_result):
sub_testcase_list = testcase.sub_testcase()
if not db_result:
@@ -284,7 +306,7 @@ class FunctestChecker:
all_passed = True
for sub_testcase in sub_testcase_list:
- logger.debug('check sub_testcase:%s' % sub_testcase)
+ self.logger.debug('check sub_testcase:%s' % sub_testcase)
if sub_testcase in db_result['details']['errors']:
testcase.sub_testcase_passed(sub_testcase, False)
all_passed = False
@@ -296,6 +318,12 @@ class FunctestChecker:
class YardstickChecker:
+ logger = None
+
+ @classmethod
+ def create_log(cls):
+ cls.logger = dt_logger.Logger(__name__+'.YardstickChecker').getLogger()
+
@staticmethod
def check(testcase, result):
if not result: