From e66520c475555b12fc67bbd6520de5acde218b9c Mon Sep 17 00:00:00 2001 From: Denys Fedoryshchenko Date: Fri, 6 Dec 2024 00:04:21 +0200 Subject: [PATCH] fix(main.py): Reset kcidb flag on state change If state changed, likely we need to reprocess the node. Signed-off-by: Denys Fedoryshchenko --- api/main.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/api/main.py b/api/main.py index fc56aadf..a649a68b 100644 --- a/api/main.py +++ b/api/main.py @@ -42,6 +42,7 @@ KernelVersion, EventHistory, ) +from pydantic import BaseModel from .auth import Authentication from .db import Database from .pubsub import PubSub @@ -59,7 +60,7 @@ UserGroup, ) from .metrics import Metrics -from pydantic import BaseModel + @asynccontextmanager @@ -747,6 +748,11 @@ async def put_node(node_id: str, node: Node, status_code=status.HTTP_400_BAD_REQUEST, detail=message ) + # if state changes, reset processed_by_kcidb_bridge flag + if node.state != new_node_def.state: + new_node_def.processed_by_kcidb_bridge = False + # Now we can update the state + new_node_def.state = node.state # KCIDB flags are reset on any update, because this means we need # to reprocess updated node. @@ -756,9 +762,6 @@ async def put_node(node_id: str, node: Node, if old_flag == new_flag: new_node_def.processed_by_kcidb_bridge = False - # Now we can update the state - new_node_def.state = node.state - # Update node in the DB obj = await db.update(new_node_def) data = _get_node_event_data('updated', obj) @@ -773,6 +776,7 @@ async def put_node(node_id: str, node: Node, class NodeUpdateRequest(BaseModel): + """Request model for updating multiple nodes""" nodes: List[str] field: str value: str @@ -803,9 +807,9 @@ async def put_batch_nodeset(data: NodeUpdateRequest, # right now we support only field: # processed_by_kcidb_bridge, also value should be boolean if field == 'processed_by_kcidb_bridge': - if value == 'true' or value == 'True': + if value in ['true', 'True']: value = True - elif value == 'false' or value == 'False': + elif value in ['false', 'False']: value = False setattr(node_from_id, field, value) await db.update(node_from_id)