From: garciadeblas Date: Thu, 12 Dec 2024 10:07:08 +0000 (+0100) Subject: Rewrite update_operation_history to simplify and add flag to update endDate X-Git-Tag: v17.0.0~16 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=f90928948417b3a1c4cfe0204b26bdf021ed41bc;p=osm%2FLCM.git Rewrite update_operation_history to simplify and add flag to update endDate Change-Id: Idae96633a03648a23cc7d3c693089a90920ea1eb Signed-off-by: garciadeblas --- diff --git a/osm_lcm/k8s.py b/osm_lcm/k8s.py index e1f86398..0c445f05 100644 --- a/osm_lcm/k8s.py +++ b/osm_lcm/k8s.py @@ -89,7 +89,7 @@ class GitOpsLcm(LcmBase): return operation.get("operationType", {}) def update_operation_history( - self, content, op_id, workflow_status=None, resource_status=None + self, content, op_id, workflow_status=None, resource_status=None, op_end=True ): self.logger.info( f"Update Operation History in DB. Workflow status: {workflow_status}. Resource status: {resource_status}" @@ -101,25 +101,26 @@ class GitOpsLcm(LcmBase): self.logger.debug("Operations: {}".format(operation)) if operation["op_id"] == op_id: self.logger.debug("Found operation number: {}".format(op_num)) - now = time() if workflow_status: - content["operationHistory"][op_num]["workflowState"] = "COMPLETED" - content["operationHistory"][op_num]["result"] = True + operation["workflowState"] = "COMPLETED" + operation["result"] = True else: - content["operationHistory"][op_num]["workflowState"] = "ERROR" - content["operationHistory"][op_num]["operationState"] = "FAILED" - content["operationHistory"][op_num]["result"] = False + operation["workflowState"] = "ERROR" + operation["operationState"] = "FAILED" + operation["result"] = False if resource_status: - content["operationHistory"][op_num]["resourceState"] = "READY" - content["operationHistory"][op_num]["operationState"] = "COMPLETED" - content["operationHistory"][op_num]["result"] = True + operation["resourceState"] = "READY" + operation["operationState"] = "COMPLETED" + operation["result"] = True else: - content["operationHistory"][op_num]["resourceState"] = "NOT_READY" - content["operationHistory"][op_num]["operationState"] = "FAILED" - content["operationHistory"][op_num]["result"] = False + operation["resourceState"] = "NOT_READY" + operation["operationState"] = "FAILED" + operation["result"] = False - content["operationHistory"][op_num]["endDate"] = now + if op_end: + now = time() + operation["endDate"] = now break op_num += 1 self.logger.debug("content: {}".format(content))