docs: add instruction of python package installation
[releng.git] / utils / test / result_collection_api / dashboard / dashboard_utils.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 retieve data from test DB
13 # and format them into a json format adapted for a dashboard
14 #
15 # v0.1: basic example
16 #
17 import os
18 import re
19 from functest2Dashboard import format_functest_for_dashboard, \
20     check_functest_case_exist
21 from yardstick2Dashboard import format_yardstick_for_dashboard, \
22     check_yardstick_case_exist
23 from vsperf2Dashboard import format_vsperf_for_dashboard, \
24     check_vsperf_case_exist
25 from bottlenecks2Dashboard import format_bottlenecks_for_dashboard, \
26     check_bottlenecks_case_exist
27 from qtip2Dashboard import format_qtip_for_dashboard, \
28     check_qtip_case_exist
29 from promise2Dashboard import format_promise_for_dashboard, \
30     check_promise_case_exist
31
32 # any project test project wishing to provide dashboard ready values
33 # must include at least 2 methods
34 # - format_<Project>_for_dashboard
35 # - check_<Project>_case_exist
36
37
38 def check_dashboard_ready_project(test_project, path):
39     # Check that the first param corresponds to a project
40     # for whoch dashboard processing is available
41     subdirectories = os.listdir(path)
42     for testfile in subdirectories:
43         m = re.search('^(.*)(2Dashboard.py)$', testfile)
44         if m:
45             if (m.group(1) == test_project):
46                 return True
47     return False
48
49
50 def check_dashboard_ready_case(project, case):
51     cmd = "check_" + project + "_case_exist(case)"
52     return eval(cmd)
53
54
55 def get_dashboard_cases(path):
56     # Retrieve all the test cases that could provide
57     # Dashboard ready graphs
58     # look in the releng repo
59     # search all the project2Dashboard.py files
60     # we assume that dashboard processing of project <Project>
61     # is performed in the <Project>2Dashboard.py file
62     dashboard_test_cases = []
63     subdirectories = os.listdir(path)
64     for testfile in subdirectories:
65         m = re.search('^(.*)(2Dashboard.py)$', testfile)
66         if m:
67             dashboard_test_cases.append(m.group(1))
68
69     return dashboard_test_cases
70
71
72 def get_dashboard_result(project, case, results):
73     # get the dashboard ready results
74     # paramters are:
75     # project: project name
76     # results: array of raw results pre-filterded
77     # according to the parameters of the request
78     cmd = "format_" + project + "_for_dashboard(case,results)"
79     res = eval(cmd)
80     return res