From 1f6a8972256f31809cee9514abca4215d96152bd Mon Sep 17 00:00:00 2001 From: maopengzhang Date: Sat, 24 Nov 2018 15:22:42 +0800 Subject: fix VNF query result none exception fix VNF query result none exception Change-Id: Id1266a88f400d671deea4da54908ae9a9f908d0d Issue-ID: VFC-989 Signed-off-by: maopengzhang --- lcm/lcm/nf/biz/query_vnf.py | 9 +++++---- lcm/lcm/nf/tests/test_query_vnf.py | 3 +-- lcm/lcm/nf/views/curd_vnf_views.py | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lcm/lcm/nf/biz/query_vnf.py b/lcm/lcm/nf/biz/query_vnf.py index c735e0b7..1dd7c2d1 100644 --- a/lcm/lcm/nf/biz/query_vnf.py +++ b/lcm/lcm/nf/biz/query_vnf.py @@ -35,11 +35,12 @@ class QueryVnf: def query_multi_vnf(self): vnf_insts = NfInstModel.objects.all() - if not vnf_insts: - raise NFLCMException('VnfInsts does not exist.') + # if not vnf_insts: + # raise NFLCMException('VnfInsts does not exist.') resp_data = [] - for vnf_inst in vnf_insts: - resp_data.append(self.fill_resp_data(vnf_inst)) + if vnf_insts: + for vnf_inst in vnf_insts: + resp_data.append(self.fill_resp_data(vnf_inst)) return resp_data def fill_resp_data(self, vnf): diff --git a/lcm/lcm/nf/tests/test_query_vnf.py b/lcm/lcm/nf/tests/test_query_vnf.py index 1fbe9c7c..25824239 100644 --- a/lcm/lcm/nf/tests/test_query_vnf.py +++ b/lcm/lcm/nf/tests/test_query_vnf.py @@ -169,5 +169,4 @@ class ResourceTest(TestCase): def test_get_vnfs_not_exist(self): response = self.client.get("/api/vnflcm/v1/vnf_instances", format='json') - self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR) - self.assertEqual({'error': 'VnfInsts does not exist.'}, response.data) + self.assertEqual(response.status_code, status.HTTP_200_OK) diff --git a/lcm/lcm/nf/views/curd_vnf_views.py b/lcm/lcm/nf/views/curd_vnf_views.py index ae8a211a..25a98af8 100644 --- a/lcm/lcm/nf/views/curd_vnf_views.py +++ b/lcm/lcm/nf/views/curd_vnf_views.py @@ -42,7 +42,8 @@ class CreateVnfAndQueryVnfs(APIView): logger.debug("QueryMultiVnf--get::> %s" % request.data) try: resp_data = QueryVnf(request.data).query_multi_vnf() - + if len(resp_data) == 0: + return Response(data=[], status=status.HTTP_200_OK) vnf_instances_serializer = VnfInstancesSerializer(data=resp_data) if not vnf_instances_serializer.is_valid(): raise NFLCMException(vnf_instances_serializer.errors) -- cgit 1.2.3-korg