summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbiancunkang <bian.cunkang@zte.com.cn>2018-08-29 16:33:52 +0800
committerbiancunkang <bian.cunkang@zte.com.cn>2018-08-29 17:36:50 +0800
commita83474f2c8459cf07de512b3ca12b3e439a28d63 (patch)
treebd6083e33f4162753f04a53f99b47ede4ed3e2c1
parent98964bc2b0da28e15cbbed521f45c2166252e7fc (diff)
Deal with ns descriptor
Add prase nsd and the assosiated change in test Change-Id: Ic9a057427210b63fb246a2a3743ec4a633342d46 Issue-ID: VFC-1038 Signed-off-by: biancunkang <bian.cunkang@zte.com.cn>
-rw-r--r--catalog/packages/biz/ns_descriptor.py13
-rw-r--r--catalog/packages/tests/test_ns_descriptor.py227
-rw-r--r--catalog/packages/views/ns_descriptor_views.py8
3 files changed, 242 insertions, 6 deletions
diff --git a/catalog/packages/biz/ns_descriptor.py b/catalog/packages/biz/ns_descriptor.py
index 278c071b..fc771082 100644
--- a/catalog/packages/biz/ns_descriptor.py
+++ b/catalog/packages/biz/ns_descriptor.py
@@ -103,9 +103,10 @@ def upload(remote_file, nsd_info_id):
for chunk in remote_file.chunks(chunk_size=1024 * 8):
local_file.write(chunk)
logger.info('NSD(%s) content has been uploaded.' % nsd_info_id)
+ return local_file_name
-def process(nsd_info_id, local_file_name):
+def parse_nsd_and_save(nsd_info_id, local_file_name):
logger.info('Start to process NSD(%s)...' % nsd_info_id)
ns_pkgs = NSPackageModel.objects.filter(nsPackageId=nsd_info_id)
ns_pkgs.update(onboardingState='PROCESSING')
@@ -130,7 +131,10 @@ def process(nsd_info_id, local_file_name):
nsdDesginer=nsd["metadata"].get("vendor", "undefined"),
nsdDescription=nsd["metadata"].get("description", ""),
nsdVersion=nsd["metadata"].get("version", "undefined"),
- nsPackageUri=local_file_name, # TODO
+ onboardingState="ONBOARDED",
+ operationalState="ENABLED",
+ usageState="NOT_IN_USE",
+ nsPackageUri=local_file_name,
sdcCsarId=nsd_info_id,
localFilePath=local_file_name,
nsdModel=nsd_json
@@ -196,3 +200,8 @@ def fill_resp_data(ns_pkg):
data['userDefinedData'] = user_defined_data
return data
+
+
+def handle_upload_failed(nsd_info_id):
+ ns_pkg = NSPackageModel.objects.filter(nsPackageId=nsd_info_id)
+ ns_pkg.update(onboardingState="CREATED")
diff --git a/catalog/packages/tests/test_ns_descriptor.py b/catalog/packages/tests/test_ns_descriptor.py
index 02b91a72..83fbd9ba 100644
--- a/catalog/packages/tests/test_ns_descriptor.py
+++ b/catalog/packages/tests/test_ns_descriptor.py
@@ -15,12 +15,14 @@
import copy
import json
import os
+import mock
from django.test import TestCase
from rest_framework import status
from rest_framework.test import APIClient
-from catalog.pub.database.models import NSPackageModel
+from catalog.pub.database.models import NSPackageModel, VnfPackageModel
from catalog.pub.config.config import CATALOG_ROOT_PATH
+from catalog.pub.utils import toscaparser
class TestNsDescriptor(TestCase):
@@ -48,6 +50,218 @@ class TestNsDescriptor(TestCase):
'userDefinedData': self.user_defined_data,
'_links': None
}
+ self.nsd_data = {"vnffgs": [{"vnffg_id": "vnffg1",
+ "description": "",
+ "members": ["path1",
+ "path2"],
+ "properties": {"vendor": "zte",
+ "connection_point": ["m6000_data_in",
+ "m600_tunnel_cp",
+ "m6000_data_out"],
+ "version": "1.0",
+ "constituent_vnfs": ["VFW",
+ "VNAT"],
+ "number_of_endpoints": 3,
+ "dependent_virtual_link": ["sfc_data_network",
+ "ext_datanet_net",
+ "ext_mnet_net"]}}],
+ "inputs": {"sfc_data_network": {"type": "string",
+ "value": "sfc_data_network"},
+ "externalDataNetworkName": {"type": "string",
+ "value": "vlan_4004_tunnel_net"},
+ "externalManageNetworkName": {"type": "string",
+ "value": "vlan_4008_mng_net"},
+ "NatIpRange": {"type": "string",
+ "value": "192.167.0.10-192.168.0.20"},
+ "externalPluginManageNetworkName": {"type": "string",
+ "value": "vlan_4007_plugin_net"}},
+ "pnfs": [{"pnf_id": "m6000_s",
+ "cps": [],
+ "description": "",
+ "properties": {"vendor": "zte",
+ "request_reclassification": False,
+ "pnf_type": "m6000s",
+ "version": "1.0",
+ "management_address": "111111",
+ "id": "m6000_s",
+ "nsh_aware": False}}],
+ "fps": [{"properties": {"symmetric": False,
+ "policy": {"type": "ACL",
+ "criteria": {"dest_port_range": "1-100",
+ "ip_protocol": "tcp",
+ "source_ip_range": ["119.1.1.1-119.1.1.10"],
+ "dest_ip_range": [{"get_input": "NatIpRange"}],
+ "dscp": 0,
+ "source_port_range": "1-100"}}},
+ "forwarder_list": [{"capability": "",
+ "type": "cp",
+ "node_name": "m6000_data_out"},
+ {"capability": "",
+ "type": "cp",
+ "node_name": "m600_tunnel_cp"},
+ {"capability": "vnat_fw_inout",
+ "type": "vnf",
+ "node_name": "VNAT"}],
+ "description": "",
+ "fp_id": "path2"},
+ {"properties": {"symmetric": True,
+ "policy": {"type": "ACL",
+ "criteria": {"dest_port_range": "1-100",
+ "ip_protocol": "tcp",
+ "source_ip_range": ["1-100"],
+ "dest_ip_range": ["1-100"],
+ "dscp": 4,
+ "source_port_range": "1-100"}}},
+ "forwarder_list": [{"capability": "",
+ "type": "cp",
+ "node_name": "m6000_data_in"},
+ {"capability": "",
+ "type": "cp",
+ "node_name": "m600_tunnel_cp"},
+ {"capability": "vfw_fw_inout",
+ "type": "vnf",
+ "node_name": "VFW"},
+ {"capability": "vnat_fw_inout",
+ "type": "vnf",
+ "node_name": "VNAT"},
+ {"capability": "",
+ "type": "cp",
+ "node_name": "m600_tunnel_cp"},
+ {"capability": "",
+ "type": "cp",
+ "node_name": "m6000_data_out"}],
+ "description": "",
+ "fp_id": "path1"}],
+ "routers": [],
+ "vnfs": [{"vnf_id": "VFW",
+ "description": "",
+ "properties": {"plugin_info": "vbrasplugin_1.0",
+ "vendor": "zte",
+ "is_shared": False,
+ "adjust_vnf_capacity": True,
+ "name": "VFW",
+ "vnf_extend_type": "driver",
+ "csarVersion": "v1.0",
+ "csarType": "NFAR",
+ "csarProvider": "ZTE",
+ "version": "1.0",
+ "nsh_aware": True,
+ "cross_dc": False,
+ "vnf_type": "VFW",
+ "vmnumber_overquota_alarm": True,
+ "vnfd_version": "1.0.0",
+ "externalPluginManageNetworkName": "vlan_4007_plugin_net",
+ "id": "vcpe_vfw_zte_1_0",
+ "request_reclassification": False},
+ "dependencies": [{"key_name": "vfw_ctrl_by_manager_cp",
+ "vl_id": "ext_mnet_net"},
+ {"key_name": "vfw_data_cp",
+ "vl_id": "sfc_data_network"}],
+ "type": "tosca.nodes.nfv.ext.zte.VNF.VFW",
+ "networks": []}],
+ "ns_exposed": {"external_cps": [],
+ "forward_cps": []},
+ "policies": [{"file_url": "policies/abc.drl",
+ "name": "aaa"}],
+ "vls": [{"route_id": "",
+ "vl_id": "ext_mnet_net",
+ "route_external": False,
+ "description": "",
+ "properties": {"name": "vlan_4008_mng_net",
+ "mtu": 1500,
+ "location_info": {"tenant": "admin",
+ "vimid": 2,
+ "availability_zone": "nova"},
+ "ip_version": 4,
+ "dhcp_enabled": True,
+ "network_name": "vlan_4008_mng_net",
+ "network_type": "vlan"}},
+ {"route_id": "",
+ "vl_id": "ext_datanet_net",
+ "route_external": False,
+ "description": "",
+ "properties": {"name": "vlan_4004_tunnel_net",
+ "mtu": 1500,
+ "location_info": {"tenant": "admin",
+ "vimid": 2,
+ "availability_zone": "nova"},
+ "ip_version": 4,
+ "dhcp_enabled": True,
+ "network_name": "vlan_4004_tunnel_net",
+ "network_type": "vlan"}},
+ {"route_id": "",
+ "vl_id": "sfc_data_network",
+ "route_external": False,
+ "description": "",
+ "properties": {"name": "sfc_data_network",
+ "dhcp_enabled": True,
+ "is_predefined": False,
+ "location_info": {"tenant": "admin",
+ "vimid": 2,
+ "availability_zone": "nova"},
+ "ip_version": 4,
+ "mtu": 1500,
+ "network_name": "sfc_data_network",
+ "network_type": "vlan"}}],
+ "cps": [{"pnf_id": "m6000_s",
+ "vl_id": "path2",
+ "description": "",
+ "cp_id": "m6000_data_out",
+ "properties": {"direction": "bidirectional",
+ "vnic_type": "normal",
+ "bandwidth": 0,
+ "mac_address": "11-22-33-22-11-44",
+ "interface_name": "xgei-0/4/1/5",
+ "ip_address": "176.1.1.2",
+ "order": 0,
+ "sfc_encapsulation": "mac"}},
+ {"pnf_id": "m6000_s",
+ "vl_id": "ext_datanet_net",
+ "description": "",
+ "cp_id": "m600_tunnel_cp",
+ "properties": {"direction": "bidirectional",
+ "vnic_type": "normal",
+ "bandwidth": 0,
+ "mac_address": "00-11-00-22-33-00",
+ "interface_name": "gei-0/4/0/13",
+ "ip_address": "191.167.100.5",
+ "order": 0,
+ "sfc_encapsulation": "mac"}},
+ {"pnf_id": "m6000_s",
+ "vl_id": "path2",
+ "description": "",
+ "cp_id": "m6000_data_in",
+ "properties": {"direction": "bidirectional",
+ "vnic_type": "normal",
+ "bandwidth": 0,
+ "mac_address": "11-22-33-22-11-41",
+ "interface_name": "gei-0/4/0/7",
+ "ip_address": "1.1.1.1",
+ "order": 0,
+ "sfc_encapsulation": "mac",
+ "bond": "none"}},
+ {"pnf_id": "m6000_s",
+ "vl_id": "ext_mnet_net",
+ "description": "",
+ "cp_id": "m600_mnt_cp",
+ "properties": {"direction": "bidirectional",
+ "vnic_type": "normal",
+ "bandwidth": 0,
+ "mac_address": "00-11-00-22-33-11",
+ "interface_name": "gei-0/4/0/1",
+ "ip_address": "10.46.244.51",
+ "order": 0,
+ "sfc_encapsulation": "mac",
+ "bond": "none"}}],
+ "metadata": {"invariant_id": "vcpe_ns_sff_1",
+ "name": "VCPE_NS",
+ "csarVersion": "v1.0",
+ "csarType": "NSAR",
+ "csarProvider": "ZTE",
+ "version": 1,
+ "vendor": "ZTE",
+ "id": "VCPE_NS",
+ "description": "vcpe_ns"}}
def tearDown(self):
pass
@@ -124,8 +338,14 @@ class TestNsDescriptor(TestCase):
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
self.assertEqual(None, response.data)
- def test_nsd_content_upload_normal(self):
+ @mock.patch.object(toscaparser, 'parse_nsd')
+ def test_nsd_content_upload_normal(self, mock_parse_nsd):
user_defined_data_json = json.JSONEncoder().encode(self.user_defined_data)
+ mock_parse_nsd.return_value = json.JSONEncoder().encode(self.nsd_data)
+ VnfPackageModel(
+ vnfPackageId="111",
+ vnfdId="vcpe_vfw_zte_1_0"
+ ).save()
NSPackageModel(
nsPackageId='22',
operationalState='DISABLED',
@@ -144,6 +364,9 @@ class TestNsDescriptor(TestCase):
with open(os.path.join(CATALOG_ROOT_PATH, '22/nsd_content.txt')) as fp:
data = fp.read()
file_content = '%s%s' % (file_content, data)
+ ns_pkg = NSPackageModel.objects.filter(nsPackageId="22")
+ self.assertEqual("VCPE_NS", ns_pkg[0].nsdId)
+ self.assertEqual("ONBOARDED", ns_pkg[0].onboardingState)
self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT)
self.assertEqual(None, resp.data)
self.assertEqual(file_content, 'test')
diff --git a/catalog/packages/views/ns_descriptor_views.py b/catalog/packages/views/ns_descriptor_views.py
index 97765e64..a1df687c 100644
--- a/catalog/packages/views/ns_descriptor_views.py
+++ b/catalog/packages/views/ns_descriptor_views.py
@@ -16,7 +16,8 @@ import logging
import traceback
from django.http import StreamingHttpResponse
-from catalog.packages.biz.ns_descriptor import create, delete_single, download, query_multiple, query_single, upload
+from catalog.packages.biz.ns_descriptor import create, delete_single, download, query_multiple, query_single, upload, \
+ parse_nsd_and_save, handle_upload_failed
from catalog.packages.serializers.create_nsd_info_request import CreateNsdInfoRequestSerializer
from catalog.packages.serializers.nsd_info import NsdInfoSerializer
from catalog.packages.serializers.nsd_infos import NsdInfosSerializer
@@ -156,12 +157,15 @@ def nsd_content_ru(request, *args, **kwargs):
if request.method == 'PUT':
files = request.FILES.getlist('file')
try:
- upload(files[0], nsd_info_id)
+ local_file_name = upload(files[0], nsd_info_id)
+ parse_nsd_and_save(nsd_info_id, local_file_name)
return Response(data=None, status=status.HTTP_204_NO_CONTENT)
except CatalogException as e:
+ handle_upload_failed(nsd_info_id)
logger.error(e.message)
error_msg = {'error': 'Uploading NSD content failed.'}
except Exception as e:
+ handle_upload_failed(nsd_info_id)
logger.error(e.message)
logger.error(traceback.format_exc())
error_msg = {'error': 'Uploading NSD content failed.'}