Update deregister operation to launch two workflows: deregister, delete
Change-Id: I8f830f880c33eaa66a7627c4f4b498e63bb06805
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
diff --git a/osm_lcm/k8s.py b/osm_lcm/k8s.py
index 37e638d..e1f8639 100644
--- a/osm_lcm/k8s.py
+++ b/osm_lcm/k8s.py
@@ -590,6 +590,14 @@
)
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 @@
)
)
if workflow_status:
- db_cluster["state"] = "DELETED"
db_cluster["resourceState"] = "IN_PROGRESS.GIT_SYNCED"
else:
db_cluster["state"] = "FAILED_DELETION"
@@ -980,21 +987,12 @@
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 7e3f163..5b90cdb 100644
--- a/osm_lcm/odu_workflows.py
+++ b/osm_lcm/odu_workflows.py
@@ -184,11 +184,19 @@
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)