Fix 2328: In NS deletion, remove EE objects according to the VCA type 66/14266/2
authorGabriel Cuba <gcuba@whitestack.com>
Tue, 19 Mar 2024 23:01:13 +0000 (18:01 -0500)
committerGabriel Cuba <gcuba@whitestack.com>
Tue, 19 Mar 2024 23:12:53 +0000 (18:12 -0500)
Change-Id: I295cb403f2321faf41db91a2bb4240992cf756fe
Signed-off-by: Gabriel Cuba <gcuba@whitestack.com>
osm_lcm/lcm_utils.py
osm_lcm/ns.py

index 12fd7fb..af460d2 100644 (file)
@@ -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):
     """
index 2fecb5d..57298bd 100644 (file)
@@ -3964,25 +3964,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,25 +4522,24 @@ 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,
+                if nsr_deployed.get("VCA").get("type") != "helm-v3":
+                    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"
+                else:
+                    # Delete Namespace and Certificates
+                    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"],
                     )
-                )
-                # 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"],
-                )
 
             # Delete from k8scluster
             stage[1] = "Deleting KDUs."
@@ -8307,25 +8293,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