summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog/packages/biz/vnf_package.py45
-rw-r--r--catalog/packages/tests/const.py10
-rw-r--r--catalog/pub/utils/toscaparser/testdata/vnf/vcpesriov/infra.csarbin15718 -> 15432 bytes
-rw-r--r--catalog/pub/utils/toscaparser/tests.py2
-rw-r--r--catalog/pub/utils/toscaparser/vnfdmodel.py72
5 files changed, 93 insertions, 36 deletions
diff --git a/catalog/packages/biz/vnf_package.py b/catalog/packages/biz/vnf_package.py
index 53f7fc0a..1d014bc3 100644
--- a/catalog/packages/biz/vnf_package.py
+++ b/catalog/packages/biz/vnf_package.py
@@ -194,29 +194,28 @@ def parse_vnfd_and_save(vnf_pkg_id, vnf_pkg_path):
vnfd_json = toscaparser.parse_vnfd(vnf_pkg_path)
vnfd = json.JSONDecoder().decode(vnfd_json)
- vnfd_id = vnfd["metadata"].get("id", '')
- if not vnfd_id:
- raise CatalogException("VNFDID(metadata.id) of VNF(%s) does not exist." % vnf_pkg_id)
- if VnfPackageModel.objects.filter(vnfdId=vnfd_id):
- logger.error("VNF package(%s) already exists." % vnfd_id)
- raise CatalogException("VNF package(%s) already exists." % vnfd_id)
-
- vnfd_ver = vnfd["metadata"].get("vnfd_version")
- if not vnfd_ver:
- vnfd_ver = vnfd["metadata"].get("vnfdVersion", "undefined")
-
- vnf_pkg.update(
- vnfPackageId=vnf_pkg_id,
- vnfdId=vnfd_id,
- vnfVendor=vnfd["metadata"].get("vendor", "undefined"),
- vnfdVersion=vnfd_ver,
- vnfSoftwareVersion=vnfd["metadata"].get("version", "undefined"),
- vnfdModel=vnfd_json,
- onboardingState=PKG_STATUS.ONBOARDED,
- operationalState=PKG_STATUS.ENABLED,
- usageState=PKG_STATUS.NOT_IN_USE,
- localFilePath=vnf_pkg_path
- )
+ if vnfd.get("vnf", "") != "":
+ vnfd_id = vnfd["vnf"]["properties"].get("descriptor_id", "")
+ if VnfPackageModel.objects.filter(vnfdId=vnfd_id):
+ logger.error("VNF package(%s) already exists." % vnfd_id)
+ raise CatalogException("VNF package(%s) already exists." % vnfd_id)
+ vnf_provider = vnfd["vnf"].get("provider", "")
+ vnfd_ver = vnfd["vnf"]["properties"].get("descriptor_verison", "")
+ vnf_software_version = vnfd["vnf"]["properties"].get("software_version", "")
+ vnf_pkg.update(
+ vnfPackageId=vnf_pkg_id,
+ vnfdId=vnfd_id,
+ vnfVendor=vnf_provider,
+ vnfdVersion=vnfd_ver,
+ vnfSoftwareVersion=vnf_software_version,
+ vnfdModel=vnfd_json,
+ onboardingState=PKG_STATUS.ONBOARDED,
+ operationalState=PKG_STATUS.ENABLED,
+ usageState=PKG_STATUS.NOT_IN_USE,
+ localFilePath=vnf_pkg_path
+ )
+ else:
+ raise CatalogException("VNF propeties and metadata in VNF Package(id=%s) are empty." % vnf_pkg_id)
logger.info('VNF package(%s) has been processed.' % vnf_pkg_id)
diff --git a/catalog/packages/tests/const.py b/catalog/packages/tests/const.py
index 97856f38..78f61b77 100644
--- a/catalog/packages/tests/const.py
+++ b/catalog/packages/tests/const.py
@@ -214,6 +214,16 @@ vnfd_data = {
"vnfProductInfoDescription": "hss",
"vnfdVersion": "1.0.0",
"vnfProductInfoName": "hss"
+ },
+ "vnf": {
+ "properties": {
+ "descriptor_id": "zte-hss-1.0",
+ "descriptor_verison": "1.0.0",
+ "software_version": "1.0.0",
+ "provider": "zte"
+ },
+ "metadata": {
+ }
}
}
diff --git a/catalog/pub/utils/toscaparser/testdata/vnf/vcpesriov/infra.csar b/catalog/pub/utils/toscaparser/testdata/vnf/vcpesriov/infra.csar
index 4547db46..c91c034e 100644
--- a/catalog/pub/utils/toscaparser/testdata/vnf/vcpesriov/infra.csar
+++ b/catalog/pub/utils/toscaparser/testdata/vnf/vcpesriov/infra.csar
Binary files differ
diff --git a/catalog/pub/utils/toscaparser/tests.py b/catalog/pub/utils/toscaparser/tests.py
index 8c6f57e9..86085e32 100644
--- a/catalog/pub/utils/toscaparser/tests.py
+++ b/catalog/pub/utils/toscaparser/tests.py
@@ -44,6 +44,8 @@ class TestToscaparser(TestCase):
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:
diff --git a/catalog/pub/utils/toscaparser/vnfdmodel.py b/catalog/pub/utils/toscaparser/vnfdmodel.py
index 74b28f54..0494bd63 100644
--- a/catalog/pub/utils/toscaparser/vnfdmodel.py
+++ b/catalog/pub/utils/toscaparser/vnfdmodel.py
@@ -16,6 +16,8 @@ import functools
import logging
import os
from catalog.pub.utils.toscaparser.basemodel import BaseInfoModel
+# from catalog.pub.exceptions import CatalogException
+
logger = logging.getLogger(__name__)
SECTIONS = (VDU_COMPUTE_TYPE, VNF_VL_TYPE, VDU_CP_TYPE, VDU_STORAGE_TYPE) = \
@@ -31,6 +33,8 @@ class EtsiVnfdInfoModel(BaseInfoModel):
super(EtsiVnfdInfoModel, self).__init__(path, params)
def parseModel(self, tosca):
+ self.vnf = {}
+ self.vnf = self.build_vnf(tosca)
self.metadata = self.buildMetadata(tosca)
self.inputs = self.buildInputs(tosca)
nodeTemplates = map(functools.partial(self.buildNode, tosca=tosca),
@@ -72,22 +76,20 @@ class EtsiVnfdInfoModel(BaseInfoModel):
ret['properties'] = node['properties']
if 'inject_files' in node['properties']:
inject_files = node['properties']['inject_files']
- if isinstance(inject_files, list):
- for inject_file in inject_files:
- source_path = os.path.join(self.basepath, inject_file['source_path'])
+ if inject_files is not None:
+ if isinstance(inject_files, list):
+ for inject_file in inject_files:
+ source_path = os.path.join(self.basepath, inject_file['source_path'])
+ with open(source_path, "rb") as f:
+ source_data = f.read()
+ source_data_base64 = source_data.encode("base64")
+ inject_file["source_data_base64"] = source_data_base64
+ if isinstance(inject_files, dict):
+ source_path = os.path.join(self.basepath, inject_files['source_path'])
with open(source_path, "rb") as f:
source_data = f.read()
source_data_base64 = source_data.encode("base64")
- inject_file["source_data_base64"] = source_data_base64
- elif isinstance(inject_files, dict):
- source_path = os.path.join(self.basepath, inject_files['source_path'])
- with open(source_path, "rb") as f:
- source_data = f.read()
- source_data_base64 = source_data.encode("base64")
- inject_files["source_data_base64"] = source_data_base64
- else:
- logger.warn("inject_files %s format is not right.", inject_files)
-
+ inject_files["source_data_base64"] = source_data_base64
virtual_storages = self.getRequirementByName(node, 'virtual_storage')
ret['virtual_storages'] = map(functools.partial(self._trans_virtual_storage), virtual_storages)
ret['dependencies'] = map(lambda x: self.get_requirement_node_name(x), self.getNodeDependencys(node))
@@ -213,3 +215,47 @@ class EtsiVnfdInfoModel(BaseInfoModel):
else:
forward_cps.append({"key_name": key, "cpd_id": value})
return forward_cps
+
+ def get_substitution_mappings(self, tosca):
+ node = {}
+ substitution_mappings = tosca.tpl['topology_template'].get('substitution_mappings', None)
+ if substitution_mappings:
+ node = substitution_mappings.get('properties', {})
+ node['type'] = substitution_mappings['node_type']
+ return node
+
+ def build_vnf(self, tosca):
+ properties = self.get_substitution_mappings(tosca)
+ metadata = self.buildMetadata(tosca)
+ if properties.get("descriptor_id", "") == "":
+ descriptor_id = metadata.get("descriptor_id", "")
+ if descriptor_id == "":
+ descriptor_id = metadata.get("id", "")
+ if descriptor_id == "":
+ descriptor_id = metadata.get("UUID", "")
+ # if descriptor_id == "":
+ # raise CatalogException('descriptor_id is Null.')
+ else:
+ properties["descriptor_id"] = descriptor_id
+
+ if properties.get("descriptor_verison", "") == "":
+ version = metadata.get("template_version", "")
+ if version == "":
+ version = metadata.get("version", "")
+ properties["descriptor_verison"] = version
+
+ if properties.get("provider", "") == "":
+ provider = metadata.get("template_author", "")
+ if provider == "":
+ provider = metadata.get("provider", "")
+ properties["provider"] = provider
+
+ if properties.get("template_name", "") == "":
+ template_name = metadata.get("template_name", "")
+ if template_name == "":
+ template_name = metadata.get("template_name", "")
+ properties["template_name"] = template_name
+ vnf = {}
+ vnf['properties'] = properties
+ vnf['metadata'] = metadata
+ return vnf