Currently, socket.error will be raised when 'quit' command is typed. This patch enables to quit SSH session without tracebacks.
Signed-off-by: IWASE Yusuke <[email protected]> --- ryu/services/protocols/bgp/operator/ssh.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ryu/services/protocols/bgp/operator/ssh.py b/ryu/services/protocols/bgp/operator/ssh.py index 35d6a7b..c228a89 100644 --- a/ryu/services/protocols/bgp/operator/ssh.py +++ b/ryu/services/protocols/bgp/operator/ssh.py @@ -110,6 +110,8 @@ class SshServer(paramiko.ServerInterface): self.transport.add_server_key(host_key) self.transport.start_server(server=self) + self.is_connected = True + # For pylint self.buf = None self.chan = None @@ -350,11 +352,15 @@ class SshServer(paramiko.ServerInterface): def _execute_cmd(self, cmds): result, _ = self.root(cmds) LOG.debug("result: %s", result) + if cmds[0] == 'quit': + self.is_connected = False + return result.status self.prompted = False self._startnewline() output = result.value.replace('\n', '\n\r').rstrip() self.chan.send(output) self.prompted = True + self._startnewline() return result.status def end_session(self): @@ -377,7 +383,7 @@ class SshServer(paramiko.ServerInterface): self.chan.send(self.WELCOME) self._startnewline() - while True: + while self.is_connected: c = self.chan.recv(1) c = c.decode() # For Python3 compatibility @@ -477,9 +483,14 @@ class SshServer(paramiko.ServerInterface): self.history.insert(0, self.buf) self.histindex = 0 self._execute_cmd(cmds) + else: + LOG.debug("no command is interpreted. " + "just start a new line.") + self._startnewline() else: - LOG.debug("blank buf. just start a new line.") - self._startnewline() + LOG.debug("blank buf is detected. " + "just start a new line.") + self._startnewline() LOG.debug("curpos: %d, buf: %s, prompted: %s", self.curpos, self.buf, self.prompted) -- 2.7.4 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
