+ def _check_update_ns_operation(self, indata, nsr) -> None:
+ """Validates the ns-update request according to updateType
+
+ If updateType is CHANGE_VNFPKG:
+ - it checks the vnfInstanceId, whether it's available under ns instance
+ - it checks the vnfdId whether it matches with the vnfd-id in the vnf-record of specified VNF.
+ Otherwise exception will be raised.
+ If updateType is REMOVE_VNF:
+ - it checks if the vnfInstanceId is available in the ns instance
+ - Otherwise exception will be raised.
+
+ Args:
+ indata: includes updateType such as CHANGE_VNFPKG,
+ nsr: network service record
+
+ Raises:
+ EngineException:
+ a meaningful error if given update parameters are not proper such as
+ "Error in validating ns-update request: <ID> does not match
+ with the vnfd-id of vnfinstance
+ http_code=HTTPStatus.UNPROCESSABLE_ENTITY"
+
+ """
+ try:
+ if indata["updateType"] == "CHANGE_VNFPKG":
+ # vnfInstanceId, nsInstanceId, vnfdId are mandatory
+ vnf_instance_id = indata["changeVnfPackageData"]["vnfInstanceId"]
+ ns_instance_id = indata["nsInstanceId"]
+ vnfd_id_2update = indata["changeVnfPackageData"]["vnfdId"]
+
+ if vnf_instance_id not in nsr["constituent-vnfr-ref"]:
+ raise EngineException(
+ f"Error in validating ns-update request: vnf {vnf_instance_id} does not "
+ f"belong to NS {ns_instance_id}",
+ http_code=HTTPStatus.UNPROCESSABLE_ENTITY,
+ )
+
+ # Getting vnfrs through the ns_instance_id
+ vnfrs = self.db.get_list("vnfrs", {"nsr-id-ref": ns_instance_id})
+ constituent_vnfd_id = next(
+ (
+ vnfr["vnfd-id"]
+ for vnfr in vnfrs
+ if vnfr["id"] == vnf_instance_id
+ ),
+ None,
+ )
+
+ # Check the given vnfd-id belongs to given vnf instance
+ if constituent_vnfd_id and (vnfd_id_2update != constituent_vnfd_id):
+ raise EngineException(
+ f"Error in validating ns-update request: vnfd-id {vnfd_id_2update} does not "
+ f"match with the vnfd-id: {constituent_vnfd_id} of VNF instance: {vnf_instance_id}",
+ http_code=HTTPStatus.UNPROCESSABLE_ENTITY,
+ )
+
+ # Validating the ns update timeout
+ if (
+ indata.get("timeout_ns_update")
+ and indata["timeout_ns_update"] < 300
+ ):
+ raise EngineException(
+ "Error in validating ns-update request: {} second is not enough "
+ "to upgrade the VNF instance: {}".format(
+ indata["timeout_ns_update"], vnf_instance_id
+ ),
+ http_code=HTTPStatus.UNPROCESSABLE_ENTITY,
+ )
+ elif indata["updateType"] == "REMOVE_VNF":
+ vnf_instance_id = indata["removeVnfInstanceId"]
+ ns_instance_id = indata["nsInstanceId"]
+ if vnf_instance_id not in nsr["constituent-vnfr-ref"]:
+ raise EngineException(
+ "Invalid VNF Instance Id. '{}' is not "
+ "present in the NS '{}'".format(vnf_instance_id, ns_instance_id)
+ )
+
+ except (
+ DbException,
+ AttributeError,
+ IndexError,
+ KeyError,
+ ValueError,
+ ) as e:
+ raise type(e)(
+ "Ns update request could not be processed with error: {}.".format(e)
+ )
+