Skip to content

Commit

Permalink
fix(main.py): Reset kcidb flag on state change
Browse files Browse the repository at this point in the history
If state changed, likely we need to reprocess the node.

Signed-off-by: Denys Fedoryshchenko <[email protected]>
  • Loading branch information
nuclearcat committed Dec 6, 2024
1 parent 94c174a commit 19066a0
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
KernelVersion,
EventHistory,
)
from pydantic import BaseModel
from .auth import Authentication
from .db import Database
from .pubsub import PubSub
Expand All @@ -59,7 +60,7 @@
UserGroup,
)
from .metrics import Metrics
from pydantic import BaseModel



@asynccontextmanager
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 19066a0

Please sign in to comment.