Remove vfc-gvnfm-vnflcm openo labels
[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 from django.test import TestCase, Client
15 from rest_framework import status
16
17 from lcm.pub.database.models import NfInstModel, StorageInstModel
18
19
20 class ResourceTest(TestCase):
21     def setUp(self):
22         self.client = Client()
23         self.nf_inst_id = "01"
24         NfInstModel.objects.all().delete()
25         self.test_data_single_vnf = {
26             "vnfInstanceId": "1",
27             "vnfInstanceName": "VNF1",
28             "vnfProvider": None,
29             "instantiatedVnfInfo": {
30                 "vnfState": None,
31                 "extCpInfo": [],
32                 "virtualStorageResourceInfo": [
33                     {
34                         "virtualStorageInstanceId": "s02",
35                         "storageResource": {
36                             "resourceId": "resource01",
37                             "vimId": "vim01"
38                         }
39                     }
40                 ],
41                 "extVirtualLink": [],
42                 "vnfcResourceInfo": [],
43                 "monitoringParameters": {},
44                 "vimInfo": [],
45                 "flavourId": None,
46                 "virtualLinkResourceInfo": [],
47                 "scaleStatus": []
48             },
49             "vnfdVersion": None,
50             "onboardedVnfPkgInfoId": None
51         }
52         self.test_data_multi_vnf = [
53             {
54                 "vnfInstanceId": "1",
55                 "vnfInstanceName": "VNF1",
56                 "vnfProvider": None,
57                 "instantiatedVnfInfo": {
58                     "vnfState": None,
59                     "extCpInfo": [],
60                     "virtualStorageResourceInfo": [
61                         {
62                             "virtualStorageInstanceId": "s01",
63                             "storageResource": {
64                                 "resourceId": "resource01",
65                                 "vimId": "vim01"
66                             }
67                         }
68                     ],
69                     "extVirtualLink": [],
70                     "vnfcResourceInfo": [],
71                     "monitoringParameters": {},
72                     "vimInfo": [],
73                     "flavourId": None,
74                     "virtualLinkResourceInfo": [],
75                     "scaleStatus": []
76                 },
77                 "vnfdVersion": None,
78                 "onboardedVnfPkgInfoId": None
79             },
80             {
81                 "vnfInstanceId": "2",
82                 "vnfInstanceName": "VNF2",
83                 "vnfProvider": None,
84                 "instantiatedVnfInfo": {
85                     "vnfState": None,
86                     "extCpInfo": [],
87                     "virtualStorageResourceInfo": [
88                         {
89                             "virtualStorageInstanceId": "s02",
90                             "storageResource": {
91                                 "resourceId": "resource02",
92                                 "vimId": "vim02"
93                             }
94                         }
95                     ],
96                     "extVirtualLink": [],
97                     "vnfcResourceInfo": [],
98                     "monitoringParameters": {},
99                     "vimInfo": [],
100                     "flavourId": None,
101                     "virtualLinkResourceInfo": [],
102                     "scaleStatus": []
103                 },
104                 "vnfdVersion": None,
105                 "onboardedVnfPkgInfoId": None
106             }
107         ]
108
109     def tearDown(self):
110         pass
111
112     def test_get_vnf(self):
113         vnf_inst_id = "1"
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("/api/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)
119
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("/api/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)