import utils.dovetail_logger as dt_logger
from utils.dovetail_config import DovetailConfig as dt_cfg
+import utils.dovetail_utils as dt_utils
from testcase import Testcase
dt_logger.Logger(__name__ + '.FunctestCrawler').getLogger()
def crawl(self, testcase=None):
- store_type = \
- dt_cfg.dovetail_config[self.type]['result']['store_type']
- if store_type == 'file':
+ report_dest = dt_cfg.dovetail_config['report_dest']
+ if report_dest.lower() == 'file':
return self.crawl_from_file(testcase)
- if store_type == 'url':
+ if report_dest.lower().startswith('http'):
return self.crawl_from_url(testcase)
def crawl_from_file(self, testcase=None):
dovetail_config = dt_cfg.dovetail_config
criteria = 'FAIL'
+ details = {}
timestart = 0
- testcase_duration = 0
+ timestop = 0
+ duration = 0
testcase_name = testcase.validate_testcase()
- json_results = {}
+ file_path = \
+ os.path.join(dovetail_config['result_dir'],
+ dovetail_config[self.type]['result']['file_path'])
+ if not os.path.exists(file_path):
+ self.logger.info('result file not found: %s', file_path)
+ return None
if testcase_name in dt_cfg.dovetail_config['functest_testcase']:
- file_path = \
- os.path.join(dovetail_config['result_dir'],
- dovetail_config[self.type]['result']['file_path'])
- if not os.path.exists(file_path):
- self.logger.info('result file not found: %s', file_path)
- return None
- with open(file_path, 'r') as f:
- for jsonfile in f:
- try:
- data = json.loads(jsonfile)
- if testcase_name == data['case_name']:
- criteria = data['details']['status']
- timestart = data['details']['timestart']
- testcase_duration = data['details']['duration']
- except Exception:
- continue
-
- json_results = {'criteria': criteria,
- 'details': {"timestart": timestart,
- "duration": testcase_duration,
- "tests": '', "failures": ''}}
+ complex_testcase = False
elif testcase_name in dt_cfg.dovetail_config['functest_testsuite']:
- file_path = \
- os.path.join(dovetail_config['result_dir'],
- dovetail_config[self.type]['result']['file_path'])
- if not os.path.exists(file_path):
- self.logger.info('result file not found: %s', file_path)
- return None
- tests = 0
- failed_num = 0
- error_case = ''
- skipped_case = ''
- with open(file_path, 'r') as f:
- for jsonfile in f:
- try:
- data = json.loads(jsonfile)
- if testcase_name == data['case_name']:
- criteria = data['details']['status']
- timestart = data['details']['timestart']
- testcase_duration = data['details']['duration']
+ complex_testcase = True
+ else:
+ self.logger.error("Wrong Functest test case %s.", testcase_name)
+ return None
+ with open(file_path, 'r') as f:
+ for jsonfile in f:
+ try:
+ data = json.loads(jsonfile)
+ if testcase_name == data['case_name']:
+ criteria = data['criteria']
+ timestart = data['start_date']
+ timestop = data['stop_date']
+ duration = dt_utils.get_duration(timestart, timestop,
+ self.logger)
+ if complex_testcase:
tests = data['details']['tests']
failed_num = data['details']['failures']
error_case = data['details']['errors']
skipped_case = data['details']['skipped']
- except Exception:
- continue
-
- json_results = {'criteria': criteria,
- 'details': {"timestart": timestart,
- "duration": testcase_duration,
- "tests": tests,
- "failures": failed_num,
- "errors": error_case,
- "skipped": skipped_case}}
+ details = {"tests": tests,
+ "failures": failed_num,
+ "errors": error_case,
+ "skipped": skipped_case}
+ except KeyError as e:
+ self.logger.error("Key error, exception: %s", e)
+ return None
+ except ValueError:
+ continue
+
+ json_results = {'criteria': criteria, 'timestart': timestart,
+ 'timestop': timestop, 'duration': duration,
+ 'details': details}
self.logger.debug('Results: %s', str(json_results))
return json_results
dt_logger.Logger(__name__ + '.YardstickCrawler').getLogger()
def crawl(self, testcase=None):
- store_type = \
- dt_cfg.dovetail_config[self.type]['result']['store_type']
- if store_type == 'file':
+ report_dest = dt_cfg.dovetail_config['report_dest']
+ if report_dest.lower() == 'file':
return self.crawl_from_file(testcase)
- if store_type == 'url':
+ if report_dest.lower().startswith('http'):
return self.crawl_from_url(testcase)
def crawl_from_file(self, testcase=None):
cls.logger = \
dt_logger.Logger(__name__ + '.FunctestChecker').getLogger()
+ @staticmethod
+ def get_sub_testcase(sub_testcase, result):
+ reg = sub_testcase + '[\s+\d+]'
+ find_reg = re.compile(reg)
+ match = find_reg.findall(result)
+ if match:
+ return True
+ return False
+
def check(self, testcase, db_result):
sub_testcase_list = testcase.sub_testcase()
testcase_passed = 'SKIP'
for sub_testcase in sub_testcase_list:
self.logger.debug('check sub_testcase:%s', sub_testcase)
- if sub_testcase in db_result['details']['errors']:
+ if self.get_sub_testcase(sub_testcase,
+ db_result['details']['errors']):
testcase.sub_testcase_passed(sub_testcase, 'FAIL')
testcase_passed = 'FAIL'
- elif sub_testcase in db_result['details']['skipped']:
+ continue
+ if self.get_sub_testcase(sub_testcase,
+ db_result['details']['skipped']):
testcase.sub_testcase_passed(sub_testcase, 'SKIP')
else:
testcase.sub_testcase_passed(sub_testcase, 'PASS')
def check_tc_result(testcase, logger):
+ result_dir = dt_cfg.dovetail_config['result_dir']
+ validate_type = testcase.validate_type()
+ functest_result = dt_cfg.dovetail_config['functest']['result']['file_path']
if dt_cfg.dovetail_config['report_dest'].startswith("http"):
- if testcase.validate_type() == 'yardstick':
- logger.info("Results have been stored with files.")
+ if validate_type.lower() == 'yardstick':
+ logger.info("Results have been stored with file %s.",
+ os.path.join(result_dir,
+ testcase.validate_testcase() + '.out'))
else:
if dt_utils.check_db_results(dt_cfg.dovetail_config['report_dest'],
dt_cfg.dovetail_config['build_tag'],
else:
logger.error("Fail to push results to database.")
if dt_cfg.dovetail_config['report_dest'] == "file":
- logger.info("Results have been stored with files.")
- result = Report.get_result(testcase)
- Report.check_result(testcase, result)
+ if validate_type.lower() == 'yardstick':
+ logger.info("Results have been stored with file %s.",
+ os.path.join(result_dir,
+ testcase.validate_testcase() + '.out'))
+ if validate_type.lower() == 'functest':
+ logger.info("Results have been stored with file %s.",
+ os.path.join(result_dir, functest_result))
+ # result = Report.get_result(testcase)
+ # Report.check_result(testcase, result)
def validate_input(input_dict, check_dict, logger):
if testsuite_validation and testarea_validation:
testsuite_yaml = load_testsuite(kwargs['testsuite'])
load_testcase()
- duration = run_test(testsuite_yaml, testarea, logger)
- if dt_cfg.dovetail_config['report_dest'] == "file":
- Report.generate(testsuite_yaml, testarea, duration)
+ run_test(testsuite_yaml, testarea, logger)
+ # if dt_cfg.dovetail_config['report_dest'] == "file":
+ # Report.generate(testsuite_yaml, testarea, duration)
else:
logger.error('invalid input commands, testsuite %s testarea %s',
kwargs['testsuite'], testarea)