1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
10 from vstf.controller.settings.template_settings import TemplateSettings
11 from vstf.controller.reporters.report.data_factory import TaskData
12 from vstf.controller.database.dbinterface import DbManage
13 import vstf.common.candy_text as candy
15 LOG = logging.getLogger(__name__)
18 class CandyGenerator(object):
19 def __init__(self, task):
22 def create(self, scenario):
27 name = candy.tuple2text(sn, candy.chapter, chapterid)
28 context[name] = self.create_env()
32 name = candy.tuple2text(sn, candy.chapter, chapterid)
33 context[name] = self.create_scenario(scenario)
35 template = TemplateSettings()
36 template.set_context(context)
37 LOG.info(template.settings)
44 name = candy.tuple2text(sn, candy.chapter, chapterid)
45 context[name] = self.create_env()
47 scenarios = self._task.common.get_scenariolist()
48 for scenario in scenarios:
51 name = candy.tuple2text(sn, candy.chapter, chapterid)
52 context[name] = self.create_scenario(scenario)
54 template = TemplateSettings()
55 template.set_context(context)
56 LOG.info(template.settings)
60 "01##title#1": ["System Environment"],
61 "02##table#2": self._task.common.get_systeminfo()
65 def create_scenario(self, scenario):
67 "01##title#1": ["Scenario Result"]
69 scenario_data = getattr(self._task, scenario)
70 test_list = scenario_data.get_testlist()
73 for test in test_list:
76 name = candy.tuple2text(sn, candy.section, sectionid)
78 case = test.CaseTag.decode()
79 ttype = test.Type.decode()
83 " Test tool: " + test.Tools.decode(),
84 " vSwitch: " + test.Switch.decode(),
85 " Protocol: " + test.Protocol.decode(),
88 if ttype in ["frameloss", "throughput"]:
92 "data": scenario_data.get_framerate_chartdata(case, ttype)
94 table = scenario_data.get_ratedata(testid, ttype)
99 "data": scenario_data.get_latency_bardata(case)
101 table = scenario_data.get_latency_tabledata(case)
102 test_section = self.create_test(sectionid, params_info, table, draw)
103 scenario_chapter[name] = test_section
105 return scenario_chapter
107 def create_test(self, section, info, table, draw):
113 draw_name = candy.tuple2text(sn, draw["node"], draw["style"])
115 "01##title#2": ["Test ID: %s" % section],
116 "02##paragraph#2": ["Parameter"],
117 "03##paragraph#3": info,
118 "04##paragraph#2": ["Result"],
119 "05##table#2": table,
121 draw_name: draw["data"]
127 from vstf.common.log import setup_logging
128 setup_logging(level=logging.DEBUG, log_file="/var/log/vstf/vstf-candy.log", clevel=logging.INFO)
131 taskid = dbase.get_last_taskid()
132 task = TaskData(taskid, dbase)
133 creator = CandyGenerator(task)
136 if __name__ == '__main__':