summaryrefslogtreecommitdiffstats
path: root/cvp/opnfv_testapi/resources
diff options
context:
space:
mode:
authorchenjiankun <chenjiankun1@huawei.com>2018-04-26 07:34:43 +0000
committerchenjiankun <chenjiankun1@huawei.com>2018-04-26 07:55:46 +0000
commit67de42416576c952ec0d6a159a0d57fc4cabc414 (patch)
tree5ec8c9cc7bc0a0baff5a16139a57b252d58db4e4 /cvp/opnfv_testapi/resources
parentcb02bccdef30575bb46080475ca13fdf8b6b4b2f (diff)
Extend web portal to show if API exemption was used during a test run
JIRA: DOVETAIL-634 The OVP web port needs to read from the test results if the strict API response validation exemption was used or not and show it correspondingly. Detailed description: As discussed on the Dovetail call on 2018-04-11, the web portal should show if API response validation was enabled or disabled. The information if API response validation was enabled or disabled is to be determined based on the dovetail.log file. If API response validation was disabled,** the log file contains the line "Strict API response validation DISABLED.". Upon uploading a result tar-package, the web portal should extract this information from the log file, store it in the database, and display it as follows: This indication shall be displayed along with the test summary on the Test Run Results page as either: "API response validation enabled" or "API response validation disabled" For clarification: API response validation is enabled by default. API response validation is disabled only if the --no-api-validation command line option is given. Change-Id: Ifacb1eb2127cc8dc6364c98dead1217aeedfd359 Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
Diffstat (limited to 'cvp/opnfv_testapi/resources')
-rw-r--r--cvp/opnfv_testapi/resources/test_handlers.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/cvp/opnfv_testapi/resources/test_handlers.py b/cvp/opnfv_testapi/resources/test_handlers.py
index 77656ae9..9adc0d82 100644
--- a/cvp/opnfv_testapi/resources/test_handlers.py
+++ b/cvp/opnfv_testapi/resources/test_handlers.py
@@ -7,6 +7,7 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
import logging
+import os
import json
from tornado import web
@@ -15,12 +16,15 @@ 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.resources import handlers
from opnfv_testapi.resources import test_models
from opnfv_testapi.tornado_swagger import swagger
from opnfv_testapi.ui.auth import constants as auth_const
from opnfv_testapi.db import api as dbapi
+DOVETAIL_LOG_PATH = '/home/testapi/logs/{}/results/dovetail.log'
+
class GenericTestHandler(handlers.GenericApiHandler):
def __init__(self, application, request, **kwargs):
@@ -109,10 +113,36 @@ class TestsCLHandler(GenericTestHandler):
class TestsGURHandler(GenericTestHandler):
@swagger.operation(nickname="getTestById")
+ @web.asynchronous
+ @gen.coroutine
def get(self, test_id):
query = dict()
query["_id"] = objectid.ObjectId(test_id)
- self._get_one(query=query)
+
+ data = yield dbapi.db_find_one(self.table, query)
+ if not data:
+ raises.NotFound(message.not_found(self.table, query))
+
+ validation = yield self._check_api_response_validation(data['id'])
+
+ data.update({'validation': validation})
+
+ self.finish_request(self.format_data(data))
+
+ @gen.coroutine
+ def _check_api_response_validation(self, test_id):
+ log_path = DOVETAIL_LOG_PATH.format(test_id)
+ if not os.path.exists(log_path):
+ raises.Forbidden('dovetail.log not found, please check')
+
+ with open(log_path) as f:
+ log_content = f.read()
+
+ warning_keyword = 'Strict API response validation DISABLED'
+ if warning_keyword in log_content:
+ raise gen.Return('API response validation disable')
+ else:
+ raise gen.Return('API response validation enable')
@swagger.operation(nickname="deleteTestById")
def delete(self, test_id):