Skip to content

Commit

Permalink
kernelci.api.helper: ignore non-node events in get_node_from_event()
Browse files Browse the repository at this point in the history
This is a provisional fix to prevent listeners from crashing when
waiting for node events upon reception of a different type of event.

Signed-off-by: Ricardo Cañuelo <[email protected]>
  • Loading branch information
Ricardo Cañuelo authored and nuclearcat committed Nov 29, 2023
1 parent 0ca2106 commit a5b43b5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion kernelci/api/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ def receive_event_data(self, sub_id):

def get_node_from_event(self, event_data):
"""Listen for an event and get the matching node object from it"""
return self.api.get_node(event_data['id'])
if 'id' in event_data:
return self.api.get_node(event_data['id'])
return None

def pubsub_event_filter(self, sub_id, event):
"""Filter Pub/Sub events
Expand Down Expand Up @@ -87,6 +89,9 @@ def receive_event_node(self, sub_id):
while True:
event = self.receive_event_data(sub_id)
node = self.get_node_from_event(event)
# Crude (provisional) filtering of non-node events
if not node:
continue
if all(self.pubsub_event_filter(sub_id, obj)
for obj in [node, event]):
return node
Expand Down

0 comments on commit a5b43b5

Please sign in to comment.