From: garciadeblas Date: Tue, 10 Dec 2024 12:42:47 +0000 (+0100) Subject: Update deregister operation to launch two workflows: deregister, delete X-Git-Tag: v17.0.0~17 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F36%2F14836%2F4;p=osm%2FLCM.git Update deregister operation to launch two workflows: deregister, delete Change-Id: I8f830f880c33eaa66a7627c4f4b498e63bb06805 Signed-off-by: garciadeblas --- diff --git a/osm_lcm/k8s.py b/osm_lcm/k8s.py index 37e638da..e1f86398 100644 --- a/osm_lcm/k8s.py +++ b/osm_lcm/k8s.py @@ -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") diff --git a/osm_lcm/odu_workflows.py b/osm_lcm/odu_workflows.py index 7e3f1632..5b90cdb8 100644 --- a/osm_lcm/odu_workflows.py +++ b/osm_lcm/odu_workflows.py @@ -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)