Fix mishandling of BirdErrors in BirdSocketTopologyProvider

styling
LEdoian 1 year ago
parent 2cb43bbc9f
commit 61b058bcfc

@ -454,8 +454,8 @@ class ProcessTopologyProvider(TopologyProvider):
class BirdMultipleInstancesError(BirdError): class BirdMultipleInstancesError(BirdError):
"""BIRD has multiple known OSPF's running. """BIRD has multiple known OSPF's running.
This exception is intended to be created from existing BirdError. (We do This exception is intended to be created from existing BirdError. (We stil
not re-raise, because we know what has happened.)""" re-raise, so the error message is sane.)"""
def __init__(self, orig_exc: BirdError, protocols: list[str]): def __init__(self, orig_exc: BirdError, protocols: list[str]):
for attr in ['code', 'start', 'end', 'text']: for attr in ['code', 'start', 'end', 'text']:
val = getattr(orig_exc, attr) val = getattr(orig_exc, attr)
@ -493,9 +493,9 @@ class BirdSocketTopologyProvider(TopologyProvider):
try: try:
response = sock.request(request) response = sock.request(request)
except BirdError as e: except BirdError as e:
if e.text == 'There are multiple OSPF protocols running': if e.text == 'There are multiple OSPF protocols running\n':
protocols = self.find_runing_ospf(sock) protocols = self.find_runing_ospf(sock)
raise BirdMultipleInstancesError(e, protocols) raise BirdMultipleInstancesError(e, protocols) from e
raise raise
parser = OspfFileTopologyParser(version=self.version, area=self.area) parser = OspfFileTopologyParser(version=self.version, area=self.area)
return parser.parse(response.text, freeze=self.freeze) return parser.parse(response.text, freeze=self.freeze)
@ -507,7 +507,7 @@ class BirdSocketTopologyProvider(TopologyProvider):
assert len(resp.codes) == 3 assert len(resp.codes) == 3
assert resp.codes[0] == ((1,1), '2002') assert resp.codes[0] == ((1,1), '2002')
assert resp.codes[1][1] == '1002' assert resp.codes[1][1] == '1002'
lines = resp.splitlines() lines = resp.text.splitlines()
header = lines[0] header = lines[0]
fields = header.split() fields = header.split()
assert fields[0] == 'Name' assert fields[0] == 'Name'

Loading…
Cancel
Save