Merge "add dashboard method to test result collection API + add new fields in pod...
[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
22 # any project test project wishing to provide dashboard ready values
23 # must include at least 2 methods
24 # - format_<Project>_for_dashboard
25 # - check_<Project>_case_exist
26
27
28 def check_dashboard_ready_project(test_project, path):
29     # Check that the first param corresponds to a project
30     # for whoch dashboard processing is available
31     subdirectories = os.listdir(path)
32     for testfile in subdirectories:
33         m = re.search('^(.*)(2Dashboard.py)$', testfile)
34         if m:
35             if (m.group(1) == test_project):
36                 return True
37     return False
38
39
40 def check_dashboard_ready_case(project, case):
41     cmd = "check_" + project + "_case_exist(case)"
42     return eval(cmd)
43
44
45 def get_dashboard_cases(path):
46     # Retrieve all the test cases that could provide
47     # Dashboard ready graphs
48     # look in the releng repo
49     # search all the project2Dashboard.py files
50     # we assume that dashboard processing of project <Project>
51     # is performed in the <Project>2Dashboard.py file
52     dashboard_test_cases = []
53     subdirectories = os.listdir(path)
54     for testfile in subdirectories:
55         m = re.search('^(.*)(2Dashboard.py)$', testfile)
56         if m:
57             dashboard_test_cases.append(m.group(1))
58
59     return dashboard_test_cases
60
61
62 def get_dashboard_result(project, case, results):
63     # get the dashboard ready results
64     # paramters are:
65     # project: project name
66     # results: array of raw results pre-filterded
67     # according to the parameters of the request
68     cmd = "format_" + project + "_for_dashboard(case,results)"
69     res = eval(cmd)
70     return res