121875d02ea4e8ca7fc61678e23c36ef82c6f59f
[releng.git] / utils / test / result_collection_api / opnfv_testapi / 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 import sys
20 from functest2Dashboard import format_functest_for_dashboard, \
21     check_functest_case_exist
22 from yardstick2Dashboard import format_yardstick_for_dashboard, \
23     check_yardstick_case_exist
24 from vsperf2Dashboard import format_vsperf_for_dashboard, \
25     check_vsperf_case_exist
26 from bottlenecks2Dashboard import format_bottlenecks_for_dashboard, \
27     check_bottlenecks_case_exist
28 from qtip2Dashboard import format_qtip_for_dashboard, \
29     check_qtip_case_exist
30 from promise2Dashboard import format_promise_for_dashboard, \
31     check_promise_case_exist
32 from doctor2Dashboard import format_doctor_for_dashboard, \
33     check_doctor_case_exist
34
35 # any project test project wishing to provide dashboard ready values
36 # must include at least 2 methods
37 # - format_<Project>_for_dashboard
38 # - check_<Project>_case_exist
39
40
41 def check_dashboard_ready_project(test_project):
42     # Check that the first param corresponds to a project
43     # for whoch dashboard processing is available
44     # print("test_project: %s" % test_project)
45     project_module = 'opnfv_testapi.dashboard.'+test_project + '2Dashboard'
46     return True if project_module in sys.modules else False
47
48
49 def check_dashboard_ready_case(project, case):
50     cmd = "check_" + project + "_case_exist(case)"
51     return eval(cmd)
52
53
54 def get_dashboard_projects():
55     # Retrieve all the projects that could provide
56     # Dashboard ready graphs
57     # look in the releng repo
58     # search all the project2Dashboard.py files
59     # we assume that dashboard processing of project <Project>
60     # is performed in the <Project>2Dashboard.py file
61     projects = []
62     cp = re.compile('opnfv_testapi\.dashboard\.(.+?)2Dashboard')
63     for module in sys.modules:
64         project = re.findall(cp, module)
65         if project:
66             projects.extend(project)
67     return projects
68
69
70 def get_dashboard_result(project, case, results=None):
71     # get the dashboard ready results
72     # paramters are:
73     # project: project name
74     # results: array of raw results pre-filterded
75     # according to the parameters of the request
76     cmd = "format_" + project + "_for_dashboard(case,results)"
77     res = eval(cmd)
78     return res