84f43a7d1ca53c93b4f6661a876fb4d99ed51011
[releng.git] / utils / test / result_collection_api / opnfv_testapi / dashboard / promise2Dashboard.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 Promise 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 import re
18 import datetime
19
20
21 def get_promise_cases():
22     """
23     get the list of the supported test cases
24     TODO: update the list when adding a new test case for the dashboard
25     """
26     return ["promise"]
27
28
29 def format_promise_for_dashboard(case, results):
30     """
31     generic method calling the method corresponding to the test case
32     check that the testcase is properly declared first
33     then build the call to the specific method
34     """
35     if check_promise_case_exist(case):
36         # note we add _case because testcase and project had the same name
37         # TODO refactoring...looks fine at the beginning wit only 1 project
38         # not very ugly now and clearly not optimized...
39         cmd = "format_" + case + "_case_for_dashboard(results)"
40         res = eval(cmd)
41     else:
42         res = []
43         print "Test cases not declared"
44     return res
45
46
47 def check_promise_case_exist(case):
48     """
49     check if the testcase exists
50     if the test case is not defined or not declared in the list
51     return False
52     """
53     promise_cases = get_promise_cases()
54
55     if (case is None or case not in promise_cases):
56         return False
57     else:
58         return True
59
60
61
62
63
64 def format_promise_case_for_dashboard(results):
65     """
66     Post processing for the promise test case
67     """
68     test_data = [{'description': 'Promise results for Dashboard'}]
69     # Graph 1: (duration)=f(time)
70     # ***************************************
71     new_element = []
72
73     # default duration 0:00:08.999904
74     # consider only seconds => 09
75     for data in results:
76         t = data['details']['duration']
77         new_element.append({'x': data['creation_date'],
78                             'y': t})
79
80     test_data.append({'name': "Promise duration ",
81                       'info': {'type': "graph",
82                                'xlabel': 'time (s)',
83                                'ylabel': 'duration (s)'},
84                       'data_set': new_element})
85
86     # Graph 2: (Nb test, nb failure)=f(time)
87     # ***************************************
88     new_element = []
89
90     for data in results:
91         promise_results = data['details']
92         new_element.append({'x': data['creation_date'],
93                             'y1': promise_results['tests'],
94                             'y2': promise_results['failures']})
95
96     test_data.append({'name': "Promise nb tests/nb failures",
97                       'info': {'type': "graph",
98                                'xlabel': 'time',
99                                'y1label': 'Number of tests',
100                                'y2label': 'Number of failures'},
101                       'data_set': new_element})
102
103     return test_data