aboutsummaryrefslogtreecommitdiffstats
path: root/opnfv_testapi/resources/result_handlers.py
diff options
context:
space:
mode:
authorDan Xu <xudan16@huawei.com>2019-03-22 07:44:31 +0000
committerGerrit Code Review <gerrit@opnfv.org>2019-03-22 07:44:31 +0000
commitaab171fe0b7b749a7414cc8d652b5f4662743106 (patch)
tree2108f5db2442bdbbd327ee80f2a17c9bf496d079 /opnfv_testapi/resources/result_handlers.py
parent3b78fa2aeb6c69efb86c68ba5f6c7d7efccfb024 (diff)
parentd0bbf3b8952379883550c6eb2062476a6d15043e (diff)
Merge changes I36bbb6e6,I2f597763
* changes: Enable Web Portal for ONAP results Prepare Web Portal for ONAP integration
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):