Refactor vfc-vnflcm swagger query logic 93/25393/1
authorying.yunlong <ying.yunlong@zte.com.cn>
Thu, 23 Nov 2017 07:12:00 +0000 (15:12 +0800)
committeryunlong ying <ying.yunlong@zte.com.cn>
Mon, 4 Dec 2017 06:39:16 +0000 (06:39 +0000)
Change-Id: Iac0287fb53a6f5635f9bafe0152cb5e6d95cf162
Issue-ID: VFC-589
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
(cherry picked from commit 8caba28ed1db2c346185b2e7549cb4eb8be0778e)

lcm/lcm/nf/vnfs/tests/test_vnf_create.py
lcm/lcm/nf/vnfs/urls.py
lcm/lcm/nf/vnfs/views.py
lcm/lcm/settings.py
lcm/lcm/swagger/__init__.py [new file with mode: 0644]
lcm/lcm/swagger/swagger.json [moved from lcm/lcm/nf/vnfs/swagger.json with 100% similarity]
lcm/lcm/swagger/tests.py [new file with mode: 0644]
lcm/lcm/swagger/urls.py [new file with mode: 0644]
lcm/lcm/swagger/views.py [new file with mode: 0644]
lcm/lcm/urls.py

index 3260c2d..537171e 100644 (file)
@@ -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(
index 5be0073..7e88f30 100644 (file)
@@ -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)
index 1062d3a..2330fa2 100644 (file)
@@ -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)
index 5583c4c..f4b7826 100644 (file)
@@ -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 (file)
index 0000000..c7b6818
--- /dev/null
@@ -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/swagger/tests.py b/lcm/lcm/swagger/tests.py
new file mode 100644 (file)
index 0000000..f65f699
--- /dev/null
@@ -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 (file)
index 0000000..6764a1d
--- /dev/null
@@ -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 (file)
index 0000000..400d6dd
--- /dev/null
@@ -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)
index e60108b..a4ebda9 100644 (file)
@@ -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