diff options
Diffstat (limited to 'lcm')
-rw-r--r-- | lcm/lcm/samples/resources.py | 2 | ||||
-rw-r--r-- | lcm/lcm/samples/tests.py | 235 | ||||
-rw-r--r-- | lcm/lcm/samples/urls.py | 2 | ||||
-rw-r--r-- | lcm/lcm/samples/views.py | 20 |
4 files changed, 242 insertions, 17 deletions
diff --git a/lcm/lcm/samples/resources.py b/lcm/lcm/samples/resources.py index 5b8bfad9..c873b117 100644 --- a/lcm/lcm/samples/resources.py +++ b/lcm/lcm/samples/resources.py @@ -37,7 +37,7 @@ class ResCreateThread(threading.Thread): logger.error(str(sys.exc_info())) def do_notify(self, res_type, ret): - logger.debug('ret of [%s] is %s', res_type, str(ret)) + logger.debug('ret of [%s] is %s', res_type, ret) class ResDeleteThread(threading.Thread): """ diff --git a/lcm/lcm/samples/tests.py b/lcm/lcm/samples/tests.py index 8f1c326f..d85e2d30 100644 --- a/lcm/lcm/samples/tests.py +++ b/lcm/lcm/samples/tests.py @@ -14,9 +14,234 @@ import unittest import json +import mock from django.test import Client from rest_framework import status +from lcm.pub.vimapi import api + +inst_res_url = "/openoapi/vnflcm/v1/resources/inst" +term_res_url = "/openoapi/vnflcm/v1/resources/term" +inst_res_data = { + "vdus": [ + { + "description": "", + "vdu_id": "vdu_vNat", + "artifacts": [ + { + "artifact_name": "cirros.img", + "type": "tosca.artifacts.nfv.SwImage", + "properties": { + "operating_system": "unbant", + "sw_image": "/swimages/xenial-snat.qcow2", + "name": "cirros.img", + "checksum": "5000", + "min_ram": "1 GB", + "disk_format": "qcow2", + "version": "1.0", + "container_format": "bare", + "min_disk": "10 GB", + "size": "10 GB" + }, + "file": "/swimages/xenial-snat.qcow2" + } + ], + "nfv_compute": { + "flavor_extra_specs": { + }, + "mem_size": "2 GB", + "num_cpus": 2 + }, + "image_file": "cirros.img", + "local_storages": [ + "intel_local_storages_1" + ], + "dependencies": [ + ], + "vls": [ + "vl_vNat" + ], + "cps": [ + "cp_vNat" + ], + "properties": { + "configurable_properties": { + "test": { + "additional_vnfc_configurable_properties": { + "aaa": "1" + } + } + }, + "name": "vNat", + "location_info": { + "vimid": "f1e33529-4a88-4155-9d7a-893cf2c80527", + "tenant": "vnfm", + "availability_zone": "zone1", + "host": "host1" + }, + "descrption": "the virtual machine of vNat", + "boot_order": [ + "vNAT_Storage" + ] + } + } + ], + "volume_storages": [ + { + "volume_storage_id": "volume_storage1", + "description": "", + "properties": { + "size": "100 GB", + "volume_id": "", + "volume_name": "volumeStorage1", + "custom_volume_type": "type1", + "disk_type": "data", + "delete_on_termination_vm": True, + "location_info": { + "vimid": "f1e33529-4a88-4155-9d7a-893cf2c80527", + "tenant": "vnfm", + "availability_zone": "zone1" + }, + "is_predefined": False, + "is_shared": False, + }, + "image_file": [ + "volume_image" + ] + } + ], + "local_storages": [ + { + "local_storage_id": "omp_local_disk1", + "description": "", + "properties": { + "size": "100 GB", + "disk_type": "root", + }, + } + ], + "routers": [ + ], + "image_files": [ + { + "description": "", + "properties": { + "operating_system": "unbant", + "sw_image": "/swimages/xenial-snat.qcow2", + "name": "cirros.img", + "checksum": "5000", + "min_ram": "1 GB", + "disk_format": "qcow2", + "version": "1.0", + "container_format": "bare", + "min_disk": "10 GB", + "size": "10 GB" + }, + "image_file_id": "cirros.img" + } + ], + "vnf_exposed": { + "external_cps": [ + { + "key_name": "sriov_plane", + "cp_id": "SRIOV_Port" + } + ], + "forward_cps": [ + ] + }, + 'vls': [ + { + "vl_id": "vl_vNat", + "description": "", + "properties": { + "name": "vNat_big_subnet", + "network_name": "vNat_big", + "is_predefined": False, + "vendor": "zte", + "netmask": "255.255.255.0", + "mtu": 1500, + "network_type": "vlan", + "physical_network": "physnet1", + "segmentation_id": "30", + "vlan_transparent": False, + "vds_name": "vds1", + "cidr": "10.43.38.0/24", + "ip_version": 4, + "gateway_ip": "10.43.38.1", + "dhcp_enabled": False, + "start_ip": "10.43.38.2", + "end_ip": "10.43.38.254", + "host_routes": [ + { + "destination": "10.43.26.0/24", + "nexthop": "10.41.23.1" + } + ], + "location_info": { + "vimid": "f1e33529-4a88-4155-9d7a-893cf2c80527", + "tenant": "vnfm" + }, + "cloud_type": "IaaS" + }, + "route_id": "router01", + "route_external": False + } + ], + "cps": [ + { + "properties": { + "name": "vNat_big_subnet_port", + "ip_address": "10.43.38.253", + "vnic_type": "normal", + "role": "root", + "virtual_network_interface_requirements": [ + { + "requirement": { + "SRIOV": "true" + }, + "support_mandatory": False, + "name": "sriov", + "description": "sriov" + } + ], + "layer_protocol": "ipv4", + "description": "sriov port" + }, + "vl_id": "vl_vNat", + "description": "", + "cp_id": "cp_vNat", + "vdu_id": "vdu_vNat" + } + ], + "metadata": { + "vnfSoftwareVersion": "1.0.0", + "vnfmType": "gvnfmdriver", + "vnfProductName": "openNAT", + "localizationLanguage": "[english, chinese]", + "vnfProvider": "intel", + "vnfmInfo": "GVNFM", + "defaultLocalizationLanguage": "english", + "csarVersion": "1.0.0", + "vnfdId": "openNAT-1.0", + "csarProvider": "intel", + "vnfProductInfoDescription": "openNAT", + "version": "1.0.0", + "vnfdVersion": "1.0.0", + "vnfProductInfoName": "openNAT", + "vendor": "intel", + "csarType": "NFAR", + "id": "openNAT-1.0" + } +} +term_res_data = { + "volume": [{"vim_id": "1", "tenant_id": "2", "res_id": "3"}], + "network": [{"vim_id": "2", "tenant_id": "3", "res_id": "4"}], + "subnet": [{"vim_id": "3", "tenant_id": "4", "res_id": "5"}], + "port": [{"vim_id": "4", "tenant_id": "5", "res_id": "6"}], + "flavor": [{"vim_id": "5", "tenant_id": "6", "res_id": "7"}], + "vm": [{"vim_id": "6", "tenant_id": "7", "res_id": "8"}] +} class SampleViewTest(unittest.TestCase): def setUp(self): @@ -31,5 +256,11 @@ class SampleViewTest(unittest.TestCase): resp_data = json.loads(response.content) self.assertEqual({"status": "active"}, resp_data) - def test_url(self): - pass + def test_inst_res(self): + resp = self.client.post(inst_res_url, data=json.dumps(inst_res_data), content_type='application/json') + self.failUnlessEqual(status.HTTP_204_NO_CONTENT, resp.status_code) + + def test_term_res(self): + resp = self.client.post(term_res_url, data=json.dumps(term_res_data), content_type='application/json') + self.failUnlessEqual(status.HTTP_204_NO_CONTENT, resp.status_code) +
\ No newline at end of file diff --git a/lcm/lcm/samples/urls.py b/lcm/lcm/samples/urls.py index 636588c4..260c2436 100644 --- a/lcm/lcm/samples/urls.py +++ b/lcm/lcm/samples/urls.py @@ -16,5 +16,5 @@ from django.conf.urls import url from lcm.samples import views urlpatterns = [ - url(r'^openoapi/vnflcm/v1/resources$', views.ResourceList.as_view()), + url(r'^openoapi/vnflcm/v1/resources/(?P<action_type>[inst|term]+)$', views.ResourceList.as_view()), url(r'^samples/$', views.SampleList.as_view()), ] diff --git a/lcm/lcm/samples/views.py b/lcm/lcm/samples/views.py index b20901e1..41c8714c 100644 --- a/lcm/lcm/samples/views.py +++ b/lcm/lcm/samples/views.py @@ -32,18 +32,12 @@ class SampleList(APIView): class ResourceList(APIView): """ - Add resource. + Instantiate/Terminate resource. """ - def post(self, request): - logger.debug("ResourceList post: %s" % request.data) - ResCreateThread(request.data).start() + def post(self, request, action_type): + logger.debug("ResourceList post(%s): %s", action_type, request.data) + if action_type == "inst": + ResCreateThread(request.data).start() + else: + ResDeleteThread(request.data).start() return Response(data=None, status=status.HTTP_204_NO_CONTENT) - - """ - Delete resource. - """ - def delete(self, request): - logger.debug("ResourceList delete: %s" % request.data) - ResDeleteThread(request.data).start() - return Response(data=None, status=status.HTTP_204_NO_CONTENT) -
\ No newline at end of file |