vici: Gracefully consume/ignore incoming events in Python event deregistration

When issuing a deregistration message, some last events may still be sent
by the daemon before deregistration completes. Ignore such event messages
silently during deregistration, avoiding exceptions like:

  vici.exception.SessionException:
    Unexpected response type 7, expected '5' (EVENT_CONFIRM)
This commit is contained in:
Martin Willi
2022-12-12 14:38:09 +01:00
committed by Tobias Brunner
parent 254d4075fe
commit 484c0f8dd0
2 changed files with 4 additions and 1 deletions
@@ -84,6 +84,7 @@ class TestSession(object):
if name is None:
i += 1
if i > 2:
s.send(Packet.EVENT, name="event", message={"late": b'1'})
s.send(Packet.EVENT_CONFIRM)
s.send(Packet.EVENT_CONFIRM)
break
@@ -40,7 +40,9 @@ class Session(CommandWrappers, object):
raise EventUnknownException(
"Unknown event type '{event}'".format(event=event_type)
)
elif response.response_type != Packet.EVENT_CONFIRM:
while response.response_type == Packet.EVENT:
response = Packet.parse(self.transport.receive())
if response.response_type != Packet.EVENT_CONFIRM:
raise SessionException(
"Unexpected response type {type}, "
"expected '{confirm}' (EVENT_CONFIRM)".format(