From: Gabriel Cuba Date: Tue, 19 Mar 2024 23:01:13 +0000 (-0500) Subject: Fix 2328: In NS deletion, remove EE objects according to the VCA type X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fv15.0;p=osm%2FLCM.git Fix 2328: In NS deletion, remove EE objects according to the VCA type Change-Id: I295cb403f2321faf41db91a2bb4240992cf756fe Signed-off-by: Gabriel Cuba Signed-off-by: garciadeblas --- diff --git a/osm_lcm/ROclient.py b/osm_lcm/ROclient.py index e731ec1..f39d267 100644 --- a/osm_lcm/ROclient.py +++ b/osm_lcm/ROclient.py @@ -179,6 +179,7 @@ class ROClient: @staticmethod def _parse(descriptor, descriptor_format, response=False): + error_text = "" if ( descriptor_format and descriptor_format != "json" @@ -205,8 +206,6 @@ class ROClient: if response: error_text = "json format error" + str(e) - if response: - raise ROClientException(error_text) raise ROClientException(error_text) @staticmethod diff --git a/osm_lcm/lcm_utils.py b/osm_lcm/lcm_utils.py index 12fd7fb..af460d2 100644 --- a/osm_lcm/lcm_utils.py +++ b/osm_lcm/lcm_utils.py @@ -448,6 +448,26 @@ class LcmBase: self.logger.error(f"{error} occured while getting the charm name") raise LcmException(error) + def get_vca_info(self, ee_item, db_nsr, get_charm_name: bool): + vca_name = charm_name = vca_type = None + if ee_item.get("juju"): + vca_name = ee_item["juju"].get("charm") + if get_charm_name: + charm_name = self.find_charm_name(db_nsr, str(vca_name)) + vca_type = ( + "lxc_proxy_charm" + if ee_item["juju"].get("charm") is not None + else "native_charm" + ) + if ee_item["juju"].get("cloud") == "k8s": + vca_type = "k8s_proxy_charm" + elif ee_item["juju"].get("proxy") is False: + vca_type = "native_charm" + elif ee_item.get("helm-chart"): + vca_name = ee_item["helm-chart"] + vca_type = "helm-v3" + return vca_name, charm_name, vca_type + class TaskRegistry(LcmBase): """ diff --git a/osm_lcm/ns.py b/osm_lcm/ns.py index 2fecb5d..d33d68d 100644 --- a/osm_lcm/ns.py +++ b/osm_lcm/ns.py @@ -3819,6 +3819,7 @@ class NsLcm(LcmBase): ) ) if del_repo_list or added_repo_dict: + unset = updated = None if k8sclustertype == "helm-chart": unset = { "_admin.helm_charts_added." + item: None @@ -3845,12 +3846,13 @@ class NsLcm(LcmBase): k8s_cluster_id, del_repo_list, added_repo_dict ) ) - self.db.set_one( - "k8sclusters", - {"_id": k8s_cluster_id}, - updated, - unset=unset, - ) + if updated and unset: + self.db.set_one( + "k8sclusters", + {"_id": k8s_cluster_id}, + updated, + unset=unset, + ) # Instantiate kdu step = "Instantiating KDU {}.{} in k8s cluster {}".format( @@ -3964,25 +3966,12 @@ class NsLcm(LcmBase): ) ) ee_descriptor_id = ee_item.get("id") - if ee_item.get("juju"): - vca_name = ee_item["juju"].get("charm") - if get_charm_name: - charm_name = self.find_charm_name(db_nsr, str(vca_name)) - vca_type = ( - "lxc_proxy_charm" - if ee_item["juju"].get("charm") is not None - else "native_charm" - ) - if ee_item["juju"].get("cloud") == "k8s": - vca_type = "k8s_proxy_charm" - elif ee_item["juju"].get("proxy") is False: - vca_type = "native_charm" - elif ee_item.get("helm-chart"): - vca_name = ee_item["helm-chart"] - vca_type = "helm-v3" - else: + vca_name, charm_name, vca_type = self.get_vca_info( + ee_item, db_nsr, get_charm_name + ) + if not vca_type: self.logger.debug( - logging_text + "skipping non juju neither charm configuration" + logging_text + "skipping, non juju/charm/helm configuration" ) continue @@ -4535,26 +4524,25 @@ class NsLcm(LcmBase): if nsr_deployed.get("VCA"): stage[1] = "Deleting all execution environments." self.logger.debug(logging_text + stage[1]) - vca_id = self.get_vca_id({}, db_nsr) - task_delete_ee = asyncio.ensure_future( - asyncio.wait_for( - self._delete_all_N2VC(db_nsr=db_nsr, vca_id=vca_id), - timeout=self.timeout.charm_delete, + helm_vca_list = get_deployed_vca(db_nsr, {"type": "helm-v3"}) + if helm_vca_list: + # Delete Namespace and Certificates + await self.vca_map["helm-v3"].delete_tls_certificate( + namespace=db_nslcmop["nsInstanceId"], + certificate_name=self.EE_TLS_NAME, ) - ) - # task_delete_ee = asyncio.ensure_future(self.n2vc.delete_namespace(namespace="." + nsr_id)) - tasks_dict_info[task_delete_ee] = "Terminating all VCA" - - # Delete Namespace and Certificates if necessary - if check_helm_ee_in_ns(list(db_vnfds_from_member_index.values())): - await self.vca_map["helm-v3"].delete_tls_certificate( - namespace=db_nslcmop["nsInstanceId"], - certificate_name=self.EE_TLS_NAME, - ) - await self.vca_map["helm-v3"].delete_namespace( - namespace=db_nslcmop["nsInstanceId"], - ) - + await self.vca_map["helm-v3"].delete_namespace( + namespace=db_nslcmop["nsInstanceId"], + ) + else: + vca_id = self.get_vca_id({}, db_nsr) + task_delete_ee = asyncio.ensure_future( + asyncio.wait_for( + self._delete_all_N2VC(db_nsr=db_nsr, vca_id=vca_id), + timeout=self.timeout.charm_delete, + ) + ) + tasks_dict_info[task_delete_ee] = "Terminating all VCA" # Delete from k8scluster stage[1] = "Deleting KDUs." self.logger.debug(logging_text + stage[1]) @@ -5039,12 +5027,15 @@ class NsLcm(LcmBase): # get all needed from database db_nsr = None db_nslcmop = None + db_vnfd = None db_nsr_update = {} db_nslcmop_update = {} nslcmop_operation_state = None error_description_nslcmop = None exc = None step = "" + kdu_action = False + try: # wait for any previous tasks in process step = "Waiting for previous operations to terminate" @@ -5107,7 +5098,7 @@ class NsLcm(LcmBase): self.update_db_2("nsrs", nsr_id, db_nsr_update) # look for primitive - config_primitive_desc = descriptor_configuration = None + config_primitive_desc = None if vdu_id: descriptor_configuration = get_configuration(db_vnfd, vdu_id) elif kdu_name: @@ -5719,6 +5710,7 @@ class NsLcm(LcmBase): change_type = "updated" detailed_status = "" member_vnf_index = None + vca_id = None try: # wait for any previous tasks in process @@ -8307,25 +8299,12 @@ class NsLcm(LcmBase): ) ) ee_descriptor_id = ee_item.get("id") - if ee_item.get("juju"): - vca_name = ee_item["juju"].get("charm") - if get_charm_name: - charm_name = self.find_charm_name(db_nsr, str(vca_name)) - vca_type = ( - "lxc_proxy_charm" - if ee_item["juju"].get("charm") is not None - else "native_charm" - ) - if ee_item["juju"].get("cloud") == "k8s": - vca_type = "k8s_proxy_charm" - elif ee_item["juju"].get("proxy") is False: - vca_type = "native_charm" - elif ee_item.get("helm-chart"): - vca_name = ee_item["helm-chart"] - vca_type = "helm-v3" - else: + vca_name, charm_name, vca_type = self.get_vca_info( + ee_item, db_nsr, get_charm_name + ) + if not vca_type: self.logger.debug( - logging_text + "skipping non juju neither charm configuration" + logging_text + "skipping, non juju/charm/helm configuration" ) continue