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.
16 from django.test import TestCase, Client
17 from rest_framework import status
19 from lcm.pub.database.models import NfInstModel, 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",
31 "instantiatedVnfInfo": {
34 "virtualStorageResourceInfo": [
36 "virtualStorageInstanceId": "s02",
38 "resourceId": "resource01",
44 "vnfcResourceInfo": [],
45 "monitoringParameters": {},
48 "virtualLinkResourceInfo": [],
52 "onboardedVnfPkgInfoId": None
54 self.test_data_multi_vnf = [
57 "vnfInstanceName": "VNF1",
59 "instantiatedVnfInfo": {
62 "virtualStorageResourceInfo": [
64 "virtualStorageInstanceId": "s01",
66 "resourceId": "resource01",
72 "vnfcResourceInfo": [],
73 "monitoringParameters": {},
76 "virtualLinkResourceInfo": [],
80 "onboardedVnfPkgInfoId": None
84 "vnfInstanceName": "VNF2",
86 "instantiatedVnfInfo": {
89 "virtualStorageResourceInfo": [
91 "virtualStorageInstanceId": "s02",
93 "resourceId": "resource02",
99 "vnfcResourceInfo": [],
100 "monitoringParameters": {},
103 "virtualLinkResourceInfo": [],
107 "onboardedVnfPkgInfoId": None
114 def test_get_vnf(self):
116 NfInstModel(nfinstid=vnf_inst_id, nf_name='VNF1').save()
117 StorageInstModel(storageid='s02', vimid='vim01', resouceid='resource01', insttype=1, 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, nf_name='VNF%s' % i).save()
125 StorageInstModel(storageid='s0%s' % i, vimid='vim0%s' % i, resouceid='resource0%s' % i,
126 insttype=1, instid='%s' % i).save()
127 response = self.client.get("/api/vnflcm/v1/vnf_instances", format='json')
128 self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
129 self.assertEqual(self.test_data_multi_vnf, response.data)