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, StorageInstModel
21 class ResourceTest(TestCase):
23 self.client = Client()
24 self.nf_inst_id = "01"
25 NfInstModel.objects.all().delete()
26 self.test_data_single_vnf = {
28 "vnfInstanceName": "VNF1",
30 "instantiatedVnfInfo": {
33 "virtualStorageResourceInfo": [
37 "resourceId": "resource01",
38 "vimConnectionId": "vim01"
42 "extVirtualLinkInfo": [],
43 "vnfcResourceInfo": [],
44 "monitoringParameters": {},
46 "vnfVirtualLinkResourceInfo": [],
52 self.test_data_multi_vnf = [
55 "vnfInstanceName": "VNF1",
57 "instantiatedVnfInfo": {
60 "virtualStorageResourceInfo": [
64 "resourceId": "resource01",
65 "vimConnectionId": "vim01"
69 "extVirtualLinkInfo": [],
70 "vnfcResourceInfo": [],
71 "monitoringParameters": {},
73 "vnfVirtualLinkResourceInfo": [],
81 "vnfInstanceName": "VNF2",
83 "instantiatedVnfInfo": {
86 "virtualStorageResourceInfo": [
90 "resourceId": "resource02",
91 "vimConnectionId": "vim02"
95 "extVirtualLinkInfo": [],
96 "vnfcResourceInfo": [],
97 "monitoringParameters": {},
99 "vnfVirtualLinkResourceInfo": [],
110 def test_get_vnf(self):
112 NfInstModel(nfinstid=vnf_inst_id, nf_name='VNF1').save()
113 StorageInstModel(storageid='s02',
115 resouceid='resource01',
117 instid=vnf_inst_id).save()
118 response = self.client.get("/api/vnflcm/v1/vnf_instances/%s" % vnf_inst_id, format='json')
119 self.assertEqual(response.status_code, status.HTTP_200_OK)
120 self.assertEqual(self.test_data_single_vnf, response.data)
122 def test_get_vnfs(self):
123 for i in range(1, 3):
124 NfInstModel(nfinstid='%s' % i,
125 nf_name='VNF%s' % i).save()
126 StorageInstModel(storageid='s0%s' % i,
128 resouceid='resource0%s' % i,
130 instid='%s' % i).save()
131 response = self.client.get("/api/vnflcm/v1/vnf_instances", format='json')
132 self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
133 self.assertEqual(self.test_data_multi_vnf, response.data)