7f21d47b89088b26623408960229353308e4d481
[vfc/gvnfm/vnflcm.git] / lcm / lcm / nf / vnfs / tests / test_vnf_query.py
1 # Copyright 2017 ZTE Corporation.
2 #
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
6 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
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
15 from django.test import TestCase, Client
16 from rest_framework import status
17
18 from lcm.pub.database.models import NfInstModel, StorageInstModel
19
20
21 class ResourceTest(TestCase):
22     def setUp(self):
23         self.client = Client()
24         self.nf_inst_id = "01"
25         NfInstModel.objects.all().delete()
26         self.test_data_single_vnf = {
27             "vnfInstanceId": "1",
28             "vnfInstanceName": "VNF1",
29             "vnfProvider": None,
30             "instantiatedVnfInfo": {
31                 "vnfState": None,
32                 "extCpInfo": [],
33                 "virtualStorageResourceInfo": [
34                     {
35                         "virtualStorageInstanceId": "s02",
36                         "storageResource": {
37                             "resourceId": "resource01",
38                             "vimId": "vim01"
39                         }
40                     }
41                 ],
42                 "extVirtualLink": [],
43                 "vnfcResourceInfo": [],
44                 "monitoringParameters": {},
45                 "vimInfo": [],
46                 "flavourId": None,
47                 "virtualLinkResourceInfo": [],
48                 "scaleStatus": []
49             },
50             "vnfdVersion": None,
51             "onboardedVnfPkgInfoId": None
52         }
53         self.test_data_multi_vnf = [
54             {
55                 "vnfInstanceId": "1",
56                 "vnfInstanceName": "VNF1",
57                 "vnfProvider": None,
58                 "instantiatedVnfInfo": {
59                     "vnfState": None,
60                     "extCpInfo": [],
61                     "virtualStorageResourceInfo": [
62                         {
63                             "virtualStorageInstanceId": "s01",
64                             "storageResource": {
65                                 "resourceId": "resource01",
66                                 "vimId": "vim01"
67                             }
68                         }
69                     ],
70                     "extVirtualLink": [],
71                     "vnfcResourceInfo": [],
72                     "monitoringParameters": {},
73                     "vimInfo": [],
74                     "flavourId": None,
75                     "virtualLinkResourceInfo": [],
76                     "scaleStatus": []
77                 },
78                 "vnfdVersion": None,
79                 "onboardedVnfPkgInfoId": None
80             },
81             {
82                 "vnfInstanceId": "2",
83                 "vnfInstanceName": "VNF2",
84                 "vnfProvider": None,
85                 "instantiatedVnfInfo": {
86                     "vnfState": None,
87                     "extCpInfo": [],
88                     "virtualStorageResourceInfo": [
89                         {
90                             "virtualStorageInstanceId": "s02",
91                             "storageResource": {
92                                 "resourceId": "resource02",
93                                 "vimId": "vim02"
94                             }
95                         }
96                     ],
97                     "extVirtualLink": [],
98                     "vnfcResourceInfo": [],
99                     "monitoringParameters": {},
100                     "vimInfo": [],
101                     "flavourId": None,
102                     "virtualLinkResourceInfo": [],
103                     "scaleStatus": []
104                 },
105                 "vnfdVersion": None,
106                 "onboardedVnfPkgInfoId": None
107             }
108         ]
109
110     def tearDown(self):
111         pass
112
113     def test_get_vnf(self):
114         vnf_inst_id = "1"
115         NfInstModel(nfinstid=vnf_inst_id, nf_name='VNF1').save()
116         StorageInstModel(storageid='s02', vimid='vim01', resouceid='resource01', insttype=1, instid=vnf_inst_id).save()
117         response = self.client.get("/api/vnflcm/v1/vnf_instances/%s" % vnf_inst_id, format='json')
118         self.assertEqual(response.status_code, status.HTTP_200_OK)
119         self.assertEqual(self.test_data_single_vnf, response.data)
120
121     def test_get_vnfs(self):
122         for i in range(1, 3):
123             NfInstModel(nfinstid='%s' % i, nf_name='VNF%s' % i).save()
124             StorageInstModel(storageid='s0%s' % i, vimid='vim0%s' % i, resouceid='resource0%s' % i,
125                              insttype=1, instid='%s' % i).save()
126         response = self.client.get("/api/vnflcm/v1/vnf_instances", format='json')
127         self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
128         self.assertEqual(self.test_data_multi_vnf, response.data)