fix empty response handling for structured output

This commit is contained in:
checktheroads 2020-06-27 12:32:11 -07:00
parent dfe8a2bbec
commit 1a1cad5b40
2 changed files with 22 additions and 20 deletions

View file

@ -83,23 +83,20 @@ class Connect:
log.debug(f"Pre-parsed responses:\n{output}")
parsed = ()
response = None
try:
if not self.device.structured_output:
for coro in parsers:
for response in output:
_output = await coro(commands=self.query, output=response)
parsed += (_output,)
response = "\n\n".join(parsed)
elif (
self.device.structured_output
and self.device.nos in nos_parsers.keys()
and self.query_type in nos_parsers[self.device.nos].keys()
):
func = nos_parsers[self.device.nos][self.query_type]
response = func(output)
except Exception as err:
log.critical(str(err))
raise ResponseEmpty(params.messages.parsing_error)
if not self.device.structured_output:
for coro in parsers:
for response in output:
_output = await coro(commands=self.query, output=response)
parsed += (_output,)
response = "\n\n".join(parsed)
elif (
self.device.structured_output
and self.device.nos in nos_parsers.keys()
and self.query_type in nos_parsers[self.device.nos].keys()
):
func = nos_parsers[self.device.nos][self.query_type]
response = func(output)
if response is None:
response = "\n\n".join(output)

View file

@ -20,13 +20,18 @@ def parse_juniper(output):
)
if "rpc-reply" in parsed.keys():
parsed = parsed["rpc-reply"]["route-information"]["route-table"]
parsed_base = parsed["rpc-reply"]["route-information"]
elif "route-information" in parsed.keys():
parsed = parsed["route-information"]["route-table"]
parsed_base = parsed["route-information"]
if "rt" not in parsed:
if "route-table" not in parsed_base:
raise ResponseEmpty(params.messages.no_output)
if "rt" not in parsed_base["route-table"]:
raise ResponseEmpty(params.messages.no_output)
parsed = parsed_base["route-table"]
validated = JuniperRoute(**parsed)
serialized = validated.serialize().export_dict()