diff options
author | Leo Wang <grakiss.wanglei@huawei.com> | 2016-09-20 07:51:11 -0400 |
---|---|---|
committer | Leo Wang <grakiss.wanglei@huawei.com> | 2016-09-21 03:35:54 -0400 |
commit | d8ee3fd2cb9e221466e49703a25e9b7e1343be62 (patch) | |
tree | 91ec95ae9af8795c4707c4ccf0dd79235568747e /scripts | |
parent | 9a4faf7c4bf22b7683e89d1b287b1a1389657233 (diff) |
save dovetail report to disk
JIRA: DOVETAIL-16
Change-Id: I8aab0b34425b698fee556ef97d3b0942b1b149d2
Signed-off-by: Leo Wang <grakiss.wanglei@huawei.com>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/conf/dovetail_config.yml | 1 | ||||
-rw-r--r-- | scripts/report.py | 74 |
2 files changed, 58 insertions, 17 deletions
diff --git a/scripts/conf/dovetail_config.yml b/scripts/conf/dovetail_config.yml index b674a190..57d6e894 100644 --- a/scripts/conf/dovetail_config.yml +++ b/scripts/conf/dovetail_config.yml @@ -1,6 +1,7 @@ work_dir: /home/opnfv/dovetail result_dir: /home/opnfv/dovetail/results +report_file: 'dovetail_report.txt' extra_config: - functest_config.yml diff --git a/scripts/report.py b/scripts/report.py index 516ea069..d92929f2 100644 --- a/scripts/report.py +++ b/scripts/report.py @@ -52,20 +52,30 @@ class Report: report += '+-----------------------------------------------------------------------------+\n' logger.info(report) + cls.save(report) return report + #save to disk as default + @classmethod + def save(cls, report): + report_file_path = dovetail_config['report_file'] + try: + with open(os.path.join(dovetail_config['result_dir'], report_file_path),'w') as report_file: + report_file.write(report) + logger.info('save report to %s' % report_file_path) + except Exception as e: + logger.error('Failed to save: %s' % report_file_path) + @classmethod def get_result(cls, testcase): script_testcase = testcase.script_testcase() type = testcase.script_type() + crawler = CrawlerFactory.create(type) if script_testcase in cls.results[type]: return cls.results[type][script_testcase] - if dovetail_config[type]['result']['store_type'] == 'file': - result = cls.get_results_from_file(type) - else: - result = cls.get_results_from_db(type, script_testcase) + result = crawler.crawl(script_testcase) if result is not None: cls.results[type][script_testcase] = result @@ -76,21 +86,33 @@ class Report: logger.debug('testcase: %s -> result acquired retry:%d' % (script_testcase, retry)) return result - @classmethod - def get_results_from_db(cls, type, testcase): - #url = 'http://testresults.opnfv.org/test/api/v1/results?case=%s&last=1' % testcase - url = dovetail_config[type]['result']['db_url'] % testcase - 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)) - return None +class CrawlerFactory: @classmethod - def get_results_from_file(cls, type, testcase=None): - file_path = os.path.join(dovetail_config['result_dir'],dovetail_config[type]['result']['file_path']) + def create(cls, type): + if type == 'functest': + return FunctestCrawler() + + if type == 'yardstick': + return YardstickCrawler() + + return None + +class FunctestCrawler: + + def __init__(self): + self.type = 'functest' + + def crawl(self, testcase=None): + store_type = dovetail_config[self.type]['result']['store_type'] + if store_type == 'file': + return self.crawl_from_file(testcase) + + if store_type == 'url': + return self.crawl_from_url(testcase) + + def crawl_from_file(self, testcase=None): + file_path = 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) return None @@ -119,6 +141,24 @@ class Report: logger.error('Cannot read content from the file: %s, exception: %s' % (file_path, e)) return None + def crawl_from_url(self, testcase=None): + url = dovetail_config[self.type]['result']['db_url'] % testcase + 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)) + return None + +class YardstickCrawler: + + def __init__(self): + self.type = 'yardstick' + + def crawl(self, testcase=None): + return None + class CheckerFactory: @classmethod |