Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of garbage input to get_event_ids #45

Merged
merged 2 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/zinolib/controllers/zino1.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
from ..compat import StrEnum
from ..event_types import EventType, Event, HistoryEntry, LogEntry, AdmState
from ..event_types import PortStateEvent
from ..ritz import ZinoError, ritz, notifier
from ..ritz import ZinoError, ProtocolError, ritz, notifier
from ..utils import log_exception_with_params


Expand Down Expand Up @@ -297,7 +297,10 @@

@staticmethod
def get_event_ids(request):
return request.get_caseids()
try:
return request.get_caseids()
except ProtocolError as e:
raise RetryError('Zino 1 failed to send a correct response header, retry') from e

Check warning on line 303 in src/zinolib/controllers/zino1.py

View check run for this annotation

Codecov / codecov/patch

src/zinolib/controllers/zino1.py#L300-L303

Added lines #L300 - L303 were not covered by tests


class HistoryAdapter:
Expand Down Expand Up @@ -400,7 +403,7 @@
try:
timestamp = int(timestamp)
except ValueError as e:
raise RetryError('Zino 1 is flaking out, retry') from e
raise RetryError('Zino 1 did not send a log, retry') from e

Check warning on line 406 in src/zinolib/controllers/zino1.py

View check run for this annotation

Codecov / codecov/patch

src/zinolib/controllers/zino1.py#L406

Added line #L406 was not covered by tests
dt = convert_timestamp(timestamp)
log_list.append({"date": dt, "log": log})
return log_list
Expand Down Expand Up @@ -485,7 +488,7 @@
self._verify_session()
attrlist = self.rename_exception(self._event_adapter.get_attrlist, self.session.request, event_id)
if not self._event_adapter.validate_raw_attrlist(attrlist):
raise RetryError('Zino 1 is flaking out, retry')
raise RetryError('Zino 1 did not send event attributes, retry')
attrdict = self._event_adapter.attrlist_to_attrdict(attrlist)
attrdict = self._event_adapter.convert_values(attrdict)
return Event.create(attrdict)
Expand Down
4 changes: 2 additions & 2 deletions src/zinolib/ritz.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,10 @@
line, buffer = buffer.split(self.DELIMITER, 1)
rawh = line.split(" ", 1) # ' ' is not a byte
header = (int(rawh[0]), rawh[1])
except ValueError:
except ValueError as e:

Check warning on line 394 in src/zinolib/ritz.py

View check run for this annotation

Codecov / codecov/patch

src/zinolib/ritz.py#L394

Added line #L394 was not covered by tests
raise ProtocolError(
"Illegal response from server detected: %s" % repr(buffer)
)
) from e
# header = line
# Crude error detection :)
if header[0] >= 500:
Expand Down
Loading