summaryrefslogtreecommitdiffstats
path: root/dovetail/report.py
diff options
context:
space:
mode:
Diffstat (limited to 'dovetail/report.py')
-rw-r--r--dovetail/report.py95
1 files changed, 88 insertions, 7 deletions
diff --git a/dovetail/report.py b/dovetail/report.py
index 08780b88..fa6a0ba4 100644
--- a/dovetail/report.py
+++ b/dovetail/report.py
@@ -13,6 +13,7 @@ import urllib2
import re
import os
import datetime
+import tarfile
from pbr import version
@@ -25,7 +26,7 @@ from testcase import Testcase
class Report(object):
- results = {'functest': {}, 'yardstick': {}, 'shell': {}}
+ results = {'functest': {}, 'yardstick': {}, 'bottlenecks': {}, 'shell': {}}
logger = None
@@ -162,6 +163,17 @@ class Report(object):
# cls.save(report_txt)
return report_txt
+ @classmethod
+ def save_logs(cls):
+ logs_gz = "logs.tar.gz"
+ result_dir = dt_cfg.dovetail_config['result_dir']
+
+ with tarfile.open(os.path.join(result_dir, logs_gz), "w:gz") as f_out:
+ files = os.listdir(result_dir)
+ for f in files:
+ if f not in ['workspace']:
+ f_out.add(os.path.join(result_dir, f))
+
# save to disk as default
@classmethod
def save(cls, report):
@@ -339,6 +351,53 @@ class YardstickCrawler(object):
return None
+class BottlenecksCrawler(object):
+
+ logger = None
+
+ def __init__(self):
+ self.type = 'bottlenecks'
+ self.logger.debug('Create crawler: {}'.format(self.type))
+
+ @classmethod
+ def create_log(cls):
+ cls.logger = \
+ dt_logger.Logger(__name__ + '.BottlenecksCrawler').getLogger()
+
+ def crawl(self, testcase=None):
+ report_dest = dt_cfg.dovetail_config['report_dest']
+ if report_dest.lower() == 'file':
+ return self.crawl_from_file(testcase)
+
+ if report_dest.lower().startswith('http'):
+ return self.crawl_from_url(testcase)
+
+ def crawl_from_file(self, testcase=None):
+ file_path = os.path.join(dt_cfg.dovetail_config['result_dir'],
+ testcase.name() + '.out')
+ if not os.path.exists(file_path):
+ self.logger.error('Result file not found: {}'.format(file_path))
+ return None
+ criteria = 'FAIL'
+ with open(file_path, 'r') as f:
+ for jsonfile in f:
+ data = json.loads(jsonfile)
+ try:
+ if 'PASS' == data["data_body"]["result"]:
+ criteria = 'PASS'
+ else:
+ criteria = 'FAIL'
+ break
+ except KeyError as e:
+ self.logger.exception('Pass flag not found {}'.format(e))
+ json_results = {'criteria': criteria}
+ self.logger.debug('Results: {}'.format(str(json_results)))
+ return json_results
+
+ def crawl_from_url(self, testcase=None):
+ return None
+
+
class ShellCrawler(object):
def __init__(self):
@@ -364,6 +423,7 @@ class CrawlerFactory(object):
CRAWLER_MAP = {'functest': FunctestCrawler,
'yardstick': YardstickCrawler,
+ 'bottlenecks': BottlenecksCrawler,
'shell': ShellCrawler}
@classmethod
@@ -397,14 +457,16 @@ class FunctestChecker(object):
sub_testcase = re.sub("\[.*?\]", "", sub_testcase)
reg = sub_testcase + '[\s+\d+]'
find_reg = re.compile(reg)
- match = find_reg.findall(result)
- if match:
- return True
+ for tc in result:
+ match = find_reg.findall(tc)
+ if match:
+ return True
reg = sub_testcase + '$'
find_reg = re.compile(reg)
- match = find_reg.findall(result)
- if match:
- return True
+ for tc in result:
+ match = find_reg.findall(tc)
+ if match:
+ return True
return False
def check(self, testcase, db_result):
@@ -466,6 +528,24 @@ class YardstickChecker(object):
return
+class BottlenecksChecker(object):
+
+ logger = None
+
+ @classmethod
+ def create_log(cls):
+ cls.logger = \
+ dt_logger.Logger(__name__ + '.BottlenecksChecker').getLogger()
+
+ @staticmethod
+ def check(testcase, result):
+ if not result:
+ testcase.passed('FAIL')
+ else:
+ testcase.passed(result['criteria'])
+ return
+
+
class ShellChecker(object):
@staticmethod
@@ -480,6 +560,7 @@ class CheckerFactory(object):
CHECKER_MAP = {'functest': FunctestChecker,
'yardstick': YardstickChecker,
+ 'bottlenecks': BottlenecksChecker,
'shell': ShellChecker}
@classmethod