Add update_state_operation_history function to update states with arbitrary text... 55/14855/1
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Fri, 20 Dec 2024 10:39:13 +0000 (11:39 +0100)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Fri, 20 Dec 2024 10:39:22 +0000 (11:39 +0100)
Change-Id: I47b87d4a02163ca0fb5c6b979d7766b97fb1ce4e
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
osm_lcm/k8s.py

index 3d974fc..9aa1a21 100644 (file)
@@ -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: