AsusWRT log exceptions (#12668)

* logexception

* Improve err message #2978

* not quiet

* tests
This commit is contained in:
Johann Kellerman 2018-02-27 02:08:37 +02:00 committed by Paulus Schoutsen
parent 6a665ffb84
commit 446390a8d1
2 changed files with 8 additions and 9 deletions

View File

@ -283,15 +283,15 @@ class SshConnection(_Connection):
lines = self._ssh.before.split(b'\n')[1:-1]
return [line.decode('utf-8') for line in lines]
except exceptions.EOF as err:
_LOGGER.error("Connection refused. SSH enabled?")
_LOGGER.error("Connection refused. %s", self._ssh.before)
self.disconnect()
return None
except pxssh.ExceptionPxssh as err:
_LOGGER.error("Unexpected SSH error: %s", str(err))
_LOGGER.error("Unexpected SSH error: %s", err)
self.disconnect()
return None
except AssertionError as err:
_LOGGER.error("Connection to router unavailable: %s", str(err))
_LOGGER.error("Connection to router unavailable: %s", err)
self.disconnect()
return None
@ -301,10 +301,10 @@ class SshConnection(_Connection):
self._ssh = pxssh.pxssh()
if self._ssh_key:
self._ssh.login(self._host, self._username,
self._ssh.login(self._host, self._username, quiet=False,
ssh_key=self._ssh_key, port=self._port)
else:
self._ssh.login(self._host, self._username,
self._ssh.login(self._host, self._username, quiet=False,
password=self._password, port=self._port)
super().connect()

View File

@ -32,8 +32,7 @@ VALID_CONFIG_ROUTER_SSH = {DOMAIN: {
CONF_PROTOCOL: 'ssh',
CONF_MODE: 'router',
CONF_PORT: '22'
}
}
}}
WL_DATA = [
'assoclist 01:02:03:04:06:08\r',
@ -249,7 +248,7 @@ class TestComponentsDeviceTrackerASUSWRT(unittest.TestCase):
self.assertEqual(ssh.login.call_count, 1)
self.assertEqual(
ssh.login.call_args,
mock.call('fake_host', 'fake_user',
mock.call('fake_host', 'fake_user', quiet=False,
ssh_key=FAKEFILE, port=22)
)
@ -275,7 +274,7 @@ class TestComponentsDeviceTrackerASUSWRT(unittest.TestCase):
self.assertEqual(ssh.login.call_count, 1)
self.assertEqual(
ssh.login.call_args,
mock.call('fake_host', 'fake_user',
mock.call('fake_host', 'fake_user', quiet=False,
password='fake_pass', port=22)
)