From: garciadeblas Date: Fri, 20 Dec 2024 10:39:13 +0000 (+0100) Subject: Add update_state_operation_history function to update states with arbitrary text... X-Git-Tag: v17.0.0~2 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F55%2F14855%2F1;p=osm%2FLCM.git Add update_state_operation_history function to update states with arbitrary text in an operation Change-Id: I47b87d4a02163ca0fb5c6b979d7766b97fb1ce4e Signed-off-by: garciadeblas --- diff --git a/osm_lcm/k8s.py b/osm_lcm/k8s.py index 3d974fce..9aa1a218 100644 --- a/osm_lcm/k8s.py +++ b/osm_lcm/k8s.py @@ -88,6 +88,33 @@ class GitOpsLcm(LcmBase): ) return operation.get("operationType", {}) + def update_state_operation_history( + self, content, op_id, workflow_state=None, resource_state=None + ): + self.logger.info( + f"Update state of operation {op_id} in Operation History in DB" + ) + self.logger.info( + f"Workflow state: {workflow_state}. Resource state: {resource_state}" + ) + self.logger.debug(f"Content: {content}") + + op_num = 0 + for operation in content["operationHistory"]: + self.logger.debug("Operations: {}".format(operation)) + if operation["op_id"] == op_id: + self.logger.debug("Found operation number: {}".format(op_num)) + if workflow_state is not None: + operation["workflowState"] = workflow_state + + if resource_state is not None: + operation["resourceState"] = resource_state + break + op_num += 1 + self.logger.debug("content: {}".format(content)) + + return content + def update_operation_history( self, content, op_id, workflow_status=None, resource_status=None, op_end=True ): @@ -198,8 +225,8 @@ class GitOpsLcm(LcmBase): return status, message else: db_item["resourceState"] = checking["resourceState"] - db_item = self.update_operation_history( - db_item, op_id, "COMPLETED", checking["resourceState"] + db_item = self.update_state_operation_history( + db_item, op_id, None, checking["resourceState"] ) self.db.set_one(db_collection, {"_id": db_item["_id"]}, db_item) except Exception as e: