From: garciadeblas Date: Thu, 17 Oct 2024 13:30:30 +0000 (+0200) Subject: Clean-up of resources created in ODU workflows for KSU X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F45%2F14645%2F1;p=osm%2FLCM.git Clean-up of resources created in ODU workflows for KSU Change-Id: Iff76df1feb6b60ffa0e6f90381ca37dbda0c715b Signed-off-by: garciadeblas --- diff --git a/osm_lcm/k8s.py b/osm_lcm/k8s.py index ab6652a..1009ea6 100644 --- a/osm_lcm/k8s.py +++ b/osm_lcm/k8s.py @@ -1320,6 +1320,14 @@ class KsuLcm(LcmBase): db_ksu = self.update_operation_history(db_ksu, workflow_status, None) self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu) + # Clean items used in the workflow, no matter if the workflow succeeded + clean_status, clean_msg = await self.odu.clean_items_workflow( + "create_ksus", op_id, op_params, content + ) + self.logger.info( + f"clean_status is :{clean_status} and clean_msg is :{clean_msg}" + ) + if workflow_status: resource_status, resource_msg = await self.odu.check_resource_status( "create_ksus", op_id, op_params, content @@ -1370,6 +1378,13 @@ class KsuLcm(LcmBase): db_ksu = self.update_operation_history(db_ksu, workflow_status, None) self.db.set_one(self.db_collection, {"_id": db_ksu["_id"]}, db_ksu) + # Clean items used in the workflow, no matter if the workflow succeeded + clean_status, clean_msg = await self.odu.clean_items_workflow( + "create_ksus", op_id, op_params, content + ) + self.logger.info( + f"clean_status is :{clean_status} and clean_msg is :{clean_msg}" + ) if workflow_status: resource_status, resource_msg = await self.odu.check_resource_status( "update_ksus", op_id, op_params, content diff --git a/osm_lcm/odu_libs/ksu.py b/osm_lcm/odu_libs/ksu.py index 0292434..17c7bae 100644 --- a/osm_lcm/odu_libs/ksu.py +++ b/osm_lcm/odu_libs/ksu.py @@ -369,6 +369,48 @@ async def move_ksu(self, op_id, op_params, content): return workflow_name +async def clean_items_ksu_create(self, op_id, op_params_list, content_list): + self.logger.info("Clean items ksu_create Enter") + self.logger.info( + f"Operation {op_id}. Params: {op_params_list}. Content: {content_list}" + ) + try: + if len(content_list) > 1: + raise Exception("There is no ODU workflow yet able to manage multiple KSUs") + db_ksu = content_list[0] + ksu_name = db_ksu["git_name"].lower() + ksu_params = op_params_list[0] + oka_list = ksu_params["oka"] + if len(oka_list) > 1: + raise Exception( + "There is no ODU workflow yet able to manage multiple OKAs for a KSU" + ) + oka_item = oka_list[0] + oka_params = oka_item.get("transformation", {}) + secret_values = oka_params.get("secret_values", "") + if secret_values: + items = { + "secrets": [ + { + "name": f"ref-secret-{ksu_name}", + "namespace": "osm-workflows", + } + ] + } + await self.clean_items(items) + return True, "OK" + except Exception as e: + return False, f"Error while cleaning items: {e}" + + +async def clean_items_ksu_update(self, op_id, op_params_list, content_list): + self.logger.info("Clean items ksu_update Enter") + self.logger.info( + f"Operation {op_id}. Params: {op_params_list}. Content: {content_list}" + ) + return await self.clean_items_ksu_create(op_id, op_params_list, content_list) + + async def check_create_ksus(self, op_id, op_params, content): self.logger.info(f"Operation {op_id}. Params: {op_params}. Content: {content}") return True, "OK" diff --git a/osm_lcm/odu_workflows.py b/osm_lcm/odu_workflows.py index 2c9ed6a..fdc3af2 100644 --- a/osm_lcm/odu_workflows.py +++ b/osm_lcm/odu_workflows.py @@ -96,10 +96,12 @@ class OduWorkflow(LcmBase): }, "create_ksus": { "workflow_function": self.create_ksus, + "clean_function": self.clean_items_ksu_create, "check_resource_function": self.check_create_ksus, }, "update_ksus": { "workflow_function": self.update_ksus, + "clean_function": self.clean_items_ksu_update, "check_resource_function": self.check_update_ksus, }, "delete_ksus": { @@ -173,6 +175,8 @@ class OduWorkflow(LcmBase): delete_ksus, clone_ksu, move_ksu, + clean_items_ksu_create, + clean_items_ksu_update, check_create_ksus, check_update_ksus, check_delete_ksus,