1 from datetime import datetime, timedelta
3 from bson.objectid import ObjectId
4 from tornado.web import HTTPError
6 from common.constants import HTTP_BAD_REQUEST, HTTP_NOT_FOUND
7 from resources.handlers import GenericApiHandler
8 from resources.result_models import TestResult
9 from tornado_swagger_ui.tornado_swagger import swagger
12 class GenericResultHandler(GenericApiHandler):
13 def __init__(self, application, request, **kwargs):
14 super(GenericResultHandler, self).__init__(application,
17 self.table = self.db_results
18 self.table_cls = TestResult
22 for k in self.request.query_arguments.keys():
23 v = self.get_query_argument(k)
24 if k == 'project' or k == 'pod' or k == 'case':
25 query[k + '_name'] = v
30 raise HTTPError(HTTP_BAD_REQUEST, 'period must be int')
32 period = datetime.now() - timedelta(days=v)
33 obj = {"$gte": str(period)}
34 query['creation_date'] = obj
40 class ResultsCLHandler(GenericResultHandler):
41 @swagger.operation(nickname="list-all")
44 @description: Retrieve result(s) for a test project
46 @notes: Retrieve result(s) for a test project on a specific pod.
47 Available filters for this request are :
48 - project : project name
51 - version : platform version (Arno-R1, ...)
52 - installer (fuel, ...)
53 - build_tag : Jenkins build tag name
54 - period : x (x last days)
55 - scenario : the test scenario (previously version)
56 - criteria : the global criteria status passed or failed
57 - trust_indicator : evaluate the stability of the test case
58 to avoid running systematically long and stable test case
60 GET /results/project=functest&case=vPing&version=Arno-R1 \
61 &pod=pod_name&period=15
62 @return 200: all test results consist with query,
63 empty list if no result is found
64 @rtype: L{TestResults}
69 @param project: project name
70 @type project: L{string}
72 @required project: True
73 @param case: case name
77 @param version: i.e. Colorado
78 @type version: L{string}
80 @required version: False
81 @param installer: fuel/apex/joid/compass
82 @type installer: L{string}
84 @required installer: False
85 @param build_tag: i.e. v3.0
86 @type build_tag: L{string}
88 @required build_tag: False
89 @param scenario: i.e. odl
90 @type scenario: L{string}
92 @required scenario: False
93 @param criteria: i.e. passed
94 @type criteria: L{string}
96 @required criteria: False
97 @param period: last days
98 @type period: L{string}
100 @required period: False
101 @param trust_indicator: must be integer
102 @type trust_indicator: L{string}
103 @in trust_indicator: query
104 @required trust_indicator: False
106 self._list(self.set_query())
108 @swagger.operation(nickname="create")
111 @description: create a test result
112 @param body: result to be created
113 @type body: L{ResultCreateRequest}
115 @rtype: L{TestResult}
116 @return 200: result is created.
117 @raise 404: pod/project/testcase not exist
118 @raise 400: body/pod_name/project_name/case_name not provided
121 return {'name': data.pod_name}
124 message = 'Could not find pod [{}]'.format(data.pod_name)
125 return HTTP_NOT_FOUND, message
127 def project_query(data):
128 return {'name': data.project_name}
130 def project_error(data):
131 message = 'Could not find project [{}]'.format(data.project_name)
132 return HTTP_NOT_FOUND, message
134 def testcase_query(data):
135 return {'project_name': data.project_name, 'name': data.case_name}
137 def testcase_error(data):
138 message = 'Could not find testcase [{}] in project [{}]'\
139 .format(data.case_name, data.project_name)
140 return HTTP_NOT_FOUND, message
142 miss_checks = ['pod_name', 'project_name', 'case_name']
143 db_checks = [('pods', True, pod_query, pod_error),
144 ('projects', True, project_query, project_error),
145 ('testcases', True, testcase_query, testcase_error)]
146 self._create(miss_checks, db_checks)
149 class ResultsGURHandler(GenericResultHandler):
150 @swagger.operation(nickname='get-one')
151 def get(self, result_id):
153 @description: get a single result by result_id
154 @rtype: L{TestResult}
155 @return 200: test result exist
156 @raise 404: test result not exist
159 query["_id"] = ObjectId(result_id)