efb5b10815d528693de1195dc0f68b39f7c656c7
[vfc/gvnfm/vnflcm.git] / lcm / lcm / samples / tests.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 import unittest
16 import json
17 from django.test import Client
18 from rest_framework import status
19
20 inst_res_url = "/api/vnflcm/v1/resources/inst"
21 term_res_url = "/api/vnflcm/v1/resources/term"
22 inst_res_data = {
23     "vdus": [
24         {
25             "description": "",
26             "vdu_id": "vdu_vNat",
27             "artifacts": [
28                 {
29                     "artifact_name": "cirros.img",
30                     "type": "tosca.artifacts.nfv.SwImage",
31                     "properties": {
32                         "operating_system": "unbant",
33                         "sw_image": "/swimages/xenial-snat.qcow2",
34                         "name": "cirros.img",
35                         "checksum": "5000",
36                         "min_ram": "1 GB",
37                         "disk_format": "qcow2",
38                         "version": "1.0",
39                         "container_format": "bare",
40                         "min_disk": "10 GB",
41                         "size": "10 GB"
42                     },
43                     "file": "/swimages/xenial-snat.qcow2"
44                 }
45             ],
46             "nfv_compute": {
47                 "flavor_extra_specs": {
48                 },
49                 "mem_size": "2 GB",
50                 "num_cpus": 2
51             },
52             "image_file": "cirros.img",
53             "local_storages": [
54                 "intel_local_storages_1"
55             ],
56             "dependencies": [
57             ],
58             "vls": [
59                 "vl_vNat"
60             ],
61             "cps": [
62                 "cp_vNat"
63             ],
64             "properties": {
65                 "configurable_properties": {
66                     "test": {
67                         "additional_vnfc_configurable_properties": {
68                             "aaa": "1"
69                         }
70                     }
71                 },
72                 "name": "vNat",
73                 "location_info": {
74                     "vimid": "f1e33529-4a88-4155-9d7a-893cf2c80527",
75                     "tenant": "vnfm",
76                     "availability_zone": "zone1",
77                     "host": "host1"
78                 },
79                 "descrption": "the virtual machine of vNat",
80                 "boot_order": [
81                     "vNAT_Storage"
82                 ]
83             }
84         }
85     ],
86     "volume_storages": [
87         {
88             "volume_storage_id": "volume_storage1",
89             "description": "",
90             "properties": {
91                 "size": "100 GB",
92                 "volume_id": "",
93                 "volume_name": "volumeStorage1",
94                 "custom_volume_type": "type1",
95                 "disk_type": "data",
96                 "delete_on_termination_vm": True,
97                 "location_info": {
98                     "vimid": "f1e33529-4a88-4155-9d7a-893cf2c80527",
99                     "tenant": "vnfm",
100                     "availability_zone": "zone1"
101                 },
102                 "is_predefined": False,
103                 "is_shared": False,
104             },
105             "image_file": [
106                 "volume_image"
107             ]
108         }
109     ],
110     "local_storages": [
111         {
112             "local_storage_id": "omp_local_disk1",
113             "description": "",
114             "properties": {
115                 "size": "100 GB",
116                 "disk_type": "root",
117             },
118         }
119     ],
120     "routers": [
121     ],
122     "image_files": [
123         {
124             "description": "",
125             "properties": {
126                 "operating_system": "unbant",
127                 "sw_image": "/swimages/xenial-snat.qcow2",
128                 "name": "cirros.img",
129                 "checksum": "5000",
130                 "min_ram": "1 GB",
131                 "disk_format": "qcow2",
132                 "version": "1.0",
133                 "container_format": "bare",
134                 "min_disk": "10 GB",
135                 "size": "10 GB"
136             },
137             "image_file_id": "cirros.img"
138         }
139     ],
140     "vnf_exposed": {
141         "external_cps": [
142             {
143                 "key_name": "sriov_plane",
144                 "cp_id": "SRIOV_Port"
145             }
146         ],
147         "forward_cps": [
148         ]
149     },
150     'vls': [
151         {
152             "vl_id": "vl_vNat",
153             "description": "",
154             "properties": {
155                 "name": "vNat_big_subnet",
156                 "network_name": "vNat_big",
157                 "is_predefined": False,
158                 "vendor": "zte",
159                 "netmask": "255.255.255.0",
160                 "mtu": 1500,
161                 "network_type": "vlan",
162                 "physical_network": "physnet1",
163                 "segmentation_id": "30",
164                 "vlan_transparent": False,
165                 "vds_name": "vds1",
166                 "cidr": "10.43.38.0/24",
167                 "ip_version": 4,
168                 "gateway_ip": "10.43.38.1",
169                 "dhcp_enabled": False,
170                 "start_ip": "10.43.38.2",
171                 "end_ip": "10.43.38.254",
172                 "host_routes": [
173                     {
174                         "destination": "10.43.26.0/24",
175                         "nexthop": "10.41.23.1"
176                     }
177                 ],
178                 "location_info": {
179                     "vimid": "f1e33529-4a88-4155-9d7a-893cf2c80527",
180                     "tenant": "vnfm"
181                 },
182                 "cloud_type": "IaaS"
183             },
184             "route_id": "router01",
185             "route_external": False
186         }
187     ],
188     "cps": [
189         {
190             "properties": {
191                 "name": "vNat_big_subnet_port",
192                 "ip_address": "10.43.38.253",
193                 "vnic_type": "normal",
194                 "role": "root",
195                 "virtual_network_interface_requirements": [
196                     {
197                         "requirement": {
198                             "SRIOV": "true"
199                         },
200                         "support_mandatory": False,
201                         "name": "sriov",
202                         "description": "sriov"
203                     }
204                 ],
205                 "layer_protocol": "ipv4",
206                 "description": "sriov port"
207             },
208             "vl_id": "vl_vNat",
209             "description": "",
210             "cp_id": "cp_vNat",
211             "vdu_id": "vdu_vNat"
212         }
213     ],
214     "metadata": {
215         "vnfSoftwareVersion": "1.0.0",
216         "vnfmType": "gvnfmdriver",
217         "vnfProductName": "openNAT",
218         "localizationLanguage": "[english, chinese]",
219         "vnfProvider": "intel",
220         "vnfmInfo": "GVNFM",
221         "defaultLocalizationLanguage": "english",
222         "csarVersion": "1.0.0",
223         "vnfdId": "openNAT-1.0",
224         "csarProvider": "intel",
225         "vnfProductInfoDescription": "openNAT",
226         "version": "1.0.0",
227         "vnfdVersion": "1.0.0",
228         "vnfProductInfoName": "openNAT",
229         "vendor": "intel",
230         "csarType": "NFAR",
231         "id": "openNAT-1.0"
232     }
233 }
234 term_res_data = {
235     "volume": [{"vim_id": "1", "tenant_id": "2", "res_id": "3"}],
236     "network": [{"vim_id": "2", "tenant_id": "3", "res_id": "4"}],
237     "subnet": [{"vim_id": "3", "tenant_id": "4", "res_id": "5"}],
238     "port": [{"vim_id": "4", "tenant_id": "5", "res_id": "6"}],
239     "flavor": [{"vim_id": "5", "tenant_id": "6", "res_id": "7"}],
240     "vm": [{"vim_id": "6", "tenant_id": "7", "res_id": "8"}]
241 }
242
243
244 class SampleViewTest(unittest.TestCase):
245     def setUp(self):
246         self.client = Client()
247
248     def tearDown(self):
249         pass
250
251     def test_sample(self):
252         response = self.client.get("/samples/")
253         self.assertEqual(status.HTTP_200_OK, response.status_code, response.content)
254         resp_data = json.loads(response.content)
255         self.assertEqual({"status": "active"}, resp_data)
256
257     def test_inst_res(self):
258         resp = self.client.post(inst_res_url, data=json.dumps(inst_res_data), content_type='application/json')
259         self.failUnlessEqual(status.HTTP_204_NO_CONTENT, resp.status_code)
260
261     def test_term_res(self):
262         resp = self.client.post(term_res_url, data=json.dumps(term_res_data), content_type='application/json')
263         self.failUnlessEqual(status.HTTP_204_NO_CONTENT, resp.status_code)