X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FNBI.git;a=blobdiff_plain;f=osm_nbi%2Fdescriptor_topics.py;h=deae786f14ffdee736dd91fe792fa4eb4af29b91;hp=d986963cf116718bb3da05eee6d41337cd8a490e;hb=HEAD;hpb=00f83aae0eb5dc138ac703b9ff37181baa082073 diff --git a/osm_nbi/descriptor_topics.py b/osm_nbi/descriptor_topics.py index d986963..b165b76 100644 --- a/osm_nbi/descriptor_topics.py +++ b/osm_nbi/descriptor_topics.py @@ -31,6 +31,7 @@ from time import time from uuid import uuid4 from re import fullmatch from zipfile import ZipFile +from urllib.parse import urlparse from osm_nbi.validation import ( ValidationError, pdu_new_schema, @@ -681,7 +682,7 @@ class DescriptorTopic(BaseTopic): # to preserve current expected behaviour if "userDefinedData" in indata: data = indata.pop("userDefinedData") - if type(data) == dict: + if isinstance(data, dict): indata["_admin"]["userDefinedData"] = data else: raise EngineException( @@ -858,12 +859,18 @@ class VnfdTopic(DescriptorTopic): @staticmethod def validate_helm_chart(indata): + def is_url(url): + result = urlparse(url) + return all([result.scheme, result.netloc]) + kdus = indata.get("kdu", []) for kdu in kdus: helm_chart_value = kdu.get("helm-chart") if not helm_chart_value: continue - if not valid_helm_chart_re.match(helm_chart_value): + if not ( + valid_helm_chart_re.match(helm_chart_value) or is_url(helm_chart_value) + ): raise EngineException( "helm-chart '{}' is not valid".format(helm_chart_value), http_code=HTTPStatus.UNPROCESSABLE_ENTITY, @@ -1460,6 +1467,8 @@ class NsdTopic(DescriptorTopic): # TODO validata that if contains cloud-init-file or charms, have artifacts _admin.storage."pkg-dir" is not none for vld in get_iterable(indata.get("virtual-link-desc")): self.validate_vld_mgmt_network_with_virtual_link_protocol_data(vld, indata) + for fg in get_iterable(indata.get("vnffgd")): + self.validate_vnffgd_data(fg, indata) self.validate_vnf_profiles_vnfd_id(indata) @@ -1481,6 +1490,45 @@ class NsdTopic(DescriptorTopic): http_code=HTTPStatus.UNPROCESSABLE_ENTITY, ) + @staticmethod + def validate_vnffgd_data(fg, indata): + position_list = [] + all_vnf_ids = set(get_iterable(fg.get("vnf-profile-id"))) + for fgposition in get_iterable(fg.get("nfp-position-element")): + position_list.append(fgposition["id"]) + + for nfpd in get_iterable(fg.get("nfpd")): + nfp_position = [] + for position in get_iterable(nfpd.get("position-desc-id")): + nfp_position = position.get("nfp-position-element-id") + if position == "nfp-position-element-id": + nfp_position = position.get("nfp-position-element-id") + if nfp_position[0] not in position_list: + raise EngineException( + "Error at vnffgd nfpd[id='{}']:nfp-position-element-id='{}' " + "does not match any nfp-position-element".format( + nfpd["id"], nfp_position[0] + ), + http_code=HTTPStatus.UNPROCESSABLE_ENTITY, + ) + + for cp in get_iterable(position.get("cp-profile-id")): + for cpe in get_iterable(cp.get("constituent-profile-elements")): + constituent_base_element_id = cpe.get( + "constituent-base-element-id" + ) + if ( + constituent_base_element_id + and constituent_base_element_id not in all_vnf_ids + ): + raise EngineException( + "Error at vnffgd constituent_profile[id='{}']:vnfd-id='{}' " + "does not match any constituent-base-element-id".format( + cpe["id"], constituent_base_element_id + ), + http_code=HTTPStatus.UNPROCESSABLE_ENTITY, + ) + @staticmethod def validate_vnf_profiles_vnfd_id(indata): all_vnfd_ids = set(get_iterable(indata.get("vnfd-id"))) @@ -1524,7 +1572,7 @@ class NsdTopic(DescriptorTopic): # to preserve current expected behaviour if "userDefinedData" in indata: data = indata.pop("userDefinedData") - if type(data) == dict: + if isinstance(data, dict): indata["_admin"]["userDefinedData"] = data else: raise EngineException(