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