Fix librouteros response error handling (#31588)

This commit is contained in:
Rami Mosleh 2020-02-07 15:03:32 +02:00 committed by GitHub
parent 37205f9f61
commit c0eb399d54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -126,7 +126,7 @@ class MikrotikData:
def get_info(self, param): def get_info(self, param):
"""Return device model name.""" """Return device model name."""
cmd = IDENTITY if param == NAME else INFO cmd = IDENTITY if param == NAME else INFO
data = list(self.command(MIKROTIK_SERVICES[cmd])) data = self.command(MIKROTIK_SERVICES[cmd])
return data[0].get(param) if data else None return data[0].get(param) if data else None
def get_hub_details(self): def get_hub_details(self):
@ -148,7 +148,7 @@ class MikrotikData:
def get_list_from_interface(self, interface): def get_list_from_interface(self, interface):
"""Get devices from interface.""" """Get devices from interface."""
result = list(self.command(MIKROTIK_SERVICES[interface])) result = self.command(MIKROTIK_SERVICES[interface])
return self.load_mac(result) if result else {} return self.load_mac(result) if result else {}
def restore_device(self, mac): def restore_device(self, mac):
@ -224,7 +224,7 @@ class MikrotikData:
"address": ip_address, "address": ip_address,
} }
cmd = "/ping" cmd = "/ping"
data = list(self.command(cmd, params)) data = self.command(cmd, params)
if data is not None: if data is not None:
status = 0 status = 0
for result in data: for result in data:
@ -242,9 +242,9 @@ class MikrotikData:
try: try:
_LOGGER.info("Running command %s", cmd) _LOGGER.info("Running command %s", cmd)
if params: if params:
response = self.api(cmd=cmd, **params) response = list(self.api(cmd=cmd, **params))
else: else:
response = self.api(cmd=cmd) response = list(self.api(cmd=cmd))
except ( except (
librouteros.exceptions.ConnectionClosed, librouteros.exceptions.ConnectionClosed,
socket.error, socket.error,