Rewrite update_operation_history to simplify and add flag to update endDate 37/14837/1
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Thu, 12 Dec 2024 10:07:08 +0000 (11:07 +0100)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Thu, 12 Dec 2024 10:07:08 +0000 (11:07 +0100)
Change-Id: Idae96633a03648a23cc7d3c693089a90920ea1eb
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
osm_lcm/k8s.py

index e1f8639..0c445f0 100644 (file)
@@ -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))