Update deregister operation to launch two workflows: deregister, delete 36/14836/4
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Tue, 10 Dec 2024 12:42:47 +0000 (13:42 +0100)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Thu, 12 Dec 2024 09:57:46 +0000 (10:57 +0100)
Change-Id: I8f830f880c33eaa66a7627c4f4b498e63bb06805
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
osm_lcm/k8s.py
osm_lcm/odu_workflows.py

index 37e638d..e1f8639 100644 (file)
@@ -590,6 +590,14 @@ class ClusterLcm(GitOpsLcm):
         )
         self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
 
+        # Clean items used in the workflow or in the cluster, no matter if the workflow succeeded
+        clean_status, clean_msg = await self.odu.clean_items_workflow(
+            "delete_cluster", op_id, op_params, db_cluster_copy
+        )
+        self.logger.info(
+            f"clean_status is :{clean_status} and clean_msg is :{clean_msg}"
+        )
+
         if workflow_status:
             resource_status, resource_msg = await self.check_resource_status(
                 "delete_cluster", op_id, op_params, db_cluster_copy
@@ -947,7 +955,6 @@ class ClusterLcm(GitOpsLcm):
             )
         )
         if workflow_status:
-            db_cluster["state"] = "DELETED"
             db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
         else:
             db_cluster["state"] = "FAILED_DELETION"
@@ -980,21 +987,12 @@ class ClusterLcm(GitOpsLcm):
             else:
                 db_cluster["resourceState"] = "ERROR"
 
-        db_cluster["operatingState"] = "IDLE"
         db_cluster = self.update_operation_history(
             db_cluster, op_id, workflow_status, resource_status
         )
-        db_cluster["current_operation"] = None
         self.db.set_one("clusters", {"_id": db_cluster["_id"]}, db_cluster)
 
-        # To delete it from DB
-        if db_cluster["state"] == "DELETED":
-            self.db.del_one("clusters", {"_id": db_cluster["_id"]})
-
-        # To delete it from k8scluster collection
-        self.db.del_one("k8sclusters", {"name": db_cluster["name"]})
-
-        return
+        return await self.delete(params, order_id)
 
     async def get_creds(self, params, order_id):
         self.logger.info("Cluster get creds Enter")
index 7e3f163..5b90cdb 100644 (file)
@@ -184,11 +184,19 @@ class OduWorkflow(LcmBase):
         self.logger.info("workflow function : {}".format(workflow_function))
         return await workflow_function(op_id, op_params, content)
 
+    async def dummy_clean_items(self, key, op_id, op_params, content):
+        self.logger.info(
+            f"Dummy clean items. Key: {key}. Operation: {op_id}. Params: {op_params}. Content: {content}"
+        )
+        return True, "OK"
+
     async def clean_items_workflow(self, key, op_id, op_params, content):
         self.logger.info(
             f"Cleaning items created during workflow launch. Key: {key}. Operation: {op_id}. Params: {op_params}. Content: {content}"
         )
-        clean_items_function = self._workflows[key]["clean_function"]
+        clean_items_function = self._workflows[key].get(
+            "clean_function", self.dummy_clean_items
+        )
         self.logger.info("clean items function : {}".format(clean_items_function))
         return await clean_items_function(op_id, op_params, content)