summaryrefslogtreecommitdiffstats
path: root/vstf/vstf/controller/reporters
diff options
context:
space:
mode:
Diffstat (limited to 'vstf/vstf/controller/reporters')
-rwxr-xr-xvstf/vstf/controller/reporters/__init__.py21
-rwxr-xr-xvstf/vstf/controller/reporters/mail/__init__.py21
-rwxr-xr-xvstf/vstf/controller/reporters/mail/mail.py9
-rwxr-xr-xvstf/vstf/controller/reporters/mail/sendmail.py15
-rwxr-xr-xvstf/vstf/controller/reporters/report/__init__.py22
-rwxr-xr-xvstf/vstf/controller/reporters/report/candy_generator.py138
-rwxr-xr-xvstf/vstf/controller/reporters/report/data_factory.py131
-rwxr-xr-xvstf/vstf/controller/reporters/report/html/__init__.py21
-rwxr-xr-xvstf/vstf/controller/reporters/report/html/html_base.py40
-rwxr-xr-xvstf/vstf/controller/reporters/report/html/html_text.py68
-rwxr-xr-xvstf/vstf/controller/reporters/report/html/htmlcreator.py162
-rwxr-xr-xvstf/vstf/controller/reporters/report/pdf/__init__.py21
-rwxr-xr-xvstf/vstf/controller/reporters/report/pdf/element.py14
-rwxr-xr-xvstf/vstf/controller/reporters/report/pdf/pdfcreator.py515
-rwxr-xr-xvstf/vstf/controller/reporters/report/pdf/pdftemplate.py31
-rwxr-xr-xvstf/vstf/controller/reporters/report/pdf/story.py47
-rwxr-xr-xvstf/vstf/controller/reporters/report/pdf/styles.py32
-rwxr-xr-xvstf/vstf/controller/reporters/report/provider/__init__.py20
-rwxr-xr-xvstf/vstf/controller/reporters/report/provider/html_provider.py68
-rwxr-xr-xvstf/vstf/controller/reporters/report/provider/pdf_provider.py51
-rwxr-xr-xvstf/vstf/controller/reporters/reporter.py58
21 files changed, 609 insertions, 896 deletions
diff --git a/vstf/vstf/controller/reporters/__init__.py b/vstf/vstf/controller/reporters/__init__.py
index 89dcd4e2..df7d24d0 100755
--- a/vstf/vstf/controller/reporters/__init__.py
+++ b/vstf/vstf/controller/reporters/__init__.py
@@ -1,14 +1,9 @@
-# Copyright Huawei Technologies Co., Ltd. 1998-2015.
-# All Rights Reserved.
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
#
-# Licensed under the Apache License, Version 2.0 (the License); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an AS IS BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
diff --git a/vstf/vstf/controller/reporters/mail/__init__.py b/vstf/vstf/controller/reporters/mail/__init__.py
index 89dcd4e2..df7d24d0 100755
--- a/vstf/vstf/controller/reporters/mail/__init__.py
+++ b/vstf/vstf/controller/reporters/mail/__init__.py
@@ -1,14 +1,9 @@
-# Copyright Huawei Technologies Co., Ltd. 1998-2015.
-# All Rights Reserved.
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
#
-# Licensed under the Apache License, Version 2.0 (the License); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an AS IS BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
diff --git a/vstf/vstf/controller/reporters/mail/mail.py b/vstf/vstf/controller/reporters/mail/mail.py
index 42d60b1a..2241d9ad 100755
--- a/vstf/vstf/controller/reporters/mail/mail.py
+++ b/vstf/vstf/controller/reporters/mail/mail.py
@@ -1,3 +1,12 @@
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
import smtplib
import logging
import os
diff --git a/vstf/vstf/controller/reporters/mail/sendmail.py b/vstf/vstf/controller/reporters/mail/sendmail.py
index ecc6fe93..a4d7bb0a 100755
--- a/vstf/vstf/controller/reporters/mail/sendmail.py
+++ b/vstf/vstf/controller/reporters/mail/sendmail.py
@@ -1,9 +1,12 @@
-#!/usr/bin/python
-# -*- coding: utf8 -*-
-# author: wly
-# date: 2015-09-07
-# see license for license details
-__version__ = ''' '''
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
import logging
from vstf.controller.reporters.mail.mail import Mail
diff --git a/vstf/vstf/controller/reporters/report/__init__.py b/vstf/vstf/controller/reporters/report/__init__.py
index 89dcd4e2..547db686 100755
--- a/vstf/vstf/controller/reporters/report/__init__.py
+++ b/vstf/vstf/controller/reporters/report/__init__.py
@@ -1,14 +1,10 @@
-# Copyright Huawei Technologies Co., Ltd. 1998-2015.
-# All Rights Reserved.
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
#
-# Licensed under the Apache License, Version 2.0 (the License); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an AS IS BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+
diff --git a/vstf/vstf/controller/reporters/report/candy_generator.py b/vstf/vstf/controller/reporters/report/candy_generator.py
new file mode 100755
index 00000000..ea296550
--- /dev/null
+++ b/vstf/vstf/controller/reporters/report/candy_generator.py
@@ -0,0 +1,138 @@
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+from vstf.controller.settings.template_settings import TemplateSettings
+from vstf.controller.reporters.report.data_factory import TaskData
+from vstf.controller.database.dbinterface import DbManage
+import vstf.common.candy_text as candy
+import logging
+LOG = logging.getLogger(__name__)
+
+
+class CandyGenerator(object):
+ def __init__(self, task):
+ self._task = task
+
+ def create(self, scenario):
+ context = {}
+
+ sn = 1
+ chapterid = 1
+ name = candy.tuple2text(sn, candy.chapter, chapterid)
+ context[name] = self.create_env()
+
+ sn += 1
+ chapterid += 1
+ name = candy.tuple2text(sn, candy.chapter, chapterid)
+ context[name] = self.create_scenario(scenario)
+
+ template = TemplateSettings()
+ template.set_context(context)
+ LOG.info(template.settings)
+
+ def create_all(self):
+ context = {}
+
+ sn = 1
+ chapterid = 1
+ name = candy.tuple2text(sn, candy.chapter, chapterid)
+ context[name] = self.create_env()
+
+ scenarios = self._task.common.get_scenariolist()
+ for scenario in scenarios:
+ sn += 1
+ chapterid += 1
+ name = candy.tuple2text(sn, candy.chapter, chapterid)
+ context[name] = self.create_scenario(scenario)
+
+ template = TemplateSettings()
+ template.set_context(context)
+ LOG.info(template.settings)
+
+ def create_env(self):
+ env = {
+ "01##title#1": ["System Environment"],
+ "02##table#2": self._task.common.get_systeminfo()
+ }
+ return env
+
+ def create_scenario(self, scenario):
+ scenario_chapter = {
+ "01##title#1": ["Scenario Result"]
+ }
+ scenario_data = getattr(self._task, scenario)
+ test_list = scenario_data.get_testlist()
+ sectionid = 0
+ sn = 1
+ for test in test_list:
+ sn += 1
+ sectionid += 1
+ name = candy.tuple2text(sn, candy.section, sectionid)
+ testid = test.TestID
+ case = test.CaseTag.decode()
+ ttype = test.Type.decode()
+
+ params_info = [
+ " Case: " + case,
+ " Test tool: " + test.Tools.decode(),
+ " vSwitch: " + test.Switch.decode(),
+ " Protocol: " + test.Protocol.decode(),
+ " Type: " + ttype
+ ]
+ if ttype in ["frameloss", "throughput"]:
+ draw = {
+ "style": 1,
+ "node": candy.plot,
+ "data": scenario_data.get_framerate_chartdata(case, ttype)
+ }
+ table = scenario_data.get_ratedata(testid, ttype)
+ else:
+ draw = {
+ "style": 1,
+ "node": candy.chart,
+ "data": scenario_data.get_latency_bardata(case)
+ }
+ table = scenario_data.get_latency_tabledata(case)
+ test_section = self.create_test(sectionid, params_info, table, draw)
+ scenario_chapter[name] = test_section
+
+ return scenario_chapter
+
+ def create_test(self, section, info, table, draw):
+ """
+
+ :rtype : dict
+ """
+ sn = 7
+ draw_name = candy.tuple2text(sn, draw["node"], draw["style"])
+ case_section = {
+ "01##title#2": ["Test ID: %s" % section],
+ "02##paragraph#2": ["Parameter"],
+ "03##paragraph#3": info,
+ "04##paragraph#2": ["Result"],
+ "05##table#2": table,
+ "06##space#2": 2,
+ draw_name: draw["data"]
+ }
+ return case_section
+
+
+def main():
+ from vstf.common.log import setup_logging
+ setup_logging(level=logging.DEBUG, log_file="/var/log/vstf/vstf-candy.log", clevel=logging.INFO)
+
+ dbase = DbManage()
+ taskid = dbase.get_last_taskid()
+ task = TaskData(taskid, dbase)
+ creator = CandyGenerator(task)
+
+ creator.create("Tn")
+if __name__ == '__main__':
+ main()
+
diff --git a/vstf/vstf/controller/reporters/report/data_factory.py b/vstf/vstf/controller/reporters/report/data_factory.py
index 39c534b6..f9fc69d9 100755
--- a/vstf/vstf/controller/reporters/report/data_factory.py
+++ b/vstf/vstf/controller/reporters/report/data_factory.py
@@ -1,11 +1,14 @@
-#!/usr/bin/python
-# -*- coding: utf8 -*-
-# author: wly
-# date: 2015-07-29
-# see license for license details
-__version__ = ''' '''
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
from vstf.controller.database.dbinterface import DbManage
+import vstf.common.constants as cst
class DataProvider(object):
@@ -15,59 +18,12 @@ class DataProvider(object):
class CommonData(DataProvider):
- def get_components(self):
- result = []
- query = self._dbase.query_exten_info(self._taskid)
- print "CommonData", query
- for item in query:
- if item[2]:
- context = "%s:%s(%s)" % (item[0], item[1], item[2])
- else:
- context = "%s:%s" % (item[0], item[1])
- result.append(context)
- return result
-
- def get_software(self):
- result = [
- " Host OS: ubuntu 14.04.2",
- " Guest OS: ubuntu 12.04.4"
- ]
- return result
-
- def get_hardware(self):
- result = [
- " Server: Dell R920",
- " CPU: E7-8893/2P/3.4GHz/10-Cores/37.5M-L3C",
- " MEM: 128G",
- " NIC: Intel 82599"
- ]
- return result
-
def get_taskname(self):
return self._dbase.query_taskname(self._taskid)
- def get_gitinfo_tabledata(self):
- result = []
- return result
-
- def get_profileparameters_tabledData(self):
- result = [
- ]
- return result
-
- def get_testingoptions_tabledata(self):
- result = [
- ]
- return result
-
- def get_systeminfo_tabledata(self):
- result = [
- ]
- return result
-
def get_systeminfo(self):
systable = [
- ['host', 'Server', 'CPU', 'MEM', 'NIC', 'OS'],
+ ['Host', 'Server', 'CPU', 'MEM', 'NIC', 'OS'],
]
query = self._dbase.query_task_host_list(self._taskid)
query = map(lambda x: list(x), query)
@@ -103,14 +59,6 @@ class CommonData(DataProvider):
return True
return False
- def get_contact(self):
- result = [
- "Name: xxx",
- "ID: xxxxxxxx",
- "Email: xxxx@xxx.com"
- ]
- return result
-
def get_casename(self, case):
return self._dbase.query_casename(case)
@@ -124,23 +72,6 @@ class ScenarioData(DataProvider):
DataProvider.__init__(self, taskid, dbase)
self._scenario = scenario
- def get_covertitle(self):
- result = [
- "",
- "",
- "Elastic Virtual Switching Performance "
- "Test Report",
- "Scenario %s" % (self._scenario)
- ]
- return result
-
- def get_test(self):
- result = [
- "Scenario: %s" % (self._scenario),
- "Configuration: without VLAN",
- ]
- return result
-
def get_test_tools(self, case):
query = self._dbase.query_casetools(self._taskid, case)
result = map(lambda x: list(x), query)
@@ -157,6 +88,13 @@ class ScenarioData(DataProvider):
else:
return result
+ def get_testlist(self):
+ query = self._dbase.query_testlist(self._taskid, self._scenario)
+ result = []
+ for item in query:
+ result.append(item.__dict__)
+ return query
+
def is_provider_start(self, case, provider):
count = self._dbase.query_case_provider_count(self._taskid, case, provider)
if count:
@@ -231,12 +169,27 @@ class ScenarioData(DataProvider):
]
return table_head + table_body
+ def get_ratedata(self, testid, test_type):
+ table_head = [
+ ["FrameSize (bytes)", "Bandwidth(Mpps)", "Load (%)", "CPU Usage(%)", "Mpps/Ghz", "AvgLatency(uSec)"],
+ ]
+ query = self._dbase.query_testdata(testid, test_type)
+ table_body = []
+ for item in query:
+ table_body.append([item.AvgFrameSize, item.Bandwidth, item.OfferedLoad, item.CPU, item.MppspGhz,
+ item.AverageLatency])
+ result = []
+ if table_body:
+ result = table_head + table_body
+ return result
+
def get_tabledata(self, case, test_type, item):
type_dict = {
"FrameSize": "FrameSize (byte)",
"fastlink": "fastlink",
"l2switch": "l2switch",
"rdp": "kernel rdp",
+ None: "ovs",
"line": "line speed"
}
item_dict = {
@@ -244,11 +197,10 @@ class ScenarioData(DataProvider):
"Mpps": " ",
"Avg": " ",
}
- provider_list = ["fastlink", "rdp", "l2switch"]
table = []
line_speed = 20.0 if case in ["Tn-2v", "Tn-2"] else 10.0
- for provider in provider_list:
+ for provider in cst.PROVIDERS:
if self.is_provider_start(case, provider):
if item == 'Percent':
query = self._dbase.query_load(self._taskid, case, provider, test_type)
@@ -260,9 +212,9 @@ class ScenarioData(DataProvider):
if query:
table_head = [[type_dict["FrameSize"]] + map(lambda x: " %4d " % (x), query[0])]
if item == "Avg":
- data = map(lambda x: item_dict[item] + "%.1f" % (x) + item_dict[item], query[1])
+ data = map(lambda x: item_dict[item] + "%.1f" % x + item_dict[item], query[1])
else:
- data = map(lambda x: item_dict[item] + "%.2f" % (x) + item_dict[item], query[1])
+ data = map(lambda x: item_dict[item] + "%.2f" % x + item_dict[item], query[1])
if item == "Mpps":
line_table = map(lambda x: "%.2f" % (line_speed * 1000 / (8 * (x + 20))), query[0])
table.append([type_dict[provider]] + data)
@@ -362,7 +314,7 @@ class TaskData(object):
class HistoryData(DataProvider):
def get_data(self, task_list, case, provider, ttype, item):
"""
- @provider in ["fastlink", "rdp", "l2switch"]
+ @provider in ["fastlink", "rdp", "l2switch", ""]
@ttype in ["throughput", "frameloss", "latency"]
@item in ["avg", "ratep", "load"]
"""
@@ -415,7 +367,6 @@ class HistoryData(DataProvider):
return task_list
def get_history_info(self, case):
- providers = ["fastlink", "rdp", "l2switch"]
provider_dict = {"fastlink": "Fast Link ", "l2switch": "L2Switch ", "rdp": "Kernel RDP "}
ttype_dict = {
"throughput": "Throughput Testing ",
@@ -431,15 +382,14 @@ class HistoryData(DataProvider):
task_list = self.get_tasklist()
result = []
- ttypes = ["throughput", "frameloss", "latency"]
- for ttype in ttypes:
+ for ttype in cst.TTYPES:
content = {}
if ttype == "latency":
item = "avg"
else:
item = "ratep"
- for provider in providers:
+ for provider in cst.PROVIDERS:
table_data = self.get_data(task_list, case, provider, ttype, item)
if table_data:
data = {
@@ -451,9 +401,7 @@ class HistoryData(DataProvider):
content["data"].append(data)
if content:
result.append(content)
- print "xxxxxxxxxxxxxx"
print result
- print "xxxxxxxxxxxxxx"
return result
@@ -475,11 +423,10 @@ def unit_test():
case = "Tn-1"
- providers = ["fastlink", "rdp", "l2switch"]
ttypes = ["throughput", "frameloss"]
items = ["ratep", "load"]
- for provider in providers:
+ for provider in cst.PROVIDERS:
for ttype in ttypes:
for item in items:
print provider
diff --git a/vstf/vstf/controller/reporters/report/html/__init__.py b/vstf/vstf/controller/reporters/report/html/__init__.py
index 89dcd4e2..df7d24d0 100755
--- a/vstf/vstf/controller/reporters/report/html/__init__.py
+++ b/vstf/vstf/controller/reporters/report/html/__init__.py
@@ -1,14 +1,9 @@
-# Copyright Huawei Technologies Co., Ltd. 1998-2015.
-# All Rights Reserved.
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
#
-# Licensed under the Apache License, Version 2.0 (the License); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an AS IS BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
diff --git a/vstf/vstf/controller/reporters/report/html/html_base.py b/vstf/vstf/controller/reporters/report/html/html_base.py
index 270ef394..36be5981 100755
--- a/vstf/vstf/controller/reporters/report/html/html_base.py
+++ b/vstf/vstf/controller/reporters/report/html/html_base.py
@@ -1,41 +1,43 @@
-#!/usr/bin/python
-# -*- coding: utf8 -*-
-# author: wly
-# date: 2015-09.25
-# see license for license details
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
__version__ = ''' '''
import os
-from vstf.common.pyhtml import *
+import vstf.common.pyhtml as pyhtm
class HtmlBase(object):
- def __init__(self, provider, ofile='text.html'):
- self._page = PyHtml('HtmlBase Text')
- self._ofile = ofile
+ def __init__(self, provider):
+ self._page = pyhtm.PyHtml('Html Text')
self._provider = provider
- self._chapter = 1
- def save(self):
- if self._ofile:
- os.system('rm -rf %s' % self._ofile)
- self._page.output(self._ofile)
+ def save(self, ofile):
+ if ofile:
+ os.system('rm -rf %s' % ofile)
+ self._page.output(ofile)
def as_string(self):
return self._page.as_string()
def add_table(self, data):
- self._page.add_table(data)
+ if data and zip(*data):
+ self._page.add_table(data)
def add_style(self):
- style = self._provider.get_style()
+ style = self._provider.get_style
self._page.add_style(style)
- def create(self, is_save=True):
+ def create(self, ofile='text.html'):
self.add_style()
self.create_story()
- if is_save:
- self.save()
+ self.save(ofile)
return self.as_string()
def create_story(self):
diff --git a/vstf/vstf/controller/reporters/report/html/html_text.py b/vstf/vstf/controller/reporters/report/html/html_text.py
deleted file mode 100755
index 86505b8f..00000000
--- a/vstf/vstf/controller/reporters/report/html/html_text.py
+++ /dev/null
@@ -1,68 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf8 -*-
-# author: wly
-# date: 2015-09-24
-# see license for license details
-__version__ = ''' '''
-
-import logging
-
-LOG = logging.getLogger(__name__)
-import vstf.common.constants as cst
-from vstf.controller.reporters.report.html.html_base import *
-
-
-class HtmlCreator(HtmlBase):
- def add_subject(self):
- title = self._provider.get_subject()
- self._page << H1(title)
-
- def add_ovs(self):
- title = "%s %s" % (self._chapter, self._provider.get_ovs_title())
- self._page << H2(title)
- data = self._provider.get_ovs_table()
- self.add_table(data)
- self._chapter += 1
-
- def add_result(self):
- title = "%s %s" % (self._chapter, self._provider.get_result_title())
- self._page << H2(title)
-
- section = 1
- for ttype in cst.TTYPES:
- data = self._provider.get_result_table(ttype)
- if data:
- title = "%s.%s %s" % (self._chapter, section, ttype.title())
- self._page << H3(title)
- self.add_table(data)
- section += 1
- self._chapter += 1
-
- def create_story(self):
- self.add_subject()
- self.add_ovs()
- self.add_result()
-
-
-def unit_test():
- from vstf.common.log import setup_logging
- setup_logging(level=logging.DEBUG, log_file="/var/log/html-test.log", clevel=logging.INFO)
-
- from vstf.controller.settings.html_settings import HtmlSettings
- from vstf.controller.settings.data_settings import DataSettings
-
- html_settings = HtmlSettings()
- LOG.info(html_settings.settings)
- data_settings = DataSettings()
- LOG.info(data_settings.settings)
-
- from vstf.controller.reporters.report.provider.html_provider import HtmlProvider
- provider = HtmlProvider(data_settings.settings, html_settings.settings)
- html = HtmlCreator(provider)
-
- result = html.create()
- print result
-
-
-if __name__ == '__main__':
- unit_test()
diff --git a/vstf/vstf/controller/reporters/report/html/htmlcreator.py b/vstf/vstf/controller/reporters/report/html/htmlcreator.py
index e6c75caf..1d150e28 100755
--- a/vstf/vstf/controller/reporters/report/html/htmlcreator.py
+++ b/vstf/vstf/controller/reporters/report/html/htmlcreator.py
@@ -1,117 +1,85 @@
-#!/usr/bin/python
-# -*- coding: utf8 -*-
-# author: wly
-# date: 2015-08-04
-# see license for license details
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
__version__ = ''' '''
import logging
-from vstf.controller.reporters.report.data_factory import TaskData
-from vstf.controller.database.dbinterface import DbManage
-from vstf.controller.reporters.report.html.html_base import *
+import vstf.common.candy_text as candy
+from vstf.controller.reporters.report.provider.html_provider import HtmlProvider
+from vstf.controller.settings.template_settings import TemplateSettings
+from vstf.controller.settings.html_settings import HtmlSettings
+from vstf.controller.reporters.report.html.html_base import HtmlBase, pyhtm
LOG = logging.getLogger(__name__)
-class HtmlvSwitchCreator(HtmlBase):
- def __init__(self, task_data, provider, ofile='creator.html'):
- HtmlBase.__init__(self, provider, ofile)
- self._task = task_data
- self._table_type = 'html'
-
+class HtmlCreator(HtmlBase):
def create_story(self):
- self.add_subject()
- self.add_gitinfo()
- self.add_envinfo()
- self.add_scenarios()
-
- def add_subject(self):
- job_name = "JOB_NAME: " + self._task.common.get_taskname()
- self._page << H2(job_name)
-
- def add_gitinfo(self):
- self._page << H2("Trigger and Repository Info")
-
- git_table = self._task.common.get_gitinfo_tabledata()
- if git_table:
- self.add_table(git_table)
-
- def add_envinfo(self):
- self._page << H2("System Environment Information")
- env_table = self._task.common.get_systeminfo()
- LOG.info(env_table)
- if env_table:
- self.add_table(env_table)
-
- def add_scenarios(self):
- scenario_list = self._task.common.get_scenariolist()
- self._page << H2("Scenario List: " + ', '.join(scenario_list))
- for scenario in scenario_list:
- self._page << H2("Scenario: " + scenario)
- data = getattr(self._task, scenario)
- self.add_scenario(data)
-
- def add_scenario(self, scenario_data):
- case_list = scenario_data.get_caselist()
- for case in case_list:
- self.add_case(scenario_data, case)
-
- def add_case(self, scenario_data, case):
- case_name = self._task.common.get_casename(case)
- title = "Case : %s (%s)" % (case, case_name)
- self._page << H2(title)
-
- provider_list = ["fastlink", "rdp", "l2switch"]
- provider_dict = {"fastlink": "Fast Link", "l2switch": "L2Switch", "rdp": "Kernel RDP"}
-
- for provider in provider_list:
- if scenario_data.is_provider_start(case, provider):
- title = " %s (%s_%s)" % (provider_dict[provider], case_name, provider)
- self._page << H3(title)
- test_types = ["throughput", "frameloss"]
- for test_type in test_types:
- if scenario_data.is_type_provider_start(case, provider, test_type):
- self.add_casedata(scenario_data, case, provider, test_type)
-
- if scenario_data.is_latency_start(case):
- self.add_latency_result(scenario_data, case)
-
- def add_casedata(self, scenario_data, case, provider, test_type):
- table_content = scenario_data.get_summary_tabledata(case, provider, test_type, self._table_type)
- if table_content:
- title = "Test type:%s" % (test_type)
- self._page << H4(title)
- self.add_table(table_content)
-
- def add_latency_result(self, scenario_data, case):
- title = "Average Latency Summary"
- table_content = scenario_data.get_latency_tabledata(case)
- if table_content:
- self._page << H2(title)
- self.add_table(table_content)
+ self.add_context()
+
+ def add_context(self):
+ context = self._provider.get_context
+ self._raw_context(context)
+
+ def _raw_context(self, context, ci=0, si=0, ui=0, level=-1):
+ _story = []
+ for key, value in sorted(context.items()):
+ LOG.info(key)
+ LOG.info(value)
+ _sn, _node, _style = candy.text2tuple(key)
+ if _node in candy.dom:
+ if _node == candy.chapter:
+ ci = _style
+ elif _node == candy.section:
+ si = _style
+ else:
+ ui = _style
+ self._raw_context(value, ci, si, ui, level + 1)
+
+ else:
+ LOG.info("node: %s %s" % (_node, candy.title))
+ if _node == candy.title:
+ assert value
+ if level in range(len(candy.dom)):
+ if level == 0:
+ value[0] = "Chapter %s %s" % (ci, value[0])
+ for title in value:
+ self._page << pyhtm.H2(title)
+ elif level == 1:
+ value[0] = "%s.%s %s" % (ci, si, value[0])
+ for title in value:
+ self._page << pyhtm.H3(title)
+ else:
+ value[0] = "%s.%s.%s %s" % (ci, si, ui, value[0])
+ for title in value:
+ self._page << pyhtm.H3(title)
+
+ elif _node == candy.table:
+ self.add_table(value)
+ elif _node == candy.paragraph:
+ for para in value:
+ para = pyhtm.space(2) + para
+ self._page << pyhtm.P(para)
def unit_test():
from vstf.common.log import setup_logging
setup_logging(level=logging.DEBUG, log_file="/var/log/html-creator.log", clevel=logging.INFO)
- dbase = DbManage()
- taskid = dbase.get_last_taskid()
- task_data = TaskData(taskid, dbase)
-
- from vstf.controller.settings.html_settings import HtmlSettings
- from vstf.controller.reporters.report.provider.html_provider import StyleProvider
+ out_file = "vstf_report.html"
+ info = TemplateSettings()
html_settings = HtmlSettings()
- LOG.info(html_settings.settings)
-
- provider = StyleProvider(html_settings.settings)
- html = HtmlvSwitchCreator(task_data, provider)
-
- result = html.create(True)
- print result
-
+ provider = HtmlProvider(info.settings, html_settings.settings)
+ reporter = HtmlCreator(provider)
+ reporter.create(out_file)
if __name__ == '__main__':
unit_test()
diff --git a/vstf/vstf/controller/reporters/report/pdf/__init__.py b/vstf/vstf/controller/reporters/report/pdf/__init__.py
index 89dcd4e2..df7d24d0 100755
--- a/vstf/vstf/controller/reporters/report/pdf/__init__.py
+++ b/vstf/vstf/controller/reporters/report/pdf/__init__.py
@@ -1,14 +1,9 @@
-# Copyright Huawei Technologies Co., Ltd. 1998-2015.
-# All Rights Reserved.
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
#
-# Licensed under the Apache License, Version 2.0 (the License); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an AS IS BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
diff --git a/vstf/vstf/controller/reporters/report/pdf/element.py b/vstf/vstf/controller/reporters/report/pdf/element.py
index 2528f2c5..78d1c59b 100755
--- a/vstf/vstf/controller/reporters/report/pdf/element.py
+++ b/vstf/vstf/controller/reporters/report/pdf/element.py
@@ -1,8 +1,12 @@
-#!/usr/bin/python
-# -*- coding: utf8 -*-
-# author: wly
-# date: 2015-05-04
-# see license for license details
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
__version__ = ''' '''
__doc__ = """
it contains the base element for pdf
diff --git a/vstf/vstf/controller/reporters/report/pdf/pdfcreator.py b/vstf/vstf/controller/reporters/report/pdf/pdfcreator.py
index 50b3bc65..4f7bd2a8 100755
--- a/vstf/vstf/controller/reporters/report/pdf/pdfcreator.py
+++ b/vstf/vstf/controller/reporters/report/pdf/pdfcreator.py
@@ -1,446 +1,129 @@
-#!/usr/bin/python
-# -*- coding: utf8 -*-
-# author: wly
-# date: 2015-05-29
-# see license for license details
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
__version__ = ''' '''
-import os
-from vstf.controller.reporters.report.pdf.styles import TemplateStyle
from vstf.controller.reporters.report.pdf.pdftemplate import PdfVswitch
-from vstf.controller.reporters.report.pdf.story import TitleStory, SpaceStory, ImageStory, LineChartStory, \
- LinePlotStory, uTableStory, Story, TableOfContentsStory, PageBreakStory, ParagraphStory, BarChartStory, cTableStory
-from vstf.controller.reporters.report.data_factory import CommonData, ScenarioData, HistoryData
-from vstf.controller.database.dbinterface import DbManage
-import vstf.controller
-
+from vstf.controller.reporters.report.pdf.story import TitleStory, SpaceStory, ImageStory, TableStory, \
+ LinePlotStory, Story, TableOfContentsStory, PageBreakStory, ParagraphStory, BarChartStory
+import vstf.common.candy_text as candy
+from vstf.controller.reporters.report.provider.pdf_provider import PdfProvider
+from vstf.controller.settings.template_settings import TemplateSettings
-class LetterOrder(object):
- def __init__(self):
- self.lettertable = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- self._cur = 0
- self._len = len(self.lettertable)
-
- def get(self):
- return self.lettertable[self._cur]
-
- def pre(self):
- self._cur = (self._cur + self._len - 1) % self._len
+import os
+import logging
- def next(self):
- self._cur = (self._cur + 1) % self._len
+LOG = logging.getLogger(__name__)
-class PdfBase(object):
- def __init__(self):
- self._case = ''
- self._ofile = ''
- self._title = []
+class PdfCreator(object):
+ def __init__(self, provider):
+ self._provider = provider
self._story = []
- self._rootdir = os.path.dirname(vstf.controller.__file__) + '/'
self._pdf = None
def create_pdf(self):
- style = TemplateStyle(name='default')
- title = self._title
- logo = [self._rootdir + "res/logo.jpg"]
- header = ['']
- footer = [""]
- note = ['', '']
- output = [self._ofile]
- self._pdf = PdfFrameLoss(style, title, logo, header, footer, output, note)
+ theme = self._provider.get_theme
+ self._pdf = PdfVswitch(theme["title"],
+ theme["logo"],
+ theme["header"],
+ theme["footer"],
+ theme["note"],
+ theme["style"])
- def save_pdf(self):
- self._pdf.generate(self._story)
+ def save_pdf(self, ofile):
+ self._pdf.generate(self._story, ofile)
def add_coverpage(self):
story = Story()
story = PageBreakStory(story)
self._story += story.storylist
- def create_story(self):
- raise NotImplementedError("abstract PdfBase")
-
- def create(self):
- self.create_pdf()
- self.create_story()
- self.save_pdf()
-
-
-class PdfvSwitchCreator(PdfBase):
- def __init__(self, ofile, common_data, scenario_data, history_data):
- PdfBase.__init__(self)
- self._common = common_data
- self._result = scenario_data
- self._history = history_data
- self._ofile = ofile
- self._chapterid = 0
- self._appendixid = LetterOrder()
-
- def create_pdf(self):
- style = TemplateStyle(name='default')
- title = self._result.get_covertitle()
- logo = [self._rootdir + "res/logo.jpg"]
- header = ['']
- footer = [""]
- note = ['', '']
- output = [self._ofile]
- self._pdf = PdfVswitch(style, title, logo, header, footer, output, note)
-
- def get_chapterid(self):
- self._chapterid = self._chapterid + 1
- return self._chapterid
+ def add_contents(self):
+ if self._provider.ifcontents:
+ story = Story()
+ story = TableOfContentsStory(story)
+ self._story += story.storylist
def create_story(self):
self.add_coverpage()
- self.add_table_of_contents()
- # self.add_contact()
- # self.add_overview()
- self.add_scenario()
- # self.add_info()
- # self.add_appendix()
- self.add_historys()
-
- def add_info(self):
- self.add_systeminfo()
- self.add_gitinfo()
- self.add_profile_parameters()
- self.add_testing_options()
-
- def add_contact(self):
- story = Story()
- story = SpaceStory(story)
- title = ["", "", "", "Reporter"]
- body = self._common.get_contact()
- story = TitleStory(story, data=title, style=7)
- story = ParagraphStory(story, data=body)
- self._story += story.storylist
-
- def add_table_of_contents(self):
- story = Story()
- story = TableOfContentsStory(story)
- self._story += story.storylist
-
- def add_overview(self):
- story = Story()
- story = PageBreakStory(story)
-
- chapterid = self.get_chapterid()
- title = ["%d.Overview" % (chapterid)]
- body = [""]
- story = TitleStory(story, data=title, style=1)
- story = ParagraphStory(story, data=body)
-
- sectionid = 1
- title = ["%d.%d Components under Test" % (chapterid, sectionid)]
- body = self._common.get_components()
- story = TitleStory(story, data=title, style=2)
- story = ParagraphStory(story, data=body)
-
- sectionid = sectionid + 1
- title = ["%d.%d Test" % (chapterid, sectionid)]
- body = self._result.get_test()
- story = TitleStory(story, data=title, style=2)
- story = ParagraphStory(story, data=body)
-
- sectionid = sectionid + 1
- title = ["%d.%d Configuration" % (chapterid, sectionid)]
- story = TitleStory(story, data=title, style=2)
-
- title = ["Software"]
- body = self._common.get_software()
- story = TitleStory(story, data=title, style=6)
- story = ParagraphStory(story, data=body)
-
- title = ["Hardware"]
- body = self._common.get_hardware()
- story = TitleStory(story, data=title, style=6)
- story = ParagraphStory(story, data=body)
- self._story += story.storylist
-
- def add_scenario(self):
- case_list = self._result.get_caselist()
- for case in case_list:
- self.add_case(case)
-
- def add_case(self, case):
- story = Story()
- chapterid = self.get_chapterid()
-
- title = ["%d. Case : %s (%s)" % (chapterid, case, self._common.get_casename(case))]
-
- tools = self._result.get_test_tools(case)
- pic = self._common.get_casefigure(case, tools)
- print pic
-
- story = TitleStory(story, data=title, style=1)
- story = SpaceStory(story)
- story = ImageStory(story, data=[self._rootdir + pic])
- story = SpaceStory(story)
-
- sectionid = 1
- story = self.add_summary(story, chapterid, sectionid, case)
- story = SpaceStory(story)
-
- if self._result.is_throughput_start(case):
- sectionid = sectionid + 1
- story = self.add_throughput_result(story, chapterid, sectionid, case)
-
- if self._result.is_frameloss_start(case):
- sectionid = sectionid + 1
- story = self.add_frameloss_result(story, chapterid, sectionid, case)
-
- if self._result.is_latency_start(case):
- sectionid = sectionid + 1
- story = self.add_latency_result(story, chapterid, sectionid, case)
-
- story = SpaceStory(story)
- story = SpaceStory(story)
- self._story += story.storylist
-
- def add_summary(self, story, chapterid, sectionid, case):
- title = ["%d.%d Summary" % (chapterid, sectionid)]
- story = TitleStory(story, data=title, style=2)
- provider_list = ["fastlink", "rdp", "l2switch"]
- provider_dict = {"fastlink": "Fast Link", "l2switch": "L2Switch", "rdp": "Kernel RDP"}
- unitid = 1
- case_name = self._common.get_casename(case)
- for provider in provider_list:
- if self._result.is_provider_start(case, provider):
- title = ["%d.%d.%d %s (%s_%s)" % (
- chapterid, sectionid, unitid, provider_dict[provider], case_name, provider)]
- unitid = unitid + 1
- story = TitleStory(story, data=title, style=6)
- test_types = ["throughput", "frameloss"]
- for test_type in test_types:
- if self._result.is_type_provider_start(case, provider, test_type):
- story = self.add_summary_type(story, case, provider, test_type)
- return story
-
- def add_summary_type(self, story, case, provider, test_type):
- bar_list = [test_type, "latency"]
- for item in bar_list:
- bar_data = self._result.get_bardata(case, provider, item)
- story = SpaceStory(story)
- story = BarChartStory(story, data=bar_data)
-
- table_content = self._result.get_summary_tabledata(case, provider, test_type)
- story = SpaceStory(story)
- story = cTableStory(story, data=table_content, style=3)
- story = SpaceStory(story)
- return story
+ self.add_contents()
+ self.add_context()
- def add_throughput_result(self, story, chapterid, sectionid, case):
- title = ["%d.%d Throughput " % (chapterid, sectionid)]
- story = TitleStory(story, data=title, style=2)
- unitid = 1
- title = ["%d.%d.%d Summary" % (chapterid, sectionid, unitid)]
- story = TitleStory(story, data=title, style=6)
-
- test_type = "throughput"
- unit = 'RX Frame Rate'
- chart_data = self._result.get_frameloss_chartdata(case, test_type)
- table_data = self._result.get_frameloss_tabledata(case, test_type)
- title = [unit + ' (%)']
- story = TitleStory(story, data=title, style=6)
- # story = SpaceStory(story)
- # story = LinePlotStory(story, data=chart_data)
- story = SpaceStory(story)
- story = uTableStory(story, data=table_data)
- story = SpaceStory(story)
-
- unit = 'Frame Loss Rate'
- title = [unit + ' (Mpps)']
-
- chart_data = self._result.get_framerate_chartdata(case, test_type)
- table_data = self._result.get_framerate_tabledata(case, test_type)
- story = TitleStory(story, data=title, style=6)
- story = SpaceStory(story)
- story = LinePlotStory(story, data=chart_data)
- story = SpaceStory(story)
- story = uTableStory(story, data=table_data)
- story = SpaceStory(story)
- return story
-
- def add_frameloss_result(self, story, chapterid, sectionid, case):
- title = ["%d.%d Frame Loss Rate " % (chapterid, sectionid)]
- story = TitleStory(story, data=title, style=2)
- unitid = 1
- title = ["%d.%d.%d Summary" % (chapterid, sectionid, unitid)]
- story = TitleStory(story, data=title, style=6)
-
- test_type = "frameloss"
- unit = 'RX Frame Rate'
- chart_data = self._result.get_frameloss_chartdata(case, test_type)
- table_data = self._result.get_frameloss_tabledata(case, test_type)
- title = [unit + ' (%)']
- story = TitleStory(story, data=title, style=6)
- # story = SpaceStory(story)
- # story = LineChartStory(story, data=chart_data)
- story = SpaceStory(story)
- story = uTableStory(story, data=table_data)
- story = SpaceStory(story)
-
- unit = 'Frame Loss Rate'
- title = [unit + ' (Mpps)']
-
- chart_data = self._result.get_framerate_chartdata(case, test_type)
- table_data = self._result.get_framerate_tabledata(case, test_type)
- story = TitleStory(story, data=title, style=6)
- story = SpaceStory(story)
- story = LineChartStory(story, data=chart_data)
- story = SpaceStory(story)
- story = uTableStory(story, data=table_data)
- story = SpaceStory(story)
- return story
-
- def add_latency_result(self, story, chapterid, sectionid, case):
- title = ["%d.%d Latency " % (chapterid, sectionid)]
- story = TitleStory(story, data=title, style=2)
- unitid = 1
- title = ["%d.%d.%d Summary" % (chapterid, sectionid, unitid)]
- story = TitleStory(story, data=title, style=6)
-
- unit = 'Average Latency'
- title = [unit + ' (uSec)']
- # chart_data = self._result.get_latency_chartdata(case)
- bar_data = self._result.get_latency_bardata(case)
- table_data = self._result.get_latency_tabledata(case)
- story = TitleStory(story, data=title, style=6)
- story = SpaceStory(story)
- # story = LineChartStory(story, data=chart_data)
- story = BarChartStory(story, data=bar_data)
-
- story = SpaceStory(story)
- story = uTableStory(story, data=table_data)
- story = SpaceStory(story)
- return story
-
- def add_systeminfo(self):
- story = Story()
- chapterid = self.get_chapterid()
- story = SpaceStory(story)
- title = ["%d. System Information " % (chapterid)]
- story = PageBreakStory(story)
- story = TitleStory(story, data=title, style=1)
- table_content = self._common.get_systeminfo_tabledata()
- story = SpaceStory(story)
- story = cTableStory(story, data=table_content, style=0)
- story = SpaceStory(story)
- self._story += story.storylist
-
- def add_gitinfo(self):
- story = Story()
- chapterid = self.get_chapterid()
- title = ["%d. Git Repository Information " % (chapterid)]
- story = TitleStory(story, data=title, style=1)
-
- table_content = self._common.get_gitinfo_tabledata()
- if table_content:
- story = SpaceStory(story)
- story = cTableStory(story, data=table_content, style=5)
- story = SpaceStory(story)
- self._story += story.storylist
-
- def add_testing_options(self):
- story = Story()
- chapterid = self.get_chapterid()
- story = SpaceStory(story)
- title = ["%d. Testing Options" % (chapterid)]
-
- story = TitleStory(story, data=title, style=1)
- table_content = self._common.get_testingoptions_tabledata()
- story = SpaceStory(story)
- story = cTableStory(story, data=table_content, style=1)
- story = SpaceStory(story)
- self._story += story.storylist
-
- def add_profile_parameters(self):
- story = Story()
- chapterid = self.get_chapterid()
- story = PageBreakStory(story)
- title = ["%d. " % (chapterid)]
- story = TitleStory(story, data=title, style=1)
- table_content = self._common.get_profileparameters_tabledData()
- story = SpaceStory(story)
- story = cTableStory(story, data=table_content, style=2)
- story = SpaceStory(story)
- self._story += story.storylist
-
- def add_appendix(self):
- story = Story()
- story = PageBreakStory(story)
-
- title = ["<b>Appendix %s: vSwitching Testing Methodology</b>" % (self._appendixid.get())]
- self._appendixid.next()
- story = TitleStory(story, data=title, style=1)
- filename = "res/Traffic-types.jpg"
- story = SpaceStory(story)
- story = ImageStory(story, data=[self._rootdir + filename])
- # story = SpaceStory(story)
-
- title = ["Traffic Patterns: "]
- story = TitleStory(story, data=title, style=6)
-
- body = [
- "<b>Ti</b> - South North Traffic",
- "<b>Tu</b> - East Eest Traffic",
- "<b>Tn</b> - Physical host or VM loop back",
- "<b>Tnv</b> - Virtual Machine loop back",
- ]
- story = ParagraphStory(story, data=body)
-
- title = ["<b>Performance Testing Coverage </b> (version 0.1):"]
- story = TitleStory(story, data=title, style=6)
-
- table_content = self._common.get_introduct_tabledata()
- story = SpaceStory(story)
- story = cTableStory(story, data=table_content, style=4)
- self._story += story.storylist
-
- def add_historys(self):
- case_list = self._result.get_caselist()
- for case in case_list:
- history = self._history.get_history_info(case)
- if history:
- self.add_history(case, history)
-
- def add_history(self, case, history):
- story = Story()
- story = PageBreakStory(story)
-
- title = ["<b>Appendix %s : %s History Records</b>" % (self._appendixid.get(), case)]
- story = TitleStory(story, data=title, style=1)
-
- for i in range(len(history)):
- title = ["%s.%s %s" % (self._appendixid.get(), i, history[i]["title"])]
- story = TitleStory(story, data=title, style=2)
-
- section = history[i]["data"]
- for unit in section:
- title = [unit['title']]
- story = TitleStory(story, data=title, style=6)
- content = unit['data']
- story = uTableStory(story, data=content)
-
- self._appendixid.next()
- self._story += story.storylist
+ def create(self, ofile):
+ self.create_pdf()
+ self.create_story()
+ self.save_pdf(ofile)
+
+ def add_context(self):
+ context = self._provider.get_context
+ self._story += self._raw_context(context)
+
+ def _raw_context(self, context, ci=0, si=0, ui=0, level=-1):
+ _story = []
+ for key, value in sorted(context.items()):
+ LOG.info(key)
+ LOG.info(value)
+ _sn, _node, _style = candy.text2tuple(key)
+ if _node in candy.dom:
+ if _node == candy.chapter:
+ ci = _style
+ elif _node == candy.section:
+ si = _style
+ else:
+ ui = _style
+ _story += self._raw_context(value, ci, si, ui, level + 1)
+
+ else:
+ story = Story()
+ LOG.info("node: %s %s" % (_node, candy.title))
+ if _node == candy.title:
+ assert value
+ if level in range(len(candy.dom)):
+ if level == 0:
+ value[0] = "Chapter %s %s" % (ci, value[0])
+ story = PageBreakStory(story)
+ elif level == 1:
+ value[0] = "%s.%s %s" % (ci, si, value[0])
+ else:
+ value[0] = "%s.%s.%s %s" % (ci, si, ui, value[0])
+ LOG.info(value)
+ story = TitleStory(story, data=value, style=_style)
+ elif _node == candy.table:
+ story = TableStory(story, data=value, style=_style)
+ elif _node == candy.figure:
+ story = ImageStory(story, data=value, style=_style)
+ elif _node == candy.paragraph:
+ story = ParagraphStory(story, data=value, style=_style)
+ elif _node == candy.plot:
+ story = LinePlotStory(story, data=value, style=_style)
+ elif _node == candy.chart:
+ story = BarChartStory(story, data=value, style=_style)
+ elif _node == candy.space:
+ assert isinstance(value, int)
+ for i in range(value):
+ story = SpaceStory(story)
+ _story += story.storylist
+ return _story
def main():
- dbase = DbManage()
- taskid = dbase.get_last_taskid()
- common_data = CommonData(taskid, dbase)
- scenario_list = common_data.get_scenariolist()
- history_data = HistoryData(taskid, dbase)
- for scenario in scenario_list:
- out_file = "vstf_report_%s.pdf" % (scenario)
- scenario_data = ScenarioData(taskid, dbase, scenario)
- reporter = PdfvSwitchCreator(out_file, common_data, scenario_data, history_data)
- if reporter:
- reporter.create()
+ from vstf.common.log import setup_logging
+ setup_logging(level=logging.DEBUG, log_file="/var/log/pdf-creator.log", clevel=logging.INFO)
+
+ out_file = "vstf_report.pdf"
+ info = TemplateSettings()
+ provider = PdfProvider(info.settings)
+ reporter = PdfCreator(provider)
+ reporter.create(out_file)
if __name__ == '__main__':
main()
diff --git a/vstf/vstf/controller/reporters/report/pdf/pdftemplate.py b/vstf/vstf/controller/reporters/report/pdf/pdftemplate.py
index 819a5c57..69c65401 100755
--- a/vstf/vstf/controller/reporters/report/pdf/pdftemplate.py
+++ b/vstf/vstf/controller/reporters/report/pdf/pdftemplate.py
@@ -1,13 +1,21 @@
-#!/usr/bin/python
-# -*- coding: utf8 -*-
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
import time
from reportlab.platypus.doctemplate import SimpleDocTemplate
from reportlab.platypus import PageBreak
from vstf.controller.reporters.report.pdf.styles import TemplateStyle, ps_head_lv1, ps_head_lv2, ps_head_lv3
+import vstf.common.constants as cst
-class MyDocTemplate(SimpleDocTemplate):
+class BaseDocTemplate(SimpleDocTemplate):
def __init__(self, filename, **kw):
self.allowSplitting = 0
SimpleDocTemplate.__init__(self, filename, **kw)
@@ -25,17 +33,16 @@ class MyDocTemplate(SimpleDocTemplate):
self.notify('TOCEntry', (2, text, self.page - 1))
-class PdfTemplate:
- def __init__(self, style, title, logo, header, footer, output, note=None):
- self._style = style
+class PdfTemplate(object):
+ def __init__(self, title, logo, header, footer, note=[], style="default"):
+ self._style = TemplateStyle(name=style)
self._title = title
self._logo = logo[0]
- self._header = header[0]
+ #self._header = header[0]
self._footer = footer
- self._output = output[0]
self._note = note
- info = " Generated on %s " % time.strftime('%Y/%m/%d %H:%M:%S', time.localtime())
- self._note[0] += info
+ info = " Generated on %s " % time.strftime(cst.TIME_FORMAT2, time.localtime())
+ self._note += [info]
def myFirstPage(self, canvas, doc):
raise NotImplementedError("abstract StoryDecorator")
@@ -43,9 +50,9 @@ class PdfTemplate:
def myLaterPages(self, canvas, doc):
raise NotImplementedError("abstract StoryDecorator")
- def generate(self, story):
+ def generate(self, story, output):
sizes = (self._style.page_wight, self._style.page_height)
- doc = MyDocTemplate(self._output, pagesize=sizes)
+ doc = BaseDocTemplate(output, pagesize=sizes)
# doc.build(story, onFirstPage=self.myFirstPage, onLaterPages=self.myLaterPages)
doc.multiBuild(story, onFirstPage=self.myFirstPage, onLaterPages=self.myLaterPages)
diff --git a/vstf/vstf/controller/reporters/report/pdf/story.py b/vstf/vstf/controller/reporters/report/pdf/story.py
index 3e56e185..940c20fb 100755
--- a/vstf/vstf/controller/reporters/report/pdf/story.py
+++ b/vstf/vstf/controller/reporters/report/pdf/story.py
@@ -1,5 +1,12 @@
-#!/usr/bin/python
-# -*- coding: utf8 -*-
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
__doc__ = """
Story Decorator contains ImageStory, HeaderStory, PageBreakStory,
TableStory, LinePlotStory, TitleStory, ParagraphStory
@@ -88,44 +95,32 @@ class TableOfContentsStory(StoryDecorator):
self._story.storylist.append(toc)
-class uTableStory(StoryDecorator):
- def new_story(self):
- print "utable story"
- style = ts_left
- if not self._data:
- print "data error "
- return
- self._story.storylist.append(eCommonTable(self._data, style).table)
-
-
-class TableStory(StoryDecorator):
- def new_story(self):
- print "table story"
- style = ts_default
- self._story.storylist.append(eDataTable(self._data, style).table)
-
-
class SpaceStory(StoryDecorator):
def new_story(self):
style = ps_space
self._story.storylist.append(eParagraph([" ", " "], style).para)
-class cTableStory(StoryDecorator):
+class TableStory(StoryDecorator):
def new_story(self):
print "table story"
style = ts_default
- if self._style == 0:
+ if self._style == 1:
+ self._story.storylist.append(eDataTable(self._data, style).table)
+ elif self._style ==2:
+ style = ts_left
+ self._story.storylist.append(eCommonTable(self._data, style).table)
+ elif self._style == 3:
self._story.storylist.append(eConfigTable(self._data, style).table)
- elif self._style == 1:
+ elif self._style == 4:
self._story.storylist.append(eOptionsTable(self._data, style).table)
- elif self._style == 2:
+ elif self._style == 5:
self._story.storylist.append(eProfileTable(self._data, style).table)
- elif self._style == 3:
+ elif self._style == 6:
self._story.storylist.append(eSummaryTable(self._data, style).table)
- elif self._style == 4:
+ elif self._style == 7:
self._story.storylist.append(eScenarioTable(self._data, style).table)
- elif self._style == 5:
+ elif self._style == 8:
self._story.storylist.append(eGitInfoTable(self._data, style).table)
diff --git a/vstf/vstf/controller/reporters/report/pdf/styles.py b/vstf/vstf/controller/reporters/report/pdf/styles.py
index d54ee8ab..2860c245 100755
--- a/vstf/vstf/controller/reporters/report/pdf/styles.py
+++ b/vstf/vstf/controller/reporters/report/pdf/styles.py
@@ -1,10 +1,17 @@
-#!/usr/bin/python
-# -*- coding: utf8 -*-
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
from reportlab.lib.styles import PropertySet
from reportlab.lib.pagesizes import A4
from reportlab.lib import colors
from reportlab.lib.styles import ParagraphStyle
-from reportlab.lib.enums import TA_LEFT
+import reportlab.lib.enums as ens
class TemplateStyle(PropertySet):
@@ -108,20 +115,14 @@ class BarChartStyle(PropertySet):
"fastlink": (colors.pink, '%4.1f'),
"l2switch": (colors.lightblue, '%4.1f'),
"kernel rdp": (colors.lightgreen, '%4.1f'),
+ "ovs": (colors.purple, '%4.1f')
},
background=colors.lightgrey,
labelsfont=6,
)
-ts_left = TableStyle(
- name='left',
- table_hAlign='LEFT', # LEFT,CENTRE or RIGHT
- table_vAlign='BOTTOM', # BOTTOM,MIDDLE or TOP
- table_colWidths=None,
- table_rowHeights=None
-)
-
+tes_default = TemplateStyle(name='default')
is_default = ImageStyle(name='default')
is_traffic = ImageStyle(name='traffic',
image_height=150,
@@ -129,12 +130,19 @@ is_traffic = ImageStyle(name='traffic',
image_hAlign='CENTRE')
ts_default = TableStyle(name='default')
+ts_left = TableStyle(
+ name='left',
+ table_hAlign='LEFT', # LEFT,CENTRE or RIGHT
+ table_vAlign='BOTTOM', # BOTTOM,MIDDLE or TOP
+ table_colWidths=None,
+ table_rowHeights=None
+)
lps_default = LinePlotStyle(name='default')
lcs_default = LineChartStyle(name='default')
bcs_default = BarChartStyle(name='default')
ps_head_lv1 = ParagraphStyle(name='ps_head_lv1',
fontName='Courier-Bold',
- alignment=TA_LEFT, # TA_CENTRE,
+ alignment=ens.TA_CENTER, # TA_LEFT, TA_RIGHT
fontSize=13,
leading=22,
leftIndent=0)
diff --git a/vstf/vstf/controller/reporters/report/provider/__init__.py b/vstf/vstf/controller/reporters/report/provider/__init__.py
index 89dcd4e2..83b8d15d 100755
--- a/vstf/vstf/controller/reporters/report/provider/__init__.py
+++ b/vstf/vstf/controller/reporters/report/provider/__init__.py
@@ -1,14 +1,8 @@
-# Copyright Huawei Technologies Co., Ltd. 1998-2015.
-# All Rights Reserved.
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
#
-# Licensed under the Apache License, Version 2.0 (the License); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an AS IS BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
diff --git a/vstf/vstf/controller/reporters/report/provider/html_provider.py b/vstf/vstf/controller/reporters/report/provider/html_provider.py
index b0b07432..74c4c593 100755
--- a/vstf/vstf/controller/reporters/report/provider/html_provider.py
+++ b/vstf/vstf/controller/reporters/report/provider/html_provider.py
@@ -1,63 +1,45 @@
-#!/usr/bin/python
-# -*- coding: utf8 -*-
-# author: wly
-# date: 2015-09-25
-# see license for license details
-__version__ = ''' '''
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
import logging
LOG = logging.getLogger(__name__)
from vstf.controller.settings.html_settings import HtmlSettings
-from vstf.controller.settings.data_settings import DataSettings
+from vstf.controller.settings.template_settings import TemplateSettings
class HtmlProvider(object):
- def __init__(self, content, style):
- self._content = content
+ def __init__(self, info, style):
+ self._info = info
self._style = style
+ @property
def get_style(self):
+ assert "style" in self._style
return self._style["style"]
- def get_subject(self):
- return self._content["subject"]
-
- def get_ovs_title(self):
- return self._content["ovs"]["title"]
-
- def get_ovs_table(self):
- return map(lambda x: list(x), self._content["ovs"]["content"].items())
-
- def get_result_title(self):
- return self._content["result"]["title"]
-
- def get_result_table(self, ttype):
- result = []
- content = self._content["result"]["content"]
- if ttype in content:
- result.append(content[ttype]["columns"])
- result.extend(content[ttype]["data"])
-
- result = map(lambda x: list(x), zip(*result))
- return result
-
-
-class StyleProvider(object):
- def __init__(self, style):
- self._style = style
-
- def get_style(self):
- return self._style["style"]
+ @property
+ def get_context(self):
+ assert "context" in self._info
+ return self._info["context"]
-def unit_test():
+def main():
from vstf.common.log import setup_logging
setup_logging(level=logging.DEBUG, log_file="/var/log/html-provder.log", clevel=logging.INFO)
html_settings = HtmlSettings()
LOG.info(html_settings.settings)
- data_settings = DataSettings()
- LOG.info(data_settings.settings)
+ info = TemplateSettings()
+ provider = HtmlProvider(info.settings, html_settings.settings)
+ LOG.info(provider.get_style)
+ LOG.info(provider.get_context)
- hprovider = HtmlProvider(data_settings.settings, html_settings.settings)
- sprovider = StyleProvider(html_settings.settings)
+if __name__ == '__main__':
+ main() \ No newline at end of file
diff --git a/vstf/vstf/controller/reporters/report/provider/pdf_provider.py b/vstf/vstf/controller/reporters/report/provider/pdf_provider.py
new file mode 100755
index 00000000..bc9f0e96
--- /dev/null
+++ b/vstf/vstf/controller/reporters/report/provider/pdf_provider.py
@@ -0,0 +1,51 @@
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+
+
+__version__ = ''' '''
+import logging
+
+LOG = logging.getLogger(__name__)
+from vstf.controller.settings.template_settings import TemplateSettings
+
+
+class PdfProvider(object):
+ def __init__(self, info):
+ self._info = info
+
+ @property
+ def get_theme(self):
+ assert "theme" in self._info
+ return self._info["theme"]
+
+ @property
+ def ifcontents(self):
+ assert "contents" in self._info
+ assert "enable" in self._info["contents"]
+ return self._info["contents"]["enable"]
+
+ @property
+ def get_context(self):
+ assert "context" in self._info
+ return self._info["context"]
+
+
+def main():
+ from vstf.common.log import setup_logging
+ setup_logging(level=logging.DEBUG, log_file="/var/log/pdf-provider.log", clevel=logging.INFO)
+
+ info = TemplateSettings()
+ provider = PdfProvider(info.settings)
+ LOG.info(provider.get_theme)
+ LOG.info(provider.ifcontents)
+ LOG.info(provider.get_context)
+
+if __name__ == '__main__':
+ main() \ No newline at end of file
diff --git a/vstf/vstf/controller/reporters/reporter.py b/vstf/vstf/controller/reporters/reporter.py
index 1c256c61..e77ae349 100755
--- a/vstf/vstf/controller/reporters/reporter.py
+++ b/vstf/vstf/controller/reporters/reporter.py
@@ -1,21 +1,28 @@
-#!/usr/bin/python
-# -*- coding: utf8 -*-
-# author: wly
-# date: 2015-05-29
-# see license for license details
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
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.reporters.report.provider.html_provider import HtmlProvider
+from vstf.controller.reporters.report.provider.pdf_provider import PdfProvider
+from vstf.controller.settings.template_settings import TemplateSettings
+from vstf.controller.reporters.report.data_factory import TaskData
+from vstf.controller.reporters.report.html.htmlcreator import HtmlCreator
+from vstf.controller.reporters.report.pdf.pdfcreator import PdfCreator
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
+from vstf.controller.reporters.report.candy_generator import CandyGenerator
import vstf.common.constants as cst
@@ -31,37 +38,44 @@ class Report(object):
"""
self._dbase = dbase
self._rpath = "."
+ self._mail_settings = MailSettings()
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)
+ task = TaskData(taskid, self._dbase)
+ scenario_list = task.common.get_scenariolist()
+ creator = CandyGenerator(task)
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)))
+ out_file = os.path.join(self._rpath, "vstf_report_%s_%s.pdf" % (scenario, time.strftime(cst.TIME_FORMAT3)))
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)
+ creator.create(scenario)
+ info = TemplateSettings()
+ provider = PdfProvider(info.settings)
+ reporter = PdfCreator(provider)
+ reporter.create(out_file)
+ 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)
+ task = TaskData(taskid, self._dbase)
+
+ creator = CandyGenerator(task)
+ creator.create_all()
html_settings = HtmlSettings()
+ info = TemplateSettings()
LOG.info(html_settings.settings)
- provider = StyleProvider(html_settings.settings)
+ provider = HtmlProvider(info.settings, 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()
+ html = HtmlCreator(provider)
+ content = html.create(out_file)
self._mail_settings.mset_subtype('html')
self._mail_settings.mset_content(content)