Skip to content

Commit

Permalink
topotato: better FRR startup exceptions
Browse files Browse the repository at this point in the history
Getting FileNotFoundError is confusing, and having a separate exception
for start failed also helps.

Signed-off-by: David Lamparter <[email protected]>
  • Loading branch information
eqvinox committed Jul 10, 2024
1 parent 8a2a016 commit 633b84d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
27 changes: 24 additions & 3 deletions topotato/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class TopotatoLogFail(TopotatoFail):
"""


class TopotatoDaemonCrash(TopotatoFail):
class TopotatoDaemonErrors(TopotatoFail):
"""
Daemon exited/crashed unexpectedly.
Common base for unexpected things going on with a daemon process
"""

def __init__(self, daemon: str, router: str, cmdline: Optional[str] = None):
Expand All @@ -87,7 +87,12 @@ def reprcrash(self) -> Optional["ReprFileLocation"]:
def toterminal(self, tw: TerminalWriter) -> None:
exc = self.excinfo.value
tw.line("")
tw.sep(" ", f"{exc.daemon} crashed on {exc.router}", red=True, bold=True)
tw.sep(
" ",
f"{exc.daemon} {exc.topotato_kind} on {exc.router}",
red=True,
bold=True,
)
if exc.cmdline:
tw.line("")
tw.line(f"started as: {exc.cmdline}")
Expand All @@ -96,6 +101,22 @@ def toterminal(self, tw: TerminalWriter) -> None:
tw.line(f"cause: {exc.__cause__!r}")


class TopotatoDaemonCrash(TopotatoDaemonErrors):
"""
Daemon exited/crashed unexpectedly.
"""

topotato_kind = "crashed"


class TopotatoDaemonStartFail(TopotatoDaemonErrors):
"""
Daemon did not start correctly.
"""

topotato_kind = "failed to start"


class TopotatoDaemonStopFail(TopotatoFail):
"""
Daemon did not stop when requested.
Expand Down
25 changes: 18 additions & 7 deletions topotato/frr/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def deprecated(fn): # type: ignore
from .livelog import LiveLog, LogMessage
from ..exceptions import (
TopotatoDaemonCrash,
TopotatoDaemonStartFail,
TopotatoDaemonStopFail,
TopotatoSkipped,
TopotatoFail,
Expand Down Expand Up @@ -678,17 +679,27 @@ def start_daemon(self, daemon: str, defer_config=False):
try:
self.check_call(cmdline, pass_fds=[logfd.fileno()])
except subprocess.CalledProcessError as e:
raise TopotatoDaemonCrash(
raise TopotatoDaemonStartFail(
daemon=daemon, router=self.name, cmdline=shlex.join(cmdline)
) from e

# want record-priority & timestamp precision...
pid, _, _ = self.vtysh_polled(
self.instance.timeline,
daemon,
"enable\nconfigure\nlog file %s\ndebug memstats-at-exit\nend\nclear log cmdline-targets"
% self.logfiles[daemon],
)
try:
pid, _, _ = self.vtysh_polled(
self.instance.timeline,
daemon,
"enable\nconfigure\nlog file %s\ndebug memstats-at-exit\nend\nclear log cmdline-targets"
% self.logfiles[daemon],
)
except ConnectionRefusedError as e:
raise TopotatoDaemonStartFail(
daemon=daemon, router=self.name, cmdline=shlex.join(cmdline)
) from e
except FileNotFoundError as e:
raise TopotatoDaemonStartFail(
daemon=daemon, router=self.name, cmdline=shlex.join(cmdline)
) from e

self.pids[daemon] = pid

if not defer_config:
Expand Down

0 comments on commit 633b84d

Please sign in to comment.