427de76a5e644902949cbd20603fa130181408df
[releng.git] / utils / test / result_collection_api / dashboard / functest2Dashboard.py
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2015 Orange
4 # morgan.richomme@orange.com
5 #
6 # This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # This script is used to build dashboard ready json results
13 # It may be used for all the test case of the Functest project
14 # a new method format_<Test_case>_for_dashboard(results)
15 # v0.1: basic example with methods for odl, Tempest, Rally and vPing
16 #
17
18
19 def get_functest_cases():
20     """
21     get the list of the supported test cases
22     TODO: update the list when adding a new test case for the dashboard
23     """
24     return ["vPing", "Tempest", "odl", "Rally"]
25
26
27 def format_functest_for_dashboard(case, results):
28     """
29     generic method calling the method corresponding to the test case
30     check that the testcase is properly declared first
31     then build the call to the specific method
32     """
33     if check_functest_case_exist(case):
34         cmd = "format_" + case + "_for_dashboard(results)"
35         res = eval(cmd)
36     else:
37         res = []
38         print "Test cases not declared"
39     return res
40
41
42 def check_functest_case_exist(case):
43     """
44     check if the testcase exists
45     if the test case is not defined or not declared in the list
46     return False
47     """
48     functest_cases = get_functest_cases()
49
50     if (case is None or case not in functest_cases):
51         return False
52     else:
53         return True
54
55
56 def format_Tempest_for_dashboard(results):
57     """
58     Post processing for the Tempest test case
59     """
60     test_data = [{'description': 'Tempest results for Dashboard'}]
61     return test_data
62
63
64 def format_odl_for_dashboard(results):
65     """
66     Post processing for the odl test case
67     """
68     test_data = [{'description': 'odl results for Dashboard'}]
69     return test_data
70
71
72 def format_Rally_for_dashboard(results):
73     """
74     Post processing for the Rally test case
75     """
76     test_data = [{'description': 'Rally results for Dashboard'}]
77     return test_data
78
79
80 def format_vPing_for_dashboard(results):
81     """
82     Post processing for the vPing test case
83     """
84     test_data = [{'description': 'vPing results for Dashboard'}]
85
86     # Graph 1: Test_Duration = f(time)
87     # ********************************
88     new_element = []
89     for data in results:
90         new_element.append({'x': data['creation_date'],
91                             'y': data['details']['duration']})
92
93     test_data.append({'name': "vPing duration",
94                       'info': {'type': "graph",
95                                'xlabel': 'time',
96                                'ylabel': 'duration (s)'},
97                       'data_set': new_element})
98
99     # Graph 2: bar
100     # ************
101     nbTest = 0
102     nbTestOk = 0
103
104     for data in results:
105         nbTest += 1
106         if data['details']['status'] == "OK":
107             nbTestOk += 1
108
109     test_data.append({'name': "vPing status",
110                       'info': {"type": "bar"},
111                       'data_set': [{'Nb tests': nbTest,
112                                     'Nb Success': nbTestOk}]})
113
114     return test_data