summaryrefslogtreecommitdiffstats
path: root/utils/test/result_collection_api/opnfv_testapi
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2016-06-09 02:10:01 +0800
committerSerenaFeng <feng.xiaowei@zte.com.cn>2016-06-09 02:17:39 +0800
commitcdff7d8d41693971f4c5dc8dd18d6907a5e31937 (patch)
treec6d0f727acb878544ead1e8a864338490c16d03f /utils/test/result_collection_api/opnfv_testapi
parent354761f94cdd7283740a487d5384ef9b233b66c3 (diff)
solve access testresults.opnfv.org/swagger/spec.html fail issue in testAPI
add swagger configuration in config.ini add swagger.docs() process in server.py add swagger configuration parse in config.py add basePath() in settings.py change 'basePath' item assignment in views.py JIRA: FUNCTEST-305 Change-Id: I049991d4d53b78755ee971021ec0ad2458f5da60 Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'utils/test/result_collection_api/opnfv_testapi')
-rw-r--r--utils/test/result_collection_api/opnfv_testapi/cmd/server.py2
-rw-r--r--utils/test/result_collection_api/opnfv_testapi/common/config.py12
-rw-r--r--utils/test/result_collection_api/opnfv_testapi/tornado_swagger/settings.py6
-rw-r--r--utils/test/result_collection_api/opnfv_testapi/tornado_swagger/views.py18
4 files changed, 21 insertions, 17 deletions
diff --git a/utils/test/result_collection_api/opnfv_testapi/cmd/server.py b/utils/test/result_collection_api/opnfv_testapi/cmd/server.py
index 9022b9aa1..c3d734607 100644
--- a/utils/test/result_collection_api/opnfv_testapi/cmd/server.py
+++ b/utils/test/result_collection_api/opnfv_testapi/cmd/server.py
@@ -49,6 +49,8 @@ CONF = APIConfig().parse(args.config_file)
client = motor.MotorClient(CONF.mongo_url)
db = client[CONF.mongo_dbname]
+swagger.docs(base_url=CONF.swagger_base_url)
+
def make_app():
return swagger.Application(
diff --git a/utils/test/result_collection_api/opnfv_testapi/common/config.py b/utils/test/result_collection_api/opnfv_testapi/common/config.py
index c444e67e3..ecab88ae3 100644
--- a/utils/test/result_collection_api/opnfv_testapi/common/config.py
+++ b/utils/test/result_collection_api/opnfv_testapi/common/config.py
@@ -37,6 +37,7 @@ class APIConfig:
self.api_port = None
self.api_debug_on = None
self._parser = None
+ self.swagger_base_url = None
def _get_parameter(self, section, param):
try:
@@ -78,6 +79,7 @@ class APIConfig:
obj.api_port = obj._get_int_parameter("api", "port")
obj.api_debug_on = obj._get_bool_parameter("api", "debug")
+ obj.swagger_base_url = obj._get_parameter("swagger", "base_url")
return obj
@@ -85,7 +87,9 @@ class APIConfig:
return "mongo_url = %s \n" \
"mongo_dbname = %s \n" \
"api_port = %s \n" \
- "api_debug_on = %s \n" % (self.mongo_url,
- self.mongo_dbname,
- self.api_port,
- self.api_debug_on)
+ "api_debug_on = %s \n" \
+ "swagger_base_url = %s \n" % (self.mongo_url,
+ self.mongo_dbname,
+ self.api_port,
+ self.api_debug_on,
+ self.swagger_base_url)
diff --git a/utils/test/result_collection_api/opnfv_testapi/tornado_swagger/settings.py b/utils/test/result_collection_api/opnfv_testapi/tornado_swagger/settings.py
index 001d55820..88d0d0f88 100644
--- a/utils/test/result_collection_api/opnfv_testapi/tornado_swagger/settings.py
+++ b/utils/test/result_collection_api/opnfv_testapi/tornado_swagger/settings.py
@@ -16,7 +16,7 @@ STATIC_PATH = os.path.join(os.path.dirname(os.path.normpath(__file__)),
'static')
default_settings = {
- 'base_url': '/',
+ 'base_url': '',
'static_path': STATIC_PATH,
'swagger_prefix': '/swagger',
'api_version': 'v1.0',
@@ -26,3 +26,7 @@ default_settings = {
}
models = []
+
+
+def basePath():
+ return default_settings.get('base_url')
diff --git a/utils/test/result_collection_api/opnfv_testapi/tornado_swagger/views.py b/utils/test/result_collection_api/opnfv_testapi/tornado_swagger/views.py
index 7190c671b..25083195b 100644
--- a/utils/test/result_collection_api/opnfv_testapi/tornado_swagger/views.py
+++ b/utils/test/result_collection_api/opnfv_testapi/tornado_swagger/views.py
@@ -6,15 +6,14 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-import urlparse
-import json
import inspect
+import json
-import tornado.web
import tornado.template
+import tornado.web
from settings import SWAGGER_VERSION, SWAGGER_API_LIST, SWAGGER_API_SPEC
-from settings import models
+from settings import models, basePath
def json_dumps(obj, pretty=False):
@@ -30,9 +29,7 @@ class SwaggerUIHandler(tornado.web.RequestHandler):
return self.static_path
def get(self):
- discovery_url = \
- urlparse.urljoin(self.request.full_url(),
- self.reverse_url(SWAGGER_API_LIST))
+ discovery_url = basePath() + self.reverse_url(SWAGGER_API_LIST)
self.render('index.html', discovery_url=discovery_url)
@@ -43,11 +40,10 @@ class SwaggerResourcesHandler(tornado.web.RequestHandler):
def get(self):
self.set_header('content-type', 'application/json')
- u = urlparse.urlparse(self.request.full_url())
resources = {
'apiVersion': self.api_version,
'swaggerVersion': SWAGGER_VERSION,
- 'basePath': '%s://%s' % (u.scheme, u.netloc),
+ 'basePath': basePath(),
'produces': ["application/json"],
'description': 'Test Api Spec',
'apis': [{
@@ -70,12 +66,10 @@ class SwaggerApiHandler(tornado.web.RequestHandler):
if apis is None:
raise tornado.web.HTTPError(404)
- base_path = urlparse.urljoin(self.request.full_url(),
- self.base_url)[:-1]
specs = {
'apiVersion': self.api_version,
'swaggerVersion': SWAGGER_VERSION,
- 'basePath': base_path,
+ 'basePath': basePath(),
'apis': [self.__get_api_spec__(path, spec, operations)
for path, spec, operations in apis],
'models': self.__get_models_spec(models)