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.
14 from django.test import TestCase, Client
15 from rest_framework import status
17 from lcm.pub.database.models import NfInstModel, StorageInstModel
20 class ResourceTest(TestCase):
22 self.client = Client()
23 self.nf_inst_id = "01"
24 NfInstModel.objects.all().delete()
25 self.test_data_single_vnf = {
27 "vnfInstanceName": "VNF1",
29 "instantiatedVnfInfo": {
32 "virtualStorageResourceInfo": [
34 "virtualStorageInstanceId": "s02",
36 "resourceId": "resource01",
42 "vnfcResourceInfo": [],
43 "monitoringParameters": {},
46 "virtualLinkResourceInfo": [],
50 "onboardedVnfPkgInfoId": None
52 self.test_data_multi_vnf = [
55 "vnfInstanceName": "VNF1",
57 "instantiatedVnfInfo": {
60 "virtualStorageResourceInfo": [
62 "virtualStorageInstanceId": "s01",
64 "resourceId": "resource01",
70 "vnfcResourceInfo": [],
71 "monitoringParameters": {},
74 "virtualLinkResourceInfo": [],
78 "onboardedVnfPkgInfoId": None
82 "vnfInstanceName": "VNF2",
84 "instantiatedVnfInfo": {
87 "virtualStorageResourceInfo": [
89 "virtualStorageInstanceId": "s02",
91 "resourceId": "resource02",
97 "vnfcResourceInfo": [],
98 "monitoringParameters": {},
101 "virtualLinkResourceInfo": [],
105 "onboardedVnfPkgInfoId": None
112 def test_get_vnf(self):
114 NfInstModel(nfinstid=vnf_inst_id, nf_name='VNF1').save()
115 StorageInstModel(storageid='s02', vimid='vim01', resouceid='resource01', insttype=1, instid=vnf_inst_id).save()
116 response = self.client.get("/openoapi/vnflcm/v1/vnf_instances/%s" % vnf_inst_id, format='json')
117 self.assertEqual(response.status_code, status.HTTP_200_OK)
118 self.assertEqual(self.test_data_single_vnf, response.data)
120 def test_get_vnfs(self):
121 for i in range(1, 3):
122 NfInstModel(nfinstid='%s' % i, nf_name='VNF%s' % i).save()
123 StorageInstModel(storageid='s0%s' % i, vimid='vim0%s' % i, resouceid='resource0%s' % i,
124 insttype=1, instid='%s' % i).save()
125 response = self.client.get("/openoapi/vnflcm/v1/vnf_instances", format='json')
126 self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
127 self.assertEqual(self.test_data_multi_vnf, response.data)