diff options
author | Yiting.Li <liyiting@huawei.com> | 2015-12-22 17:11:12 -0800 |
---|---|---|
committer | Yiting.Li <liyiting@huawei.com> | 2015-12-22 17:11:12 -0800 |
commit | 8f1101df131a4d3e03b377738507d88b745831c0 (patch) | |
tree | 73f140474fcec2a77c85a453f6946957ca0742d1 /vstf/vstf/controller/reporters/reporter.py | |
parent | 1a24ebbda3f95600c0e7d5ed8661317a8ff7e265 (diff) |
Upload the contribution of vstf as bottleneck network framework.
End to End Performance test
JIRA:BOTTLENECK-29
Change-Id: Ib2c553c8b60d6cda9e7a7b52b737c9139f706ebd
Signed-off-by: Yiting.Li <liyiting@huawei.com>
Diffstat (limited to 'vstf/vstf/controller/reporters/reporter.py')
-rwxr-xr-x | vstf/vstf/controller/reporters/reporter.py | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/vstf/vstf/controller/reporters/reporter.py b/vstf/vstf/controller/reporters/reporter.py new file mode 100755 index 00000000..1c256c61 --- /dev/null +++ b/vstf/vstf/controller/reporters/reporter.py @@ -0,0 +1,110 @@ +#!/usr/bin/python +# -*- coding: utf8 -*- +# author: wly +# date: 2015-05-29 +# see license for license details +import os +import argparse +import logging +import time + +from vstf.controller.reporters.report.pdf.pdfcreator import PdfvSwitchCreator +from vstf.controller.reporters.report.html.htmlcreator import HtmlvSwitchCreator +from vstf.controller.reporters.report.data_factory import CommonData, TaskData, ScenarioData, HistoryData +from vstf.controller.database.dbinterface import DbManage +from vstf.controller.settings.mail_settings import MailSettings +from vstf.controller.reporters.mail.sendmail import SendMail +from vstf.controller.settings.html_settings import HtmlSettings +from vstf.controller.reporters.report.provider.html_provider import StyleProvider +import vstf.common.constants as cst + + +__version__ = ''' ''' +LOG = logging.getLogger(__name__) + + +class Report(object): + def __init__(self, dbase, rpath): + """ + + :type dbase: object DbManage + """ + self._dbase = dbase + self._rpath = "." + if os.path.exists(rpath): + self._rpath = rpath + + def create_pdf(self, taskid): + common_data = CommonData(taskid, self._dbase) + scenario_list = common_data.get_scenariolist() + history_data = HistoryData(taskid, self._dbase) + attach_list = [] + for scenario in scenario_list: + out_file = os.path.join(self._rpath, "vstf_report_%s_%s.pdf" % (scenario, time.strftime(cst.TIME_STR))) + LOG.info(out_file) + scenario_data = ScenarioData(taskid, self._dbase, scenario) + pdf = PdfvSwitchCreator(out_file, common_data, scenario_data, history_data) + if pdf: + pdf.create() + attach_list.append(out_file) + if attach_list: + self._mail_settings.mset_attach(attach_list) + + def create_html(self, taskid): + task_data = TaskData(taskid, self._dbase) + + html_settings = HtmlSettings() + LOG.info(html_settings.settings) + + provider = StyleProvider(html_settings.settings) + out_file = os.path.join(self._rpath, "mail.html") + LOG.info(out_file) + + html = HtmlvSwitchCreator(task_data, provider, out_file) + content = html.create() + + self._mail_settings.mset_subtype('html') + self._mail_settings.mset_content(content) + + def report(self, taskid, mail_off): + self._mail_settings = MailSettings() + mail = SendMail(self._mail_settings.settings) + self.create_pdf(taskid) + self.create_html(taskid) + if not mail_off: + mail.send() + + +def main(): + from vstf.common.log import setup_logging + setup_logging(level=logging.DEBUG, log_file="/var/log/vstf/vstf-reporter.log", clevel=logging.INFO) + + parser = argparse.ArgumentParser(add_help=True) + parser.add_argument('-rpath', + action='store', + default='./', + type=str, + help=" the path name of test results " + ) + parser.add_argument('-mail_off', + action='store_true', + help="is need send mail the for the report" + ) + parser.add_argument('--taskid', + action='store', + default=-1, + help="report depand of a history task id." + ) + args = parser.parse_args() + dbase = DbManage() + + report = Report(dbase, args.rpath) + if args.taskid == -1: + taskid = dbase.get_last_taskid() + else: + taskid = args.taskid + report.report(taskid, args.mail_off) + + +if __name__ == '__main__': + main() |