1 ##############################################################################
2 # Copyright (c) 2015 Orange
3 # guyrodrigue.koffi@orange.com / koffirodrigue@gmail.com
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
10 from tornado.web import HTTPError
12 from opnfv_testapi.common.constants import HTTP_NOT_FOUND
13 from opnfv_testapi.dashboard.dashboard_utils import \
14 check_dashboard_ready_project, check_dashboard_ready_case, \
15 get_dashboard_result, get_dashboard_projects
16 from opnfv_testapi.resources.result_handlers import GenericResultHandler
17 from opnfv_testapi.resources.result_models import TestResult
18 from opnfv_testapi.tornado_swagger import swagger
21 class GenericDashboardHandler(GenericResultHandler):
22 def __init__(self, application, request, **kwargs):
23 super(GenericDashboardHandler, self).__init__(application,
26 self.table = self.db_results
27 self.table_cls = TestResult
30 class DashboardHandler(GenericDashboardHandler):
31 @swagger.operation(nickname='query')
34 @description: Retrieve dashboard ready result(s)
36 @notes: Retrieve dashboard ready result(s) for a test project
37 Available filters for this request are :
38 - project : project name
41 - version : platform version (Arno-R1, ...)
42 - installer (fuel, ...)
43 - period : x (x last days)
45 GET /dashboard?project=functest&case=vPing&version=Colorado \
46 &pod=pod_name&period=15
52 @param project: project name
53 @type project: L{string}
55 @required project: True
56 @param case: case name
60 @param version: i.e. Colorado
61 @type version: L{string}
63 @required version: False
64 @param installer: fuel/apex/joid/compass
65 @type installer: L{string}
67 @required installer: False
68 @param period: last days
69 @type period: L{string}
71 @required period: False
72 @return 200: test result exist
73 @raise 400: period is not in
74 @raise 404: project or case name missing,
75 or project or case is not dashboard ready
78 project_arg = self.get_query_argument("project", None)
79 case_arg = self.get_query_argument("case", None)
81 # on /dashboard retrieve the list of projects and testcases
83 if project_arg is None:
84 raise HTTPError(HTTP_NOT_FOUND, "Project name missing")
86 if not check_dashboard_ready_project(project_arg):
87 raise HTTPError(HTTP_NOT_FOUND,
88 'Project [{}] not dashboard ready'
94 'Test case missing for project [{}]'.format(project_arg))
96 if not check_dashboard_ready_case(project_arg, case_arg):
99 'Test case [{}] not dashboard ready for project [{}]'
100 .format(case_arg, project_arg))
102 # special case of status for project
103 if case_arg == 'status':
104 self.finish_request(get_dashboard_result(project_arg, case_arg))
106 def get_result(res, project, case):
107 return get_dashboard_result(project, case, res)
109 self._list(self.set_query(), get_result, project_arg, case_arg)
112 class DashboardProjectsHandler(GenericDashboardHandler):
113 @swagger.operation(nickname='list')
116 @description: Retrieve dashboard ready project(s)
118 @return 200: return all dashboard ready project(s)
120 self.finish_request(get_dashboard_projects())