aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lcm/ns/tests/test_ns_create.py2
-rw-r--r--lcm/ns/views/deprecated/create_ns_view.py82
-rw-r--r--lcm/ns/views/deprecated/get_del_ns_view.py40
3 files changed, 56 insertions, 68 deletions
diff --git a/lcm/ns/tests/test_ns_create.py b/lcm/ns/tests/test_ns_create.py
index dee1fcbb..ef00a6e1 100644
--- a/lcm/ns/tests/test_ns_create.py
+++ b/lcm/ns/tests/test_ns_create.py
@@ -49,7 +49,6 @@ class TestNsInstantiate(TestCase):
def test_create_ns_empty_data(self, mock_do_biz):
mock_do_biz.side_effect = Exception("Exception in CreateNS.")
response = self.client.post("/api/nslcm/v1/ns", data={})
- self.assertEqual(response.data["error"], "Exception in CreateNS.")
self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
self.assertIn("error", response.data)
@@ -58,7 +57,6 @@ class TestNsInstantiate(TestCase):
mock_do_biz.side_effect = Exception("nsd not exists.")
self.create_ns_dict["csarId"] = "1"
response = self.client.post("/api/nslcm/v1/ns", data=self.create_ns_dict, format='json')
- self.assertEqual(response.data["error"], "nsd not exists.")
self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
self.assertIn("error", response.data)
diff --git a/lcm/ns/views/deprecated/create_ns_view.py b/lcm/ns/views/deprecated/create_ns_view.py
index 4fb6f938..428b5eca 100644
--- a/lcm/ns/views/deprecated/create_ns_view.py
+++ b/lcm/ns/views/deprecated/create_ns_view.py
@@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
-import traceback
from drf_yasg.utils import swagger_auto_schema
from rest_framework import status
@@ -27,6 +26,7 @@ from lcm.ns.serializers.deprecated.ns_serializers import _QueryNsRespSerializer
from lcm.pub.exceptions import NSLCMException
from lcm.pub.exceptions import BadRequestException
from lcm.pub.utils.values import ignore_case_get
+from .common import view_safe_call_with_log
logger = logging.getLogger(__name__)
@@ -39,19 +39,15 @@ class CreateNSView(APIView):
status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error"
}
)
+ @view_safe_call_with_log(logger=logger)
def get(self, request):
- try:
- logger.debug("CreateNSView::get")
- ret = GetNSInfoService().get_ns_info()
- logger.debug("CreateNSView::get::ret=%s", ret)
- resp_serializer = _QueryNsRespSerializer(data=ret, many=True)
- if not resp_serializer.is_valid():
- raise NSLCMException(resp_serializer.errors)
- return Response(data=resp_serializer.data, status=status.HTTP_200_OK)
- except Exception as e:
- logger.error(traceback.format_exc())
- logger.error("Exception in GetNS: %s", e.args[0])
- return Response(data={'error': e.args[0]}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ logger.debug("CreateNSView::get")
+ ret = GetNSInfoService().get_ns_info()
+ logger.debug("CreateNSView::get::ret=%s", ret)
+ resp_serializer = _QueryNsRespSerializer(data=ret, many=True)
+ if not resp_serializer.is_valid():
+ raise NSLCMException(resp_serializer.errors)
+ return Response(data=resp_serializer.data, status=status.HTTP_200_OK)
@swagger_auto_schema(
request_body=_CreateNsReqSerializer(),
@@ -61,36 +57,38 @@ class CreateNSView(APIView):
status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error"
}
)
+ @view_safe_call_with_log(logger=logger)
def post(self, request):
logger.debug("Enter CreateNS: %s", request.data)
- try:
- req_serializer = _CreateNsReqSerializer(data=request.data)
- if not req_serializer.is_valid():
- raise BadRequestException(req_serializer.errors)
+ req_serializer = _CreateNsReqSerializer(data=request.data)
+ if not req_serializer.is_valid():
+ raise BadRequestException(req_serializer.errors)
- if ignore_case_get(request.data, 'test') == "test":
- return Response(data={'nsInstanceId': "test"}, status=status.HTTP_201_CREATED)
- csar_id = ignore_case_get(request.data, 'csarId')
- ns_name = ignore_case_get(request.data, 'nsName')
- description = ignore_case_get(request.data, 'description')
- context = ignore_case_get(request.data, 'context')
- ns_inst_id = CreateNSService(csar_id, ns_name, description, context).do_biz()
+ if ignore_case_get(request.data, 'test') == "test":
+ return Response(
+ data={'nsInstanceId': "test"},
+ status=status.HTTP_201_CREATED
+ )
+ csar_id = ignore_case_get(request.data, 'csarId')
+ ns_name = ignore_case_get(request.data, 'nsName')
+ description = ignore_case_get(request.data, 'description')
+ context = ignore_case_get(request.data, 'context')
+ ns_inst_id = CreateNSService(
+ csar_id,
+ ns_name,
+ description,
+ context
+ ).do_biz()
- logger.debug("CreateNSView::post::ret={'nsInstanceId':%s}", ns_inst_id)
- resp_serializer = _CreateNsRespSerializer(
- data={'nsInstanceId': ns_inst_id,
- 'nsInstanceName': 'nsInstanceName',
- 'nsInstanceDescription': 'nsInstanceDescription',
- 'nsdId': 123,
- 'nsdInfoId': 456,
- 'nsState': 'NOT_INSTANTIATED',
- '_links': {'self': {'href': 'href'}}})
- if not resp_serializer.is_valid():
- raise NSLCMException(resp_serializer.errors)
- return Response(data=resp_serializer.data, status=status.HTTP_201_CREATED)
- except BadRequestException as e:
- return Response(data={'error': e.args[0]}, status=status.HTTP_400_BAD_REQUEST)
- except Exception as e:
- logger.error(traceback.format_exc())
- logger.error("Exception in CreateNS: %s", e.args[0])
- return Response(data={'error': e.args[0]}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ logger.debug("CreateNSView::post::ret={'nsInstanceId':%s}", ns_inst_id)
+ resp_serializer = _CreateNsRespSerializer(
+ data={'nsInstanceId': ns_inst_id,
+ 'nsInstanceName': 'nsInstanceName',
+ 'nsInstanceDescription': 'nsInstanceDescription',
+ 'nsdId': 123,
+ 'nsdInfoId': 456,
+ 'nsState': 'NOT_INSTANTIATED',
+ '_links': {'self': {'href': 'href'}}})
+ if not resp_serializer.is_valid():
+ raise NSLCMException(resp_serializer.errors)
+ return Response(data=resp_serializer.data, status=status.HTTP_201_CREATED)
diff --git a/lcm/ns/views/deprecated/get_del_ns_view.py b/lcm/ns/views/deprecated/get_del_ns_view.py
index 2bb34c05..db5a4466 100644
--- a/lcm/ns/views/deprecated/get_del_ns_view.py
+++ b/lcm/ns/views/deprecated/get_del_ns_view.py
@@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
-import traceback
from drf_yasg.utils import swagger_auto_schema
from rest_framework import status
@@ -23,6 +22,7 @@ from lcm.ns.biz.ns_delete import DeleteNsService
from lcm.ns.biz.ns_get import GetNSInfoService
from lcm.pub.exceptions import NSLCMException
from lcm.ns.serializers.deprecated.ns_serializers import _QueryNsRespSerializer
+from .common import view_safe_call_with_log
logger = logging.getLogger(__name__)
@@ -36,22 +36,18 @@ class NSDetailView(APIView):
status.HTTP_404_NOT_FOUND: "Ns instance does not exist"
}
)
+ @view_safe_call_with_log(logger=logger)
def get(self, request, ns_instance_id):
- try:
- logger.debug("Enter NSDetailView::get ns(%s)", ns_instance_id)
- ns_filter = {"ns_inst_id": ns_instance_id}
- ret = GetNSInfoService(ns_filter).get_ns_info()
- if not ret:
- return Response(status=status.HTTP_404_NOT_FOUND)
- logger.debug("Leave NSDetailView::get::ret=%s", ret)
- resp_serializer = _QueryNsRespSerializer(data=ret[0])
- if not resp_serializer.is_valid():
- raise NSLCMException(resp_serializer.errors)
- return Response(data=resp_serializer.data, status=status.HTTP_200_OK)
- except Exception as e:
- logger.error(traceback.format_exc())
- logger.error("Exception in GetNSDetail: %s", e.args[0])
- return Response(data={'error': e.args[0]}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ logger.debug("Enter NSDetailView::get ns(%s)", ns_instance_id)
+ ns_filter = {"ns_inst_id": ns_instance_id}
+ ret = GetNSInfoService(ns_filter).get_ns_info()
+ if not ret:
+ return Response(status=status.HTTP_404_NOT_FOUND)
+ logger.debug("Leave NSDetailView::get::ret=%s", ret)
+ resp_serializer = _QueryNsRespSerializer(data=ret[0])
+ if not resp_serializer.is_valid():
+ raise NSLCMException(resp_serializer.errors)
+ return Response(data=resp_serializer.data, status=status.HTTP_200_OK)
@swagger_auto_schema(
request_body=None,
@@ -60,12 +56,8 @@ class NSDetailView(APIView):
status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error"
}
)
+ @view_safe_call_with_log(logger=logger)
def delete(self, request, ns_instance_id):
- try:
- logger.debug("Enter NSDetailView::delete ns(%s)", ns_instance_id)
- DeleteNsService(ns_instance_id).do_biz()
- return Response(data={}, status=status.HTTP_204_NO_CONTENT)
- except Exception as e:
- logger.error(traceback.format_exc())
- logger.error("Exception in delete NS: %s", e.args[0])
- return Response(data={'error': e.args[0]}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ logger.debug("Enter NSDetailView::delete ns(%s)", ns_instance_id)
+ DeleteNsService(ns_instance_id).do_biz()
+ return Response(data={}, status=status.HTTP_204_NO_CONTENT)