aboutsummaryrefslogtreecommitdiffstats
path: root/opnfv_testapi/resources/result_handlers.py
diff options
context:
space:
mode:
authorpkaralis <pkaralis@intracom-telecom.com>2018-12-06 00:43:12 +0200
committerPanagiotis Karalis <pkaralis@intracom-telecom.com>2019-03-20 15:28:23 +0200
commitd0bbf3b8952379883550c6eb2062476a6d15043e (patch)
tree106f65b223054077279bda7ff988a73bea314a34 /opnfv_testapi/resources/result_handlers.py
parent5f20495d6e3ec984c4e86fd76399ddf0d042b336 (diff)
Enable Web Portal for ONAP results
The web portal needs to be able to read test results of the ONAP compliance program and display them. In order for the above goal to be achieved, the following two parts should be impacted: 1- A new front-end should be prepared in order to handle and display the results 2- The REST API should be extended in order to support the aforementioned operation. JIRA: DOVETAIL-669 Change-Id: I36bbb6e602a67020d7e27aedbfc776f5cf4f3dc3 Signed-off-by: pkaralis <pkaralis@intracom-telecom.com> Co-Authored-By: Stamatis Katsaounis <mokats@intracom-telecom.com>
Diffstat (limited to 'opnfv_testapi/resources/result_handlers.py')
-rw-r--r--opnfv_testapi/resources/result_handlers.py40
1 files changed, 36 insertions, 4 deletions
diff --git a/opnfv_testapi/resources/result_handlers.py b/opnfv_testapi/resources/result_handlers.py
index 38109ad..9501bfd 100644
--- a/opnfv_testapi/resources/result_handlers.py
+++ b/opnfv_testapi/resources/result_handlers.py
@@ -20,6 +20,7 @@ from bson import objectid
from opnfv_testapi.common.config import CONF
from opnfv_testapi.common import message
from opnfv_testapi.common import raises
+from opnfv_testapi.db import api as dbapi
from opnfv_testapi.resources import handlers
from opnfv_testapi.resources import result_models
from opnfv_testapi.tornado_swagger import swagger
@@ -41,6 +42,7 @@ class GenericResultHandler(handlers.GenericApiHandler):
raises.BadRequest(message.must_int(key))
return value
+ @gen.coroutine
def set_query(self):
query = dict()
date_range = dict()
@@ -82,11 +84,15 @@ class GenericResultHandler(handlers.GenericApiHandler):
if 'start_date' in query and '$lt' not in query['start_date']:
query['start_date'].update({'$lt': str(datetime.now())})
- return query
+ query['is_onap'] = 'true' if self.is_onap else None
+
+ raise gen.Return((query))
class ResultsCLHandler(GenericResultHandler):
@swagger.operation(nickname="queryTestResults")
+ @web.asynchronous
+ @gen.coroutine
def get(self):
"""
@description: Retrieve result(s) for a test project
@@ -195,7 +201,8 @@ class ResultsCLHandler(GenericResultHandler):
'per_page': CONF.api_results_per_page
}
- self._list(query=self.set_query(), **limitations)
+ query = yield self.set_query()
+ yield self._list(query=query, **limitations)
@swagger.operation(nickname="createTestResult")
def post(self):
@@ -267,10 +274,19 @@ class ResultsUploadHandler(ResultsCLHandler):
results = results.split('\n')
result_ids = []
version = ''
+ vnf_type = None
+ vnf_checksum = None
for result in results:
if result == '':
continue
self.json_args = json.loads(result).copy()
+ openid = self.get_secure_cookie(auth_const.OPENID)
+ if openid:
+ self.json_args['owner'] = openid
+ if self.is_onap:
+ self.json_args['is_onap'] = 'true'
+ vnf_type = self.json_args['vnf_type']
+ vnf_checksum = self.json_args['vnf_checksum']
# the result files used in the first release of OVP did not
# specify an OVP version
if (self.json_args['version'] == 'master'
@@ -288,14 +304,30 @@ class ResultsUploadHandler(ResultsCLHandler):
with open(log_filename, "wb") as tar_out:
tar_out.write(fileinfo['body'])
resp = {'id': test_id, 'results': result_ids, 'version': version}
+ if vnf_type:
+ resp['vnf_type'] = vnf_type
+ resp['vnf_checksum'] = vnf_checksum
self.finish_request(resp)
class ResultsGURHandler(GenericResultHandler):
@swagger.operation(nickname='DeleteTestResultById')
+ @gen.coroutine
def delete(self, result_id):
- query = {'_id': objectid.ObjectId(result_id)}
- self._delete(query=query)
+ curr_user = self.get_secure_cookie(auth_const.OPENID)
+ curr_user_role = self.get_secure_cookie(auth_const.ROLE)
+ if curr_user is not None:
+ query = {'_id': objectid.ObjectId(result_id)}
+ test_data = yield dbapi.db_find_one(self.table, query)
+ if not test_data:
+ raises.NotFound(message.not_found(self.table, query))
+ if curr_user == test_data['owner'] or \
+ curr_user_role.find('administrator') != -1:
+ self._delete(query=query)
+ else:
+ raises.Forbidden(message.no_auth())
+ else:
+ raises.Unauthorized(message.no_auth())
@swagger.operation(nickname='getTestResultById')
def get(self, result_id):