diff --git a/osm_lcm/k8s.py b/osm_lcm/k8s.py index 3d974fcebaae7b4a318db986b6e546ebc7a92074..9aa1a21807a24d9dc98dcf9eb5bcc6b997435420 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: