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):
20 def __init__(self, task):
23 def create(self, scenario):
28 name = candy.tuple2text(sn, candy.chapter, chapterid)
29 context[name] = self.create_env()
33 name = candy.tuple2text(sn, candy.chapter, chapterid)
34 context[name] = self.create_scenario(scenario)
36 template = TemplateSettings()
37 template.set_context(context)
38 LOG.info(template.settings)
45 name = candy.tuple2text(sn, candy.chapter, chapterid)
46 context[name] = self.create_env()
48 scenarios = self._task.common.get_scenariolist()
49 for scenario in scenarios:
52 name = candy.tuple2text(sn, candy.chapter, chapterid)
53 context[name] = self.create_scenario(scenario)
55 template = TemplateSettings()
56 template.set_context(context)
57 LOG.info(template.settings)
61 "01##title#1": ["System Environment"],
62 "02##table#2": self._task.common.get_systeminfo()
66 def create_scenario(self, scenario):
68 "01##title#1": ["Scenario Result"]
70 scenario_data = getattr(self._task, scenario)
71 test_list = scenario_data.get_testlist()
74 for test in test_list:
77 name = candy.tuple2text(sn, candy.section, sectionid)
79 case = test.CaseTag.decode()
80 ttype = test.Type.decode()
84 " Test tool: " + test.Tools.decode(),
85 " vSwitch: " + test.Switch.decode(),
86 " Protocol: " + test.Protocol.decode(),
89 if ttype in ["frameloss", "throughput"]:
93 "data": scenario_data.get_framerate_chartdata(case, ttype)
95 table = scenario_data.get_ratedata(testid, ttype)
100 "data": scenario_data.get_latency_bardata(case)
102 table = scenario_data.get_latency_tabledata(case)
103 test_section = self.create_test(
104 sectionid, params_info, table, draw)
105 scenario_chapter[name] = test_section
107 return scenario_chapter
109 def create_test(self, section, info, table, draw):
115 draw_name = candy.tuple2text(sn, draw["node"], draw["style"])
117 "01##title#2": ["Test ID: %s" % section],
118 "02##paragraph#2": ["Parameter"],
119 "03##paragraph#3": info,
120 "04##paragraph#2": ["Result"],
121 "05##table#2": table,
123 draw_name: draw["data"]
129 from vstf.common.log import setup_logging
132 log_file="/var/log/vstf/vstf-candy.log",
136 taskid = dbase.get_last_taskid()
137 task = TaskData(taskid, dbase)
138 creator = CandyGenerator(task)
141 if __name__ == '__main__':