diff options
-rw-r--r-- | catalog/packages/biz/common.py | 6 | ||||
-rw-r--r-- | catalog/packages/biz/pnf_descriptor.py | 12 | ||||
-rw-r--r-- | catalog/packages/tests/test_ns_descriptor.py | 2 | ||||
-rw-r--r-- | catalog/packages/tests/test_pnf_descriptor.py | 6 | ||||
-rw-r--r-- | catalog/packages/tests/test_vnf_package.py | 23 | ||||
-rw-r--r-- | catalog/packages/views/ns_descriptor_views.py | 2 | ||||
-rw-r--r-- | catalog/packages/views/pnf_descriptor_views.py | 6 | ||||
-rw-r--r-- | catalog/packages/views/vnf_package_views.py | 2 | ||||
-rw-r--r-- | catalog/pub/utils/toscaparser/testdata/vnf/vcpesriov/vgw.csar | bin | 15054 -> 24011 bytes | |||
-rw-r--r-- | catalog/pub/utils/toscaparser/tests.py | 33 | ||||
-rw-r--r-- | catalog/pub/utils/toscaparser/vnfdparser/vnfd_sol_251.py | 46 |
11 files changed, 96 insertions, 42 deletions
diff --git a/catalog/packages/biz/common.py b/catalog/packages/biz/common.py index c4205fb6..ce77a41e 100644 --- a/catalog/packages/biz/common.py +++ b/catalog/packages/biz/common.py @@ -45,7 +45,7 @@ def read(file_path, start, end): def parse_file_range(file_path, file_range): start, end = 0, os.path.getsize(file_path) if file_range: - [start, end] = file_range.split('-') - start, end = start.strip(), end.strip() - start, end = int(start), int(end) + [start, range_end] = file_range.split('-') + range_end = range_end.strip() if range_end.strip() else end + start, end = int(start.strip()), int(range_end) return start, end diff --git a/catalog/packages/biz/pnf_descriptor.py b/catalog/packages/biz/pnf_descriptor.py index ddadb4c5..e2a027b9 100644 --- a/catalog/packages/biz/pnf_descriptor.py +++ b/catalog/packages/biz/pnf_descriptor.py @@ -53,7 +53,8 @@ class PnfDescriptor(object): logger.info('A PNFD(%s) has been created.' % data['id']) return data - def query_multiple(self, pnfdId=None): + def query_multiple(self, request): + pnfdId = request.query_params.get('pnfdId') if pnfdId: pnf_pkgs = PnfPackageModel.objects.filter(pnfdId=pnfdId) else: @@ -140,10 +141,10 @@ class PnfDescriptor(object): pnfdName = "" if pnfd.get("pnf", "") != "": if pnfd["pnf"].get("properties", "") != "": - pnfd_id = pnfd["pnf"].get("properties", "").get("descriptor_id", "") - pnfdVersion = pnfd["pnf"].get("properties", "").get("version", "") - pnfdProvider = pnfd["pnf"].get("properties", "").get("provider", "") - pnfdName = pnfd["pnf"].get("properties", "").get("name", "") + pnfd_id = pnfd["pnf"].get("properties", {}).get("descriptor_id", "") + pnfdVersion = pnfd["pnf"].get("properties", {}).get("version", "") + pnfdProvider = pnfd["pnf"].get("properties", {}).get("provider", "") + pnfdName = pnfd["pnf"].get("properties", {}).get("name", "") if pnfd_id == "": pnfd_id = pnfd["metadata"].get("descriptor_id", "") if pnfd_id == "": @@ -212,7 +213,6 @@ class PnfDescriptor(object): pnf_pkg.update(onboardingState=PKG_STATUS.CREATED) def parse_pnfd(self, csar_id, inputs): - ret = None try: pnf_pkg = PnfPackageModel.objects.filter(pnfPackageId=csar_id) if not pnf_pkg: diff --git a/catalog/packages/tests/test_ns_descriptor.py b/catalog/packages/tests/test_ns_descriptor.py index f26ec394..d156843a 100644 --- a/catalog/packages/tests/test_ns_descriptor.py +++ b/catalog/packages/tests/test_ns_descriptor.py @@ -248,7 +248,7 @@ class TestNsDescriptor(TestCase): response = self.client.get( "/api/nsd/v1/ns_descriptors/23/nsd_content", - RANGE='5-10', + HTTP_RANGE='5-10', format='json' ) partial_file_content = '' diff --git a/catalog/packages/tests/test_pnf_descriptor.py b/catalog/packages/tests/test_pnf_descriptor.py index a722d805..97515187 100644 --- a/catalog/packages/tests/test_pnf_descriptor.py +++ b/catalog/packages/tests/test_pnf_descriptor.py @@ -17,6 +17,7 @@ import copy import json import mock import os +import shutil from django.test import TestCase @@ -25,6 +26,7 @@ from rest_framework.test import APIClient from catalog.packages.biz.pnf_descriptor import PnfDescriptor from catalog.packages.const import PKG_STATUS from catalog.packages.tests.const import pnfd_data +from catalog.pub.config.config import CATALOG_ROOT_PATH from catalog.pub.database.models import PnfPackageModel, NSPackageModel from catalog.pub.utils import toscaparser @@ -55,7 +57,9 @@ class TestPnfDescriptor(TestCase): } def tearDown(self): - pass + file_path = os.path.join(CATALOG_ROOT_PATH, "22") + if os.path.exists(file_path): + shutil.rmtree(file_path) def test_pnfd_create_normal(self): request_data = {'userDefinedData': self.user_defined_data} diff --git a/catalog/packages/tests/test_vnf_package.py b/catalog/packages/tests/test_vnf_package.py index e83aa7a3..8def3ba9 100644 --- a/catalog/packages/tests/test_vnf_package.py +++ b/catalog/packages/tests/test_vnf_package.py @@ -16,6 +16,7 @@ import json import os import urllib2 import mock +import shutil from django.test import TestCase from rest_framework import status @@ -42,7 +43,9 @@ class TestVnfPackage(TestCase): self.client = APIClient() def tearDown(self): - pass + file_path = os.path.join(CATALOG_ROOT_PATH, "222") + if os.path.exists(file_path): + shutil.rmtree(file_path) @mock.patch.object(toscaparser, 'parse_vnfd') def test_upload_vnf_pkg(self, mock_parse_vnfd): @@ -250,7 +253,7 @@ class TestVnfPackage(TestCase): onboardingState="ONBOARDED", localFilePath="vnfPackage.csar" ) - response = self.client.get("/api/vnfpkgm/v1/vnf_packages/222/package_content", RANGE="4-7") + response = self.client.get("/api/vnfpkgm/v1/vnf_packages/222/package_content", HTTP_RANGE="4-7") partial_file_content = '' for data in response.streaming_content: partial_file_content = partial_file_content + data @@ -258,6 +261,22 @@ class TestVnfPackage(TestCase): self.assertEqual('BBB', partial_file_content) os.remove("vnfPackage.csar") + def test_fetch_last_partical_vnf_pkg(self): + with open("vnfPackage.csar", "wb") as fp: + fp.writelines("AAAABBBBCCCCDDDD") + VnfPackageModel.objects.create( + vnfPackageId="222", + onboardingState="ONBOARDED", + localFilePath="vnfPackage.csar" + ) + response = self.client.get("/api/vnfpkgm/v1/vnf_packages/222/package_content", HTTP_RANGE=" 4-") + partial_file_content = '' + for data in response.streaming_content: + partial_file_content = partial_file_content + data + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual('BBBBCCCCDDDD', partial_file_content) + os.remove("vnfPackage.csar") + def test_fetch_vnf_pkg_when_pkg_not_exist(self): response = self.client.get("/api/vnfpkgm/v1/vnf_packages/222/package_content") self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) diff --git a/catalog/packages/views/ns_descriptor_views.py b/catalog/packages/views/ns_descriptor_views.py index 81836d35..73388ee4 100644 --- a/catalog/packages/views/ns_descriptor_views.py +++ b/catalog/packages/views/ns_descriptor_views.py @@ -134,6 +134,6 @@ def nsd_content_ru(request, **kwargs): raise e if request.method == 'GET': - file_range = request.META.get('RANGE') + file_range = request.META.get('HTTP_RANGE') file_iterator = NsDescriptor().download(nsd_info_id, file_range) return StreamingHttpResponse(file_iterator, status=status.HTTP_200_OK) diff --git a/catalog/packages/views/pnf_descriptor_views.py b/catalog/packages/views/pnf_descriptor_views.py index 2b99fd93..0545bfb1 100644 --- a/catalog/packages/views/pnf_descriptor_views.py +++ b/catalog/packages/views/pnf_descriptor_views.py @@ -99,11 +99,7 @@ def pnf_descriptors_rc(request): return Response(data=pnfd_info.data, status=status.HTTP_201_CREATED) if request.method == 'GET': - pnfdId = request.query_params.get('pnfdId', None) - if pnfdId: - data = PnfDescriptor().query_multiple(pnfdId) - else: - data = PnfDescriptor().query_multiple() + data = PnfDescriptor().query_multiple(request) pnfd_infos = validate_data(data, PnfdInfosSerializer) return Response(data=pnfd_infos.data, status=status.HTTP_200_OK) diff --git a/catalog/packages/views/vnf_package_views.py b/catalog/packages/views/vnf_package_views.py index 094b6f59..dcff9867 100644 --- a/catalog/packages/views/vnf_package_views.py +++ b/catalog/packages/views/vnf_package_views.py @@ -105,7 +105,7 @@ def package_content_ru(request, **kwargs): raise e if request.method == "GET": - file_range = request.META.get('RANGE') + file_range = request.META.get('HTTP_RANGE') file_iterator = VnfPackage().download(vnf_pkg_id, file_range) return StreamingHttpResponse(file_iterator, status=status.HTTP_200_OK) diff --git a/catalog/pub/utils/toscaparser/testdata/vnf/vcpesriov/vgw.csar b/catalog/pub/utils/toscaparser/testdata/vnf/vcpesriov/vgw.csar Binary files differindex 5e47b771..433e5724 100644 --- a/catalog/pub/utils/toscaparser/testdata/vnf/vcpesriov/vgw.csar +++ b/catalog/pub/utils/toscaparser/testdata/vnf/vcpesriov/vgw.csar diff --git a/catalog/pub/utils/toscaparser/tests.py b/catalog/pub/utils/toscaparser/tests.py index bd7fbc06..285d9706 100644 --- a/catalog/pub/utils/toscaparser/tests.py +++ b/catalog/pub/utils/toscaparser/tests.py @@ -35,26 +35,25 @@ class TestToscaparser(TestCase): def test_vnfd_parse(self): self.remove_temp_dir() input_parameters = [{"value": "222222", "key": "sdncontroller"}] - vcpe = ["vgw", "infra", "vbng", "vbrgemu", "vgmux"] + # vcpe = ["vgw", "infra", "vbng", "vbrgemu", "vgmux"] + vcpe_part = 'vgw' sriov_path = os.path.dirname(os.path.abspath(__file__)) + "/testdata/vnf/vcpesriov" - for vcpe_part in vcpe: - csar_file = ("%s/%s.csar" % (sriov_path, vcpe_part)) - logger.debug("csar_file:%s", csar_file) - vnfd_json = parse_vnfd(csar_file, input_parameters) - metadata = json.loads(vnfd_json).get("metadata") - logger.debug("sriov metadata:%s", metadata) - self.assertEqual(("vCPE_%s" % vcpe_part), metadata.get("template_name", "")) - if vcpe_part == "infra": - self.assertEqual("b1bb0ce7-1111-4fa7-95ed-4840d70a1177", json.loads(vnfd_json)["vnf"]["properties"]["descriptor_id"]) + csar_file = ("%s/%s.csar" % (sriov_path, vcpe_part)) + logger.debug("csar_file:%s", csar_file) + vnfd_json = parse_vnfd(csar_file, input_parameters) + metadata = json.loads(vnfd_json).get("metadata") + logger.debug("sriov metadata:%s", metadata) + self.assertEqual(("vCPE_%s" % vcpe_part), metadata.get("template_name", "")) + if vcpe_part == "infra": + self.assertEqual("b1bb0ce7-1111-4fa7-95ed-4840d70a1177", json.loads(vnfd_json)["vnf"]["properties"]["descriptor_id"]) dpdk_path = os.path.dirname(os.path.abspath(__file__)) + "/testdata/vnf/vcpedpdk" - for vcpe_part in vcpe: - csar_file = ("%s/%s.csar" % (dpdk_path, vcpe_part)) - logger.debug("csar_file:%s", csar_file) - vnfd_json = parse_vnfd(csar_file, input_parameters) - metadata = json.loads(vnfd_json).get("metadata") - logger.debug("dpdk metadata:%s", metadata) - self.assertEqual(("vCPE_%s" % vcpe_part), metadata.get("template_name", "")) + csar_file = ("%s/%s.csar" % (dpdk_path, vcpe_part)) + logger.debug("csar_file:%s", csar_file) + vnfd_json = parse_vnfd(csar_file, input_parameters) + metadata = json.loads(vnfd_json).get("metadata") + logger.debug("dpdk metadata:%s", metadata) + self.assertEqual(("vCPE_%s" % vcpe_part), metadata.get("template_name", "")) def test_pnfd_parse(self): self.remove_temp_dir() diff --git a/catalog/pub/utils/toscaparser/vnfdparser/vnfd_sol_251.py b/catalog/pub/utils/toscaparser/vnfdparser/vnfd_sol_251.py index d6c15de9..ed347aff 100644 --- a/catalog/pub/utils/toscaparser/vnfdparser/vnfd_sol_251.py +++ b/catalog/pub/utils/toscaparser/vnfdparser/vnfd_sol_251.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import functools import logging import os @@ -68,6 +67,23 @@ class VnfdSOL251(): vl['vl_id'] = node['name'] vl['description'] = node['description'] vl['properties'] = node['properties'] + vlp = vl['properties'] + nodep = node['properties'] + vlp['connectivity_type']['layer_protocol'] = nodep['connectivity_type']['layer_protocols'] + vlp['vl_profile']['max_bit_rate_requirements'] = nodep['vl_profile']['max_bitrate_requirements'] + vlp['vl_profile']['min_bit_rate_requirements'] = nodep['vl_profile']['min_bitrate_requirements'] + if 'virtual_link_protocol_data' in nodep['vl_profile']: + protocol_data = nodep['vl_profile']['virtual_link_protocol_data'][0] + vlp['vl_profile']['associated_layer_protocol'] = protocol_data['associated_layer_protocol'] + if 'l3_protocol_data' in protocol_data: + l3 = protocol_data['l3_protocol_data'] + vlp['vl_profile']['networkName'] = l3.get("name", "") + vlp['vl_profile']['cidr'] = l3.get("cidr", "") + vlp['vl_profile']['dhcpEnabled'] = l3.get("dhcp_enabled", "") + vlp['vl_profile']['ip_version'] = l3.get("ip_version", "") + if 'l2_protocol_data' in protocol_data: + l2 = protocol_data['l2_protocol_data'] + vlp['vl_profile']['physicalNetwork'] = l2.get("physical_network", "") vls.append(vl) return vls @@ -79,7 +95,22 @@ class VnfdSOL251(): cp['cp_id'] = node['name'] cp['cpd_id'] = node['name'] cp['description'] = node['description'] - cp['properties'] = node['properties'] + cp['properties'] = {} + nodep = node['properties'] + cp['properties']['trunk_mode'] = nodep.get("trunk_mode", "") + cp['properties']['layer_protocol'] = nodep.get("layer_protocols", "") + if 'vnic_type' in nodep: + cp['properties']['vnic_type'] = nodep.get("vnic_type", "normal") + if 'virtual_network_interface_requirements' in nodep: + cp['properties']['virtual_network_interface_requirements'] = nodep.get("virtual_network_interface_requirements", "") + if "protocol" in nodep: + node_protocol = nodep['protocol'][0] + cp['properties']['protocol_data'] = nodep['protocol'] + cp_protocol = cp['properties']['protocol_data'][0] + cp_protocol['asscociated_layer_protocol'] = node_protocol['associated_layer_protocol'] + if "address_data" in node_protocol: + cp_protocol['address_data'] = node_protocol['address_data'][0] + cp['vl_id'] = self._get_node_vl_id(node) cp['vdu_id'] = self._get_node_vdu_id(node) vls = self._buil_cp_vls(node) @@ -112,6 +143,9 @@ class VnfdSOL251(): if 'description' in node: ret['description'] = node['description'] ret['properties'] = node['properties'] + if 'boot_data' in node['properties']: + ret['properties']['user_data'] = node['properties']['boot_data'] + del ret['properties']['boot_data'] if 'inject_files' in node['properties']: inject_files = node['properties']['inject_files'] if inject_files is not None: @@ -128,12 +162,14 @@ class VnfdSOL251(): source_data = f.read() source_data_base64 = source_data.encode("base64") inject_files["source_data_base64"] = source_data_base64 - virtual_storages = self.model.getRequirementByName(node, 'virtual_storage') - ret['virtual_storages'] = map(functools.partial(self._trans_virtual_storage), virtual_storages) ret['dependencies'] = map(lambda x: self.model.get_requirement_node_name(x), self.model.getNodeDependencys(node)) virtual_compute = self.model.getCapabilityByName(node, 'virtual_compute') if virtual_compute is not None and 'properties' in virtual_compute: - ret['virtual_compute'] = virtual_compute['properties'] + vc = {} + vc['virtual_cpu'] = virtual_compute['properties']['virtual_cpu'] + vc['virtual_memory'] = virtual_compute['properties']['virtual_memory'] + vc['virtual_storages'] = virtual_compute['properties'].get("virtual_local_storage", {}) + ret['virtual_compute'] = vc ret['vls'] = self._get_linked_vl_ids(node, nodeTemplates) ret['cps'] = self._get_virtal_binding_cp_ids(node, nodeTemplates) ret['artifacts'] = self.model.build_artifacts(node) |