1 # Copyright 2017 ZTE Corporation.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 from rest_framework.test import APIClient
19 from rest_framework import status
20 from lcm.pub.utils import restcall
22 inst_res_url = "/api/vnflcm/v1/resources/inst"
23 term_res_url = "/api/vnflcm/v1/resources/term"
27 "type": "tosca.nodes.nfv.Vdu.Compute",
28 "description": "vbng",
29 "vdu_id": "VDU_vbng_0",
32 "virtual_mem_size": "4096 MB",
33 "vdu_memory_requirements": {
34 "memoryPageSize": "2 MB",
35 "numberOfPages": "1024"
39 "num_virtual_cpu": "2",
40 "cpu_architecture": "generic"
43 "type_of_storage": "root",
44 "size_of_storage": "40 GB"
49 "artifact_name": "cirros.img",
50 "type": "tosca.artifacts.nfv.SwImage",
52 "operating_system": "unbant",
53 "sw_image": "/swimages/xenial-snat.qcow2",
57 "disk_format": "qcow2",
59 "container_format": "bare",
63 "file": "/swimages/xenial-snat.qcow2"
66 "image_file": "cirros.img",
68 "intel_local_storages_1"
79 "configurable_properties": {
81 "additional_vnfc_configurable_properties": {
88 "vimid": "f1e33529-4a88-4155-9d7a-893cf2c80527",
90 "availability_zone": "zone1",
93 "descrption": "the virtual machine of vNat",
102 "volume_storage_id": "volume_storage1",
107 "volume_name": "volumeStorage1",
108 "custom_volume_type": "type1",
110 "delete_on_termination_vm": True,
112 "vimid": "f1e33529-4a88-4155-9d7a-893cf2c80527",
114 "availability_zone": "zone1"
116 "is_predefined": False,
126 "local_storage_id": "omp_local_disk1",
140 "operating_system": "unbant",
141 "sw_image": "/swimages/xenial-snat.qcow2",
142 "name": "cirros.img",
145 "disk_format": "qcow2",
147 "container_format": "bare",
151 "image_file_id": "cirros.img"
157 "key_name": "sriov_plane",
158 "cp_id": "SRIOV_Port"
169 "connectivity_type": {
170 "layer_protocol": "ipv4"
173 "networkName": "vNat_big",
174 "networkType": "vlan",
175 "physicalNetwork": "physnet1",
176 "segmentationId": "30",
177 "vlanTransparent": False,
178 "cidr": "10.43.38.0/24",
179 "gatewayIp": "10.43.38.1",
180 "dhcpEnabled": False,
181 "startIp": "10.43.38.2",
182 "endIp": "10.43.38.254"
184 "is_predefined": False,
186 "netmask": "255.255.255.0",
191 "destination": "10.43.26.0/24",
192 "nexthop": "10.41.23.1"
196 "vimid": "f1e33529-4a88-4155-9d7a-893cf2c80527",
201 "route_id": "router01",
202 "route_external": False
209 "name": "vNat_big_subnet_port",
214 "fixed_ip_address": ["10.43.38.253"]
219 "vnic_type": "normal",
221 "virtual_network_interface_requirements": [
226 "support_mandatory": False,
228 "description": "sriov"
231 "layer_protocol": "ipv4",
232 "description": "sriov port"
237 "vdu_id": "VDU_vbng_0"
241 "vnfSoftwareVersion": "1.0.0",
242 "vnfmType": "gvnfmdriver",
243 "vnfProductName": "openNAT",
244 "localizationLanguage": "[english, chinese]",
245 "vnfProvider": "intel",
247 "defaultLocalizationLanguage": "english",
248 "csarVersion": "1.0.0",
249 "vnfdId": "openNAT-1.0",
250 "csarProvider": "intel",
251 "vnfProductInfoDescription": "openNAT",
253 "vnfdVersion": "1.0.0",
254 "vnfProductInfoName": "openNAT",
262 "volume": [{"is_predefined": NOT_PREDEFINED, "vim_id": "1", "tenant_id": "2", "res_id": "3"}],
263 "network": [{"is_predefined": NOT_PREDEFINED, "vim_id": "2", "tenant_id": "3", "res_id": "4"}],
264 "subnet": [{"is_predefined": NOT_PREDEFINED, "vim_id": "3", "tenant_id": "4", "res_id": "5"}],
265 "port": [{"is_predefined": NOT_PREDEFINED, "vim_id": "4", "tenant_id": "5", "res_id": "6"}],
266 "flavor": [{"is_predefined": NOT_PREDEFINED, "vim_id": "5", "tenant_id": "6", "res_id": "7"}],
267 "vm": [{"is_predefined": NOT_PREDEFINED, "vim_id": "6", "tenant_id": "7", "res_id": "8"}]
271 c0_data_get_tenant_id = {
280 c1_data_create_volume = {
281 "vimId": "f1e33529-4a88-4155-9d7a-893cf2c80527",
287 c1_data_get_volume = {
288 "vimId": "f1e33529-4a88-4155-9d7a-893cf2c80527",
289 "status": "AVAILABLE"
292 c2_data_create_network = {
293 "vimId": "f1e33529-4a88-4155-9d7a-893cf2c80527",
298 c3_data_create_subnet = {
299 "vimId": "f1e33529-4a88-4155-9d7a-893cf2c80527",
303 c4_data_create_port = {
304 "vimId": "f1e33529-4a88-4155-9d7a-893cf2c80527",
309 c5_data_get_flavor = [{
313 "flavor-id": "111111",
314 "hpa-capabilities": [
316 "hpa-capability-id": "1243",
317 "hpa-feature-attributes": [
319 "hpa-attribute-key": "memoryPageSize",
320 "hpa-attribute-value": {"value": 2, "unit": "MB"}
330 c6_data_list_image = {
333 "name": "cirros.img",
339 c6_data_create_vm = {
351 class SampleViewTest(unittest.TestCase):
353 self.client = APIClient()
358 def test_sample(self):
359 response = self.client.get("/samples/")
360 self.assertEqual(status.HTTP_200_OK, response.status_code, response.content)
361 resp_data = json.loads(response.content)
362 self.assertEqual({"status": "active"}, resp_data)
364 @mock.patch.object(restcall, 'call_req')
365 def test_inst_res(self, mock_call_req):
366 r0_data_get_tenant_id = [0, json.JSONEncoder().encode(c0_data_get_tenant_id), '200']
367 r1_data_create_volume = [0, json.JSONEncoder().encode(c1_data_create_volume), '200']
368 r1_data_get_volume = [0, json.JSONEncoder().encode(c1_data_get_volume), '200']
369 r2_data_create_network = [0, json.JSONEncoder().encode(c2_data_create_network), '200']
370 r3_data_create_subnet = [0, json.JSONEncoder().encode(c3_data_create_subnet), '200']
371 r4_data_create_port = [0, json.JSONEncoder().encode(c4_data_create_port), '200']
372 r5_data_get_flavor = [0, json.JSONEncoder().encode(c5_data_get_flavor), '200']
373 r6_data_list_image = [0, json.JSONEncoder().encode(c6_data_list_image), '200']
374 r6_data_create_vm = [0, json.JSONEncoder().encode(c6_data_create_vm), '200']
375 r6_data_get_vm = [0, json.JSONEncoder().encode(c6_data_get_vm), '200']
377 mock_call_req.side_effect = [r0_data_get_tenant_id,
378 r1_data_create_volume, r1_data_get_volume,
379 r2_data_create_network,
380 r3_data_create_subnet,
383 r6_data_list_image, r6_data_create_vm, r6_data_get_vm]
384 resp = self.client.post(inst_res_url, data=json.dumps(inst_res_data), content_type='application/json')
385 self.failUnlessEqual(status.HTTP_204_NO_CONTENT, resp.status_code)
387 @mock.patch.object(restcall, 'call_req')
388 def test_term_res(self, mock_call_req):
389 r0_data_delete = [0, json.JSONEncoder().encode({"vim_id": "123"}), '200']
390 mock_call_req.side_effect = [r0_data_delete,
397 resp = self.client.post(term_res_url, data=json.dumps(term_res_data), content_type='application/json')
398 self.failUnlessEqual(status.HTTP_204_NO_CONTENT, resp.status_code)