summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormaopengzhang <zhang.maopeng1@zte.com.cn>2018-11-24 15:22:42 +0800
committermaopengzhang <zhang.maopeng1@zte.com.cn>2018-11-24 23:43:58 +0800
commit1f6a8972256f31809cee9514abca4215d96152bd (patch)
tree2e6212edcf672b00d5c6c27f608ea37d55fb1347
parent1be16bee6fc098097aa28eba07ff7ab624901010 (diff)
fix VNF query result none exception
fix VNF query result none exception Change-Id: Id1266a88f400d671deea4da54908ae9a9f908d0d Issue-ID: VFC-989 Signed-off-by: maopengzhang <zhang.maopeng1@zte.com.cn>
-rw-r--r--lcm/lcm/nf/biz/query_vnf.py9
-rw-r--r--lcm/lcm/nf/tests/test_query_vnf.py3
-rw-r--r--lcm/lcm/nf/views/curd_vnf_views.py3
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)