summaryrefslogtreecommitdiffstats
path: root/lcm
diff options
context:
space:
mode:
authorlaili <lai.li@zte.com.cn>2018-08-17 15:35:57 +0800
committerlaili <lai.li@zte.com.cn>2018-08-17 15:35:57 +0800
commit9e6a8075db99f06574cd483bf42d30550f9aca46 (patch)
treeec2fd1099e867a8b0e8870ee0dc0d0f588a62a72 /lcm
parentd2dc48b3cec803261a2673cac09a7fffefd43e7e (diff)
Dealing with test related stuffs.
Add test methods to test vnf query. Change-Id: Ief5fa9b1e8faf380a3a182b9c5c20c3dd15d631a Issue-ID: VFC-1012 Signed-off-by: laili <lai.li@zte.com.cn>
Diffstat (limited to 'lcm')
-rw-r--r--lcm/lcm/nf/biz/query_vnf.py7
-rw-r--r--lcm/lcm/nf/tests/test_query_vnf.py33
-rw-r--r--lcm/lcm/nf/views/curd_vnf_views.py2
3 files changed, 35 insertions, 7 deletions
diff --git a/lcm/lcm/nf/biz/query_vnf.py b/lcm/lcm/nf/biz/query_vnf.py
index bd4a1e3a..09fab6ca 100644
--- a/lcm/lcm/nf/biz/query_vnf.py
+++ b/lcm/lcm/nf/biz/query_vnf.py
@@ -29,14 +29,14 @@ class QueryVnf:
def query_single_vnf(self):
vnf_inst = NfInstModel.objects.filter(nfinstid=self.vnf_inst_id)
if not vnf_inst.exists():
- raise NFLCMException('VnfInst(%s) does not exist' % self.vnf_inst_id)
+ raise NFLCMException('VnfInst(%s) does not exist.' % self.vnf_inst_id)
resp_data = self.fill_resp_data(vnf_inst[0])
return resp_data
def query_multi_vnf(self):
vnf_insts = NfInstModel.objects.all()
if not vnf_insts:
- raise NFLCMException('VnfInsts does not exist')
+ raise NFLCMException('VnfInsts does not exist.')
resp_data = []
for vnf_inst in vnf_insts:
resp_data.append(self.fill_resp_data(vnf_inst))
@@ -78,7 +78,8 @@ class QueryVnf:
vm = VmInstModel.objects.filter(vmid=vnfc.vmid)
if not vm:
raise NFLCMException('VmInst(%s) does not exist.' % vnfc.vmid)
- storage = StorageInstModel.objects.filter(ownerid=vm[0].vmid)
+ storage = StorageInstModel.objects.filter(vimid=vm[0].vmid)
+ # TODO: previously, ownerid=vm[0].vmid, but ownerid is not a field of StorageInstModel.
if not storage:
raise NFLCMException('StorageInst(%s) does not exist.' % vm[0].vmid)
vnfc_dic = {
diff --git a/lcm/lcm/nf/tests/test_query_vnf.py b/lcm/lcm/nf/tests/test_query_vnf.py
index 40151850..95f387b9 100644
--- a/lcm/lcm/nf/tests/test_query_vnf.py
+++ b/lcm/lcm/nf/tests/test_query_vnf.py
@@ -15,7 +15,8 @@
from django.test import TestCase, Client
from rest_framework import status
-from lcm.pub.database.models import NfInstModel, StorageInstModel
+from lcm.pub.database.models import (NfInstModel, VLInstModel,
+ VNFCInstModel, VmInstModel, StorageInstModel)
class ResourceTest(TestCase):
@@ -125,7 +126,33 @@ class ResourceTest(TestCase):
def test_get_vnf_not_exist(self):
response = self.client.get("/api/vnflcm/v1/vnf_instances/x", format='json')
self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
- self.assertEqual({'error': 'VnfInst(x) does not exist'}, response.data)
+ self.assertEqual({'error': 'VnfInst(x) does not exist.'}, response.data)
+
+ def test_get_vnf_net_not_exist(self):
+ vnf_inst_id = "1"
+ NfInstModel(nfinstid=vnf_inst_id, nf_name='VNF1', status='INSTANTIATED').save()
+ VLInstModel(ownerid=vnf_inst_id, relatednetworkid='x', ownertype='0').save()
+ response = self.client.get("/api/vnflcm/v1/vnf_instances/%s" % vnf_inst_id, format='json')
+ self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
+ self.assertEqual({'error': 'NetworkInst(x) does not exist.'}, response.data)
+
+ def test_get_vnf_vm_not_exist(self):
+ vnf_inst_id = "1"
+ NfInstModel(nfinstid=vnf_inst_id, nf_name='VNF1', status='INSTANTIATED').save()
+ VNFCInstModel(instid=vnf_inst_id, vmid='x').save()
+ response = self.client.get("/api/vnflcm/v1/vnf_instances/%s" % vnf_inst_id, format='json')
+ self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
+ self.assertEqual({'error': 'VmInst(x) does not exist.'}, response.data)
+
+ def test_get_vnf_storage_not_exist(self):
+ vnf_inst_id = "1"
+ NfInstModel(nfinstid=vnf_inst_id, nf_name='VNF1', status='INSTANTIATED').save()
+ VNFCInstModel(instid=vnf_inst_id,
+ vmid='x',).save()
+ VmInstModel(vmid='x', insttype='0').save()
+ response = self.client.get("/api/vnflcm/v1/vnf_instances/%s" % vnf_inst_id, format='json')
+ self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
+ self.assertEqual({'error': 'StorageInst(x) does not exist.'}, response.data)
def test_get_vnfs(self):
for i in range(1, 3):
@@ -144,4 +171,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({'error': 'VnfInsts does not exist.'}, response.data)
diff --git a/lcm/lcm/nf/views/curd_vnf_views.py b/lcm/lcm/nf/views/curd_vnf_views.py
index efd85168..5c5f407e 100644
--- a/lcm/lcm/nf/views/curd_vnf_views.py
+++ b/lcm/lcm/nf/views/curd_vnf_views.py
@@ -109,7 +109,7 @@ class DeleteVnfAndQueryVnf(APIView):
logger.error(e.message)
return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
except Exception as e:
- logger.eror(e.message)
+ logger.error(e.message)
logger.error(traceback.format_exc())
return Response(data={'error': 'Failed to get Vnf(%s)' % instanceid},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)