summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2017-11-23 15:12:00 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2017-11-23 15:12:00 +0800
commit8caba28ed1db2c346185b2e7549cb4eb8be0778e (patch)
tree6d87e4b5abba4ab1504b1f1dccf4e707a5c8ebc3
parent810981f10c7730bf5c6c39fd4ed33c1f54242067 (diff)
Refactor vfc-vnflcm swagger query logic
Change-Id: Iac0287fb53a6f5635f9bafe0152cb5e6d95cf162 Issue-ID: VFC-589 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
-rw-r--r--lcm/lcm/nf/vnfs/tests/test_vnf_create.py4
-rw-r--r--lcm/lcm/nf/vnfs/urls.py3
-rw-r--r--lcm/lcm/nf/vnfs/views.py11
-rw-r--r--lcm/lcm/settings.py3
-rw-r--r--lcm/lcm/swagger/__init__.py13
-rw-r--r--lcm/lcm/swagger/swagger.json (renamed from lcm/lcm/nf/vnfs/swagger.json)0
-rw-r--r--lcm/lcm/swagger/tests.py30
-rw-r--r--lcm/lcm/swagger/urls.py20
-rw-r--r--lcm/lcm/swagger/views.py26
-rw-r--r--lcm/lcm/urls.py1
10 files changed, 93 insertions, 18 deletions
diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
index 3260c2db..537171e3 100644
--- a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
+++ b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
@@ -43,10 +43,6 @@ class TestNFInstantiate(TestCase):
descp=job_detail)
self.assertEqual(1, len(jobs))
- def test_swagger_ok(self):
- response = self.client.get("/api/vnflcm/v1/swagger.json", format='json')
- self.assertEqual(response.status_code, status.HTTP_200_OK)
-
@mock.patch.object(restcall, 'call_req')
def test_create_vnf_identifier(self, mock_call_req):
r1_get_csarid_by_vnfdid = [0, json.JSONEncoder().encode(
diff --git a/lcm/lcm/nf/vnfs/urls.py b/lcm/lcm/nf/vnfs/urls.py
index 5be0073e..7e88f30a 100644
--- a/lcm/lcm/nf/vnfs/urls.py
+++ b/lcm/lcm/nf/vnfs/urls.py
@@ -15,7 +15,7 @@
from django.conf.urls import patterns, url
from rest_framework.urlpatterns import format_suffix_patterns
-from lcm.nf.vnfs.views import InstantiateVnf, TerminateVnf, SwaggerJsonView, DeleteVnfAndQueryVnf, CreateVnfAndQueryVnfs
+from lcm.nf.vnfs.views import InstantiateVnf, TerminateVnf, DeleteVnfAndQueryVnf, CreateVnfAndQueryVnfs
urlpatterns = patterns('',
url(r'^api/vnflcm/v1/vnf_instances$', CreateVnfAndQueryVnfs.as_view()),
@@ -25,7 +25,6 @@ urlpatterns = patterns('',
DeleteVnfAndQueryVnf.as_view()),
url(r'^api/vnflcm/v1/vnf_instances/(?P<instanceid>[0-9a-zA-Z_-]+)/terminate$',
TerminateVnf.as_view()),
- url(r'^api/vnflcm/v1/swagger.json$', SwaggerJsonView.as_view())
)
urlpatterns = format_suffix_patterns(urlpatterns)
diff --git a/lcm/lcm/nf/vnfs/views.py b/lcm/lcm/nf/vnfs/views.py
index 1062d3a1..2330fa2c 100644
--- a/lcm/lcm/nf/vnfs/views.py
+++ b/lcm/lcm/nf/vnfs/views.py
@@ -12,9 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import json
import logging
-import os
import traceback
from rest_framework import status
@@ -119,12 +117,3 @@ class TerminateVnf(APIView):
return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
rsp = {"jobId": job_id}
return Response(data=rsp, status=status.HTTP_202_ACCEPTED)
-
-
-class SwaggerJsonView(APIView):
- def get(self, request):
- json_file = os.path.join(os.path.dirname(__file__), 'swagger.json')
- f = open(json_file)
- json_data = json.JSONDecoder().decode(f.read())
- f.close()
- return Response(json_data)
diff --git a/lcm/lcm/settings.py b/lcm/lcm/settings.py
index 5583c4cd..f4b7826b 100644
--- a/lcm/lcm/settings.py
+++ b/lcm/lcm/settings.py
@@ -44,7 +44,8 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'rest_framework',
'lcm.pub.database',
- 'lcm.samples'
+ 'lcm.samples',
+ 'lcm.swagger'
]
MIDDLEWARE_CLASSES = [
diff --git a/lcm/lcm/swagger/__init__.py b/lcm/lcm/swagger/__init__.py
new file mode 100644
index 00000000..c7b6818e
--- /dev/null
+++ b/lcm/lcm/swagger/__init__.py
@@ -0,0 +1,13 @@
+# Copyright 2017 ZTE Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
diff --git a/lcm/lcm/nf/vnfs/swagger.json b/lcm/lcm/swagger/swagger.json
index a15556dc..a15556dc 100644
--- a/lcm/lcm/nf/vnfs/swagger.json
+++ b/lcm/lcm/swagger/swagger.json
diff --git a/lcm/lcm/swagger/tests.py b/lcm/lcm/swagger/tests.py
new file mode 100644
index 00000000..f65f6990
--- /dev/null
+++ b/lcm/lcm/swagger/tests.py
@@ -0,0 +1,30 @@
+# Copyright 2017 ZTE Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import unittest
+
+from django.test import Client
+from rest_framework import status
+
+
+class SwaggerViewTest(unittest.TestCase):
+ def setUp(self):
+ self.client = Client()
+
+ def tearDown(self):
+ pass
+
+ def test_swagger(self):
+ response = self.client.get("/api/vnflcm/v1/swagger.json")
+ self.assertEqual(status.HTTP_200_OK, response.status_code, response.content)
diff --git a/lcm/lcm/swagger/urls.py b/lcm/lcm/swagger/urls.py
new file mode 100644
index 00000000..6764a1d4
--- /dev/null
+++ b/lcm/lcm/swagger/urls.py
@@ -0,0 +1,20 @@
+# Copyright 2017 ZTE Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from django.conf.urls import url
+from lcm.swagger import views
+
+urlpatterns = [
+ url(r'^api/vnflcm/v1/swagger.json$', views.SwaggerView.as_view())
+]
diff --git a/lcm/lcm/swagger/views.py b/lcm/lcm/swagger/views.py
new file mode 100644
index 00000000..400d6dd1
--- /dev/null
+++ b/lcm/lcm/swagger/views.py
@@ -0,0 +1,26 @@
+# Copyright 2017 ZTE Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+import os
+import json
+from rest_framework.views import APIView
+from rest_framework.response import Response
+
+
+class SwaggerView(APIView):
+ def get(self, request, format=None):
+ json_file = os.path.join(os.path.dirname(__file__), 'swagger.json')
+ f = open(json_file)
+ json_data = json.JSONDecoder().decode(f.read())
+ f.close()
+ return Response(json_data)
diff --git a/lcm/lcm/urls.py b/lcm/lcm/urls.py
index e60108b8..a4ebda98 100644
--- a/lcm/lcm/urls.py
+++ b/lcm/lcm/urls.py
@@ -19,6 +19,7 @@ urlpatterns = [
url(r'^', include('lcm.samples.urls')),
url(r'^', include('lcm.nf.vnfs.urls')),
url(r'^', include('lcm.jobs.urls')),
+ url(r'^', include('lcm.swagger.urls')),
]
# regist to MSB when startup