change the usage of tornado_swagger package
[releng.git] / utils / test / result_collection_api / opnfv_testapi / resources / dashboard_handlers.py
1 from tornado.web import HTTPError
2
3 from opnfv_testapi.common.constants import HTTP_NOT_FOUND
4 from opnfv_testapi.dashboard.dashboard_utils import \
5     check_dashboard_ready_project, \
6     check_dashboard_ready_case, get_dashboard_result
7 from opnfv_testapi.resources.result_handlers import GenericResultHandler
8 from opnfv_testapi.resources.result_models import TestResult
9 from opnfv_testapi.tornado_swagger import swagger
10
11
12 class GenericDashboardHandler(GenericResultHandler):
13     def __init__(self, application, request, **kwargs):
14         super(GenericDashboardHandler, self).__init__(application,
15                                                       request,
16                                                       **kwargs)
17         self.table = self.db_results
18         self.table_cls = TestResult
19
20
21 class DashboardHandler(GenericDashboardHandler):
22     @swagger.operation(nickname='query')
23     def get(self):
24         """
25             @description: Retrieve dashboard ready result(s)
26                           for a test project
27             @notes: Retrieve dashboard ready result(s) for a test project
28                 Available filters for this request are :
29                  - project : project name
30                  - case : case name
31                  - pod : pod name
32                  - version : platform version (Arno-R1, ...)
33                  - installer (fuel, ...)
34                  - period : x (x last days)
35
36                 GET /dashboard?project=functest&case=vPing&version=Colorado \
37                 &pod=pod_name&period=15
38             @rtype: L{string}
39             @param pod: pod name
40             @type pod: L{string}
41             @in pod: query
42             @required pod: False
43             @param project: project name
44             @type project: L{string}
45             @in project: query
46             @required project: True
47             @param case: case name
48             @type case: L{string}
49             @in case: query
50             @required case: True
51             @param version: i.e. Colorado
52             @type version: L{string}
53             @in version: query
54             @required version: False
55             @param installer: fuel/apex/joid/compass
56             @type installer: L{string}
57             @in installer: query
58             @required installer: False
59             @param period: last days
60             @type period: L{string}
61             @in period: query
62             @required period: False
63             @return 200: test result exist
64             @raise 400: period is not in
65             @raise 404: project or case name missing,
66                         or project or case is not dashboard ready
67         """
68
69         project_arg = self.get_query_argument("project", None)
70         case_arg = self.get_query_argument("case", None)
71
72         # on /dashboard retrieve the list of projects and testcases
73         # ready for dashboard
74         if project_arg is None:
75             raise HTTPError(HTTP_NOT_FOUND, "Project name missing")
76
77         if not check_dashboard_ready_project(project_arg):
78             raise HTTPError(HTTP_NOT_FOUND,
79                             'Project [{}] not dashboard ready'
80                             .format(project_arg))
81
82         if case_arg is None:
83             raise HTTPError(
84                 HTTP_NOT_FOUND,
85                 'Test case missing for project [{}]'.format(project_arg))
86
87         if not check_dashboard_ready_case(project_arg, case_arg):
88             raise HTTPError(
89                 HTTP_NOT_FOUND,
90                 'Test case [{}] not dashboard ready for project [{}]'
91                 .format(case_arg, project_arg))
92
93         # special case of status for project
94         if case_arg == 'status':
95             self.finish_request(get_dashboard_result(project_arg, case_arg))
96         else:
97             def get_result(res, project, case):
98                 return get_dashboard_result(project, case, res)
99
100             self._list(self.set_query(), get_result, project_arg, case_arg)