5 # see license for license details
10 from vstf.controller.reporters.report.pdf.styles import TemplateStyle
11 from vstf.controller.reporters.report.pdf.pdftemplate import PdfVswitch
12 from vstf.controller.reporters.report.pdf.story import TitleStory, SpaceStory, ImageStory, LineChartStory, \
13 LinePlotStory, uTableStory, Story, TableOfContentsStory, PageBreakStory, ParagraphStory, BarChartStory, cTableStory
14 from vstf.controller.reporters.report.data_factory import CommonData, ScenarioData, HistoryData
15 from vstf.controller.database.dbinterface import DbManage
16 import vstf.controller
19 class LetterOrder(object):
21 self.lettertable = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
23 self._len = len(self.lettertable)
26 return self.lettertable[self._cur]
29 self._cur = (self._cur + self._len - 1) % self._len
32 self._cur = (self._cur + 1) % self._len
35 class PdfBase(object):
41 self._rootdir = os.path.dirname(vstf.controller.__file__) + '/'
45 style = TemplateStyle(name='default')
47 logo = [self._rootdir + "res/logo.jpg"]
51 output = [self._ofile]
52 self._pdf = PdfFrameLoss(style, title, logo, header, footer, output, note)
55 self._pdf.generate(self._story)
57 def add_coverpage(self):
59 story = PageBreakStory(story)
60 self._story += story.storylist
62 def create_story(self):
63 raise NotImplementedError("abstract PdfBase")
71 class PdfvSwitchCreator(PdfBase):
72 def __init__(self, ofile, common_data, scenario_data, history_data):
73 PdfBase.__init__(self)
74 self._common = common_data
75 self._result = scenario_data
76 self._history = history_data
79 self._appendixid = LetterOrder()
82 style = TemplateStyle(name='default')
83 title = self._result.get_covertitle()
84 logo = [self._rootdir + "res/logo.jpg"]
88 output = [self._ofile]
89 self._pdf = PdfVswitch(style, title, logo, header, footer, output, note)
91 def get_chapterid(self):
92 self._chapterid = self._chapterid + 1
93 return self._chapterid
95 def create_story(self):
97 self.add_table_of_contents()
102 # self.add_appendix()
106 self.add_systeminfo()
108 self.add_profile_parameters()
109 self.add_testing_options()
111 def add_contact(self):
113 story = SpaceStory(story)
114 title = ["", "", "", "Reporter"]
115 body = self._common.get_contact()
116 story = TitleStory(story, data=title, style=7)
117 story = ParagraphStory(story, data=body)
118 self._story += story.storylist
120 def add_table_of_contents(self):
122 story = TableOfContentsStory(story)
123 self._story += story.storylist
125 def add_overview(self):
127 story = PageBreakStory(story)
129 chapterid = self.get_chapterid()
130 title = ["%d.Overview" % (chapterid)]
132 story = TitleStory(story, data=title, style=1)
133 story = ParagraphStory(story, data=body)
136 title = ["%d.%d Components under Test" % (chapterid, sectionid)]
137 body = self._common.get_components()
138 story = TitleStory(story, data=title, style=2)
139 story = ParagraphStory(story, data=body)
141 sectionid = sectionid + 1
142 title = ["%d.%d Test" % (chapterid, sectionid)]
143 body = self._result.get_test()
144 story = TitleStory(story, data=title, style=2)
145 story = ParagraphStory(story, data=body)
147 sectionid = sectionid + 1
148 title = ["%d.%d Configuration" % (chapterid, sectionid)]
149 story = TitleStory(story, data=title, style=2)
152 body = self._common.get_software()
153 story = TitleStory(story, data=title, style=6)
154 story = ParagraphStory(story, data=body)
157 body = self._common.get_hardware()
158 story = TitleStory(story, data=title, style=6)
159 story = ParagraphStory(story, data=body)
160 self._story += story.storylist
162 def add_scenario(self):
163 case_list = self._result.get_caselist()
164 for case in case_list:
167 def add_case(self, case):
169 chapterid = self.get_chapterid()
171 title = ["%d. Case : %s (%s)" % (chapterid, case, self._common.get_casename(case))]
173 tools = self._result.get_test_tools(case)
174 pic = self._common.get_casefigure(case, tools)
177 story = TitleStory(story, data=title, style=1)
178 story = SpaceStory(story)
179 story = ImageStory(story, data=[self._rootdir + pic])
180 story = SpaceStory(story)
183 story = self.add_summary(story, chapterid, sectionid, case)
184 story = SpaceStory(story)
186 if self._result.is_throughput_start(case):
187 sectionid = sectionid + 1
188 story = self.add_throughput_result(story, chapterid, sectionid, case)
190 if self._result.is_frameloss_start(case):
191 sectionid = sectionid + 1
192 story = self.add_frameloss_result(story, chapterid, sectionid, case)
194 if self._result.is_latency_start(case):
195 sectionid = sectionid + 1
196 story = self.add_latency_result(story, chapterid, sectionid, case)
198 story = SpaceStory(story)
199 story = SpaceStory(story)
200 self._story += story.storylist
202 def add_summary(self, story, chapterid, sectionid, case):
203 title = ["%d.%d Summary" % (chapterid, sectionid)]
204 story = TitleStory(story, data=title, style=2)
205 provider_list = ["fastlink", "rdp", "l2switch"]
206 provider_dict = {"fastlink": "Fast Link", "l2switch": "L2Switch", "rdp": "Kernel RDP"}
208 case_name = self._common.get_casename(case)
209 for provider in provider_list:
210 if self._result.is_provider_start(case, provider):
211 title = ["%d.%d.%d %s (%s_%s)" % (
212 chapterid, sectionid, unitid, provider_dict[provider], case_name, provider)]
214 story = TitleStory(story, data=title, style=6)
215 test_types = ["throughput", "frameloss"]
216 for test_type in test_types:
217 if self._result.is_type_provider_start(case, provider, test_type):
218 story = self.add_summary_type(story, case, provider, test_type)
221 def add_summary_type(self, story, case, provider, test_type):
222 bar_list = [test_type, "latency"]
223 for item in bar_list:
224 bar_data = self._result.get_bardata(case, provider, item)
225 story = SpaceStory(story)
226 story = BarChartStory(story, data=bar_data)
228 table_content = self._result.get_summary_tabledata(case, provider, test_type)
229 story = SpaceStory(story)
230 story = cTableStory(story, data=table_content, style=3)
231 story = SpaceStory(story)
234 def add_throughput_result(self, story, chapterid, sectionid, case):
235 title = ["%d.%d Throughput " % (chapterid, sectionid)]
236 story = TitleStory(story, data=title, style=2)
238 title = ["%d.%d.%d Summary" % (chapterid, sectionid, unitid)]
239 story = TitleStory(story, data=title, style=6)
241 test_type = "throughput"
242 unit = 'RX Frame Rate'
243 chart_data = self._result.get_frameloss_chartdata(case, test_type)
244 table_data = self._result.get_frameloss_tabledata(case, test_type)
245 title = [unit + ' (%)']
246 story = TitleStory(story, data=title, style=6)
247 # story = SpaceStory(story)
248 # story = LinePlotStory(story, data=chart_data)
249 story = SpaceStory(story)
250 story = uTableStory(story, data=table_data)
251 story = SpaceStory(story)
253 unit = 'Frame Loss Rate'
254 title = [unit + ' (Mpps)']
256 chart_data = self._result.get_framerate_chartdata(case, test_type)
257 table_data = self._result.get_framerate_tabledata(case, test_type)
258 story = TitleStory(story, data=title, style=6)
259 story = SpaceStory(story)
260 story = LinePlotStory(story, data=chart_data)
261 story = SpaceStory(story)
262 story = uTableStory(story, data=table_data)
263 story = SpaceStory(story)
266 def add_frameloss_result(self, story, chapterid, sectionid, case):
267 title = ["%d.%d Frame Loss Rate " % (chapterid, sectionid)]
268 story = TitleStory(story, data=title, style=2)
270 title = ["%d.%d.%d Summary" % (chapterid, sectionid, unitid)]
271 story = TitleStory(story, data=title, style=6)
273 test_type = "frameloss"
274 unit = 'RX Frame Rate'
275 chart_data = self._result.get_frameloss_chartdata(case, test_type)
276 table_data = self._result.get_frameloss_tabledata(case, test_type)
277 title = [unit + ' (%)']
278 story = TitleStory(story, data=title, style=6)
279 # story = SpaceStory(story)
280 # story = LineChartStory(story, data=chart_data)
281 story = SpaceStory(story)
282 story = uTableStory(story, data=table_data)
283 story = SpaceStory(story)
285 unit = 'Frame Loss Rate'
286 title = [unit + ' (Mpps)']
288 chart_data = self._result.get_framerate_chartdata(case, test_type)
289 table_data = self._result.get_framerate_tabledata(case, test_type)
290 story = TitleStory(story, data=title, style=6)
291 story = SpaceStory(story)
292 story = LineChartStory(story, data=chart_data)
293 story = SpaceStory(story)
294 story = uTableStory(story, data=table_data)
295 story = SpaceStory(story)
298 def add_latency_result(self, story, chapterid, sectionid, case):
299 title = ["%d.%d Latency " % (chapterid, sectionid)]
300 story = TitleStory(story, data=title, style=2)
302 title = ["%d.%d.%d Summary" % (chapterid, sectionid, unitid)]
303 story = TitleStory(story, data=title, style=6)
305 unit = 'Average Latency'
306 title = [unit + ' (uSec)']
307 # chart_data = self._result.get_latency_chartdata(case)
308 bar_data = self._result.get_latency_bardata(case)
309 table_data = self._result.get_latency_tabledata(case)
310 story = TitleStory(story, data=title, style=6)
311 story = SpaceStory(story)
312 # story = LineChartStory(story, data=chart_data)
313 story = BarChartStory(story, data=bar_data)
315 story = SpaceStory(story)
316 story = uTableStory(story, data=table_data)
317 story = SpaceStory(story)
320 def add_systeminfo(self):
322 chapterid = self.get_chapterid()
323 story = SpaceStory(story)
324 title = ["%d. System Information " % (chapterid)]
325 story = PageBreakStory(story)
326 story = TitleStory(story, data=title, style=1)
327 table_content = self._common.get_systeminfo_tabledata()
328 story = SpaceStory(story)
329 story = cTableStory(story, data=table_content, style=0)
330 story = SpaceStory(story)
331 self._story += story.storylist
333 def add_gitinfo(self):
335 chapterid = self.get_chapterid()
336 title = ["%d. Git Repository Information " % (chapterid)]
337 story = TitleStory(story, data=title, style=1)
339 table_content = self._common.get_gitinfo_tabledata()
341 story = SpaceStory(story)
342 story = cTableStory(story, data=table_content, style=5)
343 story = SpaceStory(story)
344 self._story += story.storylist
346 def add_testing_options(self):
348 chapterid = self.get_chapterid()
349 story = SpaceStory(story)
350 title = ["%d. Testing Options" % (chapterid)]
352 story = TitleStory(story, data=title, style=1)
353 table_content = self._common.get_testingoptions_tabledata()
354 story = SpaceStory(story)
355 story = cTableStory(story, data=table_content, style=1)
356 story = SpaceStory(story)
357 self._story += story.storylist
359 def add_profile_parameters(self):
361 chapterid = self.get_chapterid()
362 story = PageBreakStory(story)
363 title = ["%d. " % (chapterid)]
364 story = TitleStory(story, data=title, style=1)
365 table_content = self._common.get_profileparameters_tabledData()
366 story = SpaceStory(story)
367 story = cTableStory(story, data=table_content, style=2)
368 story = SpaceStory(story)
369 self._story += story.storylist
371 def add_appendix(self):
373 story = PageBreakStory(story)
375 title = ["<b>Appendix %s: vSwitching Testing Methodology</b>" % (self._appendixid.get())]
376 self._appendixid.next()
377 story = TitleStory(story, data=title, style=1)
378 filename = "res/Traffic-types.jpg"
379 story = SpaceStory(story)
380 story = ImageStory(story, data=[self._rootdir + filename])
381 # story = SpaceStory(story)
383 title = ["Traffic Patterns: "]
384 story = TitleStory(story, data=title, style=6)
387 "<b>Ti</b> - South North Traffic",
388 "<b>Tu</b> - East Eest Traffic",
389 "<b>Tn</b> - Physical host or VM loop back",
390 "<b>Tnv</b> - Virtual Machine loop back",
392 story = ParagraphStory(story, data=body)
394 title = ["<b>Performance Testing Coverage </b> (version 0.1):"]
395 story = TitleStory(story, data=title, style=6)
397 table_content = self._common.get_introduct_tabledata()
398 story = SpaceStory(story)
399 story = cTableStory(story, data=table_content, style=4)
400 self._story += story.storylist
402 def add_historys(self):
403 case_list = self._result.get_caselist()
404 for case in case_list:
405 history = self._history.get_history_info(case)
407 self.add_history(case, history)
409 def add_history(self, case, history):
411 story = PageBreakStory(story)
413 title = ["<b>Appendix %s : %s History Records</b>" % (self._appendixid.get(), case)]
414 story = TitleStory(story, data=title, style=1)
416 for i in range(len(history)):
417 title = ["%s.%s %s" % (self._appendixid.get(), i, history[i]["title"])]
418 story = TitleStory(story, data=title, style=2)
420 section = history[i]["data"]
422 title = [unit['title']]
423 story = TitleStory(story, data=title, style=6)
424 content = unit['data']
425 story = uTableStory(story, data=content)
427 self._appendixid.next()
428 self._story += story.storylist
433 taskid = dbase.get_last_taskid()
434 common_data = CommonData(taskid, dbase)
435 scenario_list = common_data.get_scenariolist()
436 history_data = HistoryData(taskid, dbase)
437 for scenario in scenario_list:
438 out_file = "vstf_report_%s.pdf" % (scenario)
439 scenario_data = ScenarioData(taskid, dbase, scenario)
440 reporter = PdfvSwitchCreator(out_file, common_data, scenario_data, history_data)
445 if __name__ == '__main__':