- for vnf in descriptor["constituent-vnfd"]:
- vnfd_id = vnf["vnfd-id-ref"]
- filter_q = self._get_project_filter(session, write=False, show_all=True)
- filter_q["id"] = vnfd_id
- if not self.db.get_list("vnfds", filter_q):
- raise EngineException("Descriptor error at 'constituent-vnfd':'vnfd-id-ref'='{}' references a non "
- "existing vnfd".format(vnfd_id), http_code=HTTPStatus.CONFLICT)
+ member_vnfd_index = {}
+ if descriptor.get("constituent-vnfd") and not session["force"]:
+ for vnf in descriptor["constituent-vnfd"]:
+ vnfd_id = vnf["vnfd-id-ref"]
+ filter_q = self._get_project_filter(session)
+ filter_q["id"] = vnfd_id
+ vnf_list = self.db.get_list("vnfds", filter_q)
+ if not vnf_list:
+ raise EngineException("Descriptor error at 'constituent-vnfd':'vnfd-id-ref'='{}' references a non "
+ "existing vnfd".format(vnfd_id), http_code=HTTPStatus.CONFLICT)
+ # elif len(vnf_list) > 1:
+ # raise EngineException("More than one vnfd found for id='{}'".format(vnfd_id),
+ # http_code=HTTPStatus.CONFLICT)
+ member_vnfd_index[vnf["member-vnf-index"]] = vnf_list[0]
+
+ # Cross references validation in the descriptor and vnfd connection point validation
+ for vld in get_iterable(descriptor.get("vld")):
+ for referenced_vnfd_cp in get_iterable(vld.get("vnfd-connection-point-ref")):
+ # look if this vnfd contains this connection point
+ vnfd = member_vnfd_index.get(referenced_vnfd_cp["member-vnf-index-ref"])
+ if not vnfd:
+ raise EngineException("Error at vld[id='{}']:vnfd-connection-point-ref[member-vnf-index-ref='{}'] "
+ "does not match any constituent-vnfd:member-vnf-index"
+ .format(vld["id"], referenced_vnfd_cp["member-vnf-index-ref"]),
+ http_code=HTTPStatus.UNPROCESSABLE_ENTITY)
+ for vnfd_cp in get_iterable(vnfd.get("connection-point")):
+ if referenced_vnfd_cp.get("vnfd-connection-point-ref") == vnfd_cp["name"]:
+ break
+ else:
+ raise EngineException(
+ "Error at vld[id='{}']:vnfd-connection-point-ref[member-vnf-index-ref='{}']:vnfd-"
+ "connection-point-ref='{}' references a non existing conection-point:name inside vnfd '{}'"
+ .format(vld["id"], referenced_vnfd_cp["member-vnf-index-ref"],
+ referenced_vnfd_cp["vnfd-connection-point-ref"], vnfd["id"]),
+ http_code=HTTPStatus.UNPROCESSABLE_ENTITY)