1 # Copyright 2017 ZTE Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 from django.test import TestCase, Client
16 from rest_framework import status
18 from lcm.pub.database.models import (NfInstModel, VLInstModel,
19 VNFCInstModel, VmInstModel, StorageInstModel)
22 class ResourceTest(TestCase):
24 self.client = Client()
25 self.nf_inst_id = "01"
26 NfInstModel.objects.all().delete()
27 self.test_data_single_vnf = {
29 "vnfInstanceName": "VNF1",
30 "vnfInstanceDescription": "VNF DESC",
33 "vnfProductName": "XGW",
34 "vnfSoftwareVersion": "V1",
37 "instantiationState": "INSTANTIATED",
38 "instantiatedVnfInfo": {
39 "vnfState": "STARTED",
41 "virtualStorageResourceInfo": [
45 "resourceId": "resource01",
46 "vimConnectionId": "vim01"
50 "extVirtualLinkInfo": [],
51 "vnfcResourceInfo": [],
52 "monitoringParameters": [],
54 "vnfVirtualLinkResourceInfo": [],
58 self.test_data_multi_vnf = [
61 "vnfInstanceName": "VNF1",
62 "vnfInstanceDescription": "VNF DESC",
65 "vnfProductName": "XGW",
66 "vnfSoftwareVersion": "V1",
69 "instantiationState": "INSTANTIATED",
70 "instantiatedVnfInfo": {
71 "vnfState": "STARTED",
73 "virtualStorageResourceInfo": [
77 "resourceId": "resource01",
78 "vimConnectionId": "vim01"
82 "extVirtualLinkInfo": [],
83 "vnfcResourceInfo": [],
84 "monitoringParameters": [],
86 "vnfVirtualLinkResourceInfo": [],
92 "vnfInstanceName": "VNF2",
93 "vnfInstanceDescription": "VNF DESC",
96 "vnfProductName": "XGW",
97 "vnfSoftwareVersion": "V1",
100 "instantiationState": "INSTANTIATED",
101 "instantiatedVnfInfo": {
102 "vnfState": "STARTED",
104 "virtualStorageResourceInfo": [
108 "resourceId": "resource02",
109 "vimConnectionId": "vim02"
113 "extVirtualLinkInfo": [],
114 "vnfcResourceInfo": [],
115 "monitoringParameters": [],
117 "vnfVirtualLinkResourceInfo": [],
126 def test_get_vnf(self):
128 NfInstModel(nfinstid=vnf_inst_id,
134 vnfSoftwareVersion="V1",
137 status='INSTANTIATED').save()
138 StorageInstModel(storageid='s02',
140 resourceid='resource01',
142 instid=vnf_inst_id).save()
143 response = self.client.get("/api/vnflcm/v1/vnf_instances/%s" % vnf_inst_id, format='json')
144 self.assertEqual(response.status_code, status.HTTP_200_OK)
145 self.assertEqual(self.test_data_single_vnf, response.data)
147 def test_get_vnf_not_exist(self):
148 response = self.client.get("/api/vnflcm/v1/vnf_instances/x", format='json')
149 self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
151 'detail': 'VnfInst(x) does not exist.',
155 def test_get_vnf_net_not_exist(self):
157 NfInstModel(nfinstid=vnf_inst_id,
162 vnfSoftwareVersion="V1",
165 status='INSTANTIATED').save()
166 VLInstModel(ownerid=vnf_inst_id,
167 relatednetworkid='x',
168 ownertype='0').save()
169 response = self.client.get("/api/vnflcm/v1/vnf_instances/%s" % vnf_inst_id, format='json')
170 self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
172 'detail': 'NetworkInst(x) does not exist.',
176 def test_get_vnf_vm_not_exist(self):
178 NfInstModel(nfinstid=vnf_inst_id,
183 vnfSoftwareVersion="V1",
186 status='INSTANTIATED').save()
187 VNFCInstModel(instid=vnf_inst_id,
189 response = self.client.get("/api/vnflcm/v1/vnf_instances/%s" % vnf_inst_id, format='json')
190 self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
192 'detail': 'VmInst(x) does not exist.',
196 def test_get_vnf_storage_not_exist(self):
198 NfInstModel(nfinstid=vnf_inst_id,
203 vnfSoftwareVersion="V1",
206 status='INSTANTIATED').save()
207 VNFCInstModel(instid=vnf_inst_id,
209 VmInstModel(vmid='x', insttype='0').save()
210 response = self.client.get("/api/vnflcm/v1/vnf_instances/%s" % vnf_inst_id, format='json')
211 self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
213 def test_get_vnfs(self):
214 for i in range(1, 3):
215 NfInstModel(nfinstid='%s' % i,
221 vnfSoftwareVersion="V1",
224 status='INSTANTIATED').save()
225 StorageInstModel(storageid='s0%s' % i,
227 resourceid='resource0%s' % i,
229 instid='%s' % i).save()
230 response = self.client.get("/api/vnflcm/v1/vnf_instances", format='json')
231 self.assertEqual(status.HTTP_200_OK, response.status_code)
232 self.assertEqual(self.test_data_multi_vnf, response.data)
234 def test_get_vnfs_not_exist(self):
235 response = self.client.get("/api/vnflcm/v1/vnf_instances", format='json')
236 self.assertEqual(response.status_code, status.HTTP_200_OK)