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": [
35 "virtualStorageInstanceId": "s02",
37 "resourceId": "resource01",
43 "vnfcResourceInfo": [],
44 "monitoringParameters": {},
47 "virtualLinkResourceInfo": [],
51 "onboardedVnfPkgInfoId": None
53 self.test_data_multi_vnf = [
56 "vnfInstanceName": "VNF1",
58 "instantiatedVnfInfo": {
61 "virtualStorageResourceInfo": [
63 "virtualStorageInstanceId": "s01",
65 "resourceId": "resource01",
71 "vnfcResourceInfo": [],
72 "monitoringParameters": {},
75 "virtualLinkResourceInfo": [],
79 "onboardedVnfPkgInfoId": None
83 "vnfInstanceName": "VNF2",
85 "instantiatedVnfInfo": {
88 "virtualStorageResourceInfo": [
90 "virtualStorageInstanceId": "s02",
92 "resourceId": "resource02",
98 "vnfcResourceInfo": [],
99 "monitoringParameters": {},
102 "virtualLinkResourceInfo": [],
106 "onboardedVnfPkgInfoId": None
113 def test_get_vnf(self):
115 NfInstModel(nfinstid=vnf_inst_id, nf_name='VNF1').save()
116 StorageInstModel(storageid='s02',
118 resouceid='resource01',
120 instid=vnf_inst_id).save()
121 response = self.client.get("/api/vnflcm/v1/vnf_instances/%s" % vnf_inst_id, format='json')
122 self.assertEqual(response.status_code, status.HTTP_200_OK)
123 self.assertEqual(self.test_data_single_vnf, response.data)
125 def test_get_vnfs(self):
126 for i in range(1, 3):
127 NfInstModel(nfinstid='%s' % i,
128 nf_name='VNF%s' % i).save()
129 StorageInstModel(storageid='s0%s' % i,
131 resouceid='resource0%s' % i,
133 instid='%s' % i).save()
134 response = self.client.get("/api/vnflcm/v1/vnf_instances", format='json')
135 self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
136 self.assertEqual(self.test_data_multi_vnf, response.data)