Modify vnf query related stuffs in vnflcm.
[vfc/gvnfm/vnflcm.git] / lcm / lcm / nf / tests / test_query_vnf.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             "id": "1",
28             "vnfInstanceName": "VNF1",
29             "vnfProvider": None,
30             "instantiatedVnfInfo": {
31                 "vnfState": None,
32                 "extCpInfo": [],
33                 "virtualStorageResourceInfo": [
34                     {
35                         "id": "s02",
36                         "storageResource": {
37                             "resourceId": "resource01",
38                             "vimConnectionId": "vim01"
39                         }
40                     }
41                 ],
42                 "extVirtualLinkInfo": [],
43                 "vnfcResourceInfo": [],
44                 "monitoringParameters": {},
45                 "flavourId": None,
46                 "vnfVirtualLinkResourceInfo": [],
47                 "scaleStatus": []
48             },
49             "vnfdVersion": None,
50             "vnfPkgId": None
51         }
52         self.test_data_multi_vnf = [
53             {
54                 "id": "1",
55                 "vnfInstanceName": "VNF1",
56                 "vnfProvider": None,
57                 "instantiatedVnfInfo": {
58                     "vnfState": None,
59                     "extCpInfo": [],
60                     "virtualStorageResourceInfo": [
61                         {
62                             "id": "s01",
63                             "storageResource": {
64                                 "resourceId": "resource01",
65                                 "vimConnectionId": "vim01"
66                             }
67                         }
68                     ],
69                     "extVirtualLinkInfo": [],
70                     "vnfcResourceInfo": [],
71                     "monitoringParameters": {},
72                     "flavourId": None,
73                     "vnfVirtualLinkResourceInfo": [],
74                     "scaleStatus": []
75                 },
76                 "vnfdVersion": None,
77                 "vnfPkgId": None
78             },
79             {
80                 "id": "2",
81                 "vnfInstanceName": "VNF2",
82                 "vnfProvider": None,
83                 "instantiatedVnfInfo": {
84                     "vnfState": None,
85                     "extCpInfo": [],
86                     "virtualStorageResourceInfo": [
87                         {
88                             "id": "s02",
89                             "storageResource": {
90                                 "resourceId": "resource02",
91                                 "vimConnectionId": "vim02"
92                             }
93                         }
94                     ],
95                     "extVirtualLinkInfo": [],
96                     "vnfcResourceInfo": [],
97                     "monitoringParameters": {},
98                     "flavourId": None,
99                     "vnfVirtualLinkResourceInfo": [],
100                     "scaleStatus": []
101                 },
102                 "vnfdVersion": None,
103                 "vnfPkgId": None
104             }
105         ]
106
107     def tearDown(self):
108         pass
109
110     def test_get_vnf(self):
111         vnf_inst_id = "1"
112         NfInstModel(nfinstid=vnf_inst_id, nf_name='VNF1').save()
113         StorageInstModel(storageid='s02',
114                          vimid='vim01',
115                          resouceid='resource01',
116                          insttype=1,
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)
121
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,
127                              vimid='vim0%s' % i,
128                              resouceid='resource0%s' % i,
129                              insttype=1,
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)