From 752bf1b33b76a0beae7f8e7a2a1745d940e0687e Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Thu, 30 Apr 2020 18:00:10 +0200 Subject: Handle exceptions in ssh commands --- ryu/services/protocols/bgp/operator/ssh.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ryu/services/protocols/bgp/operator/ssh.py b/ryu/services/protocols/bgp/operator/ssh.py index 5690f674..c4f4ca50 100644 --- a/ryu/services/protocols/bgp/operator/ssh.py +++ b/ryu/services/protocols/bgp/operator/ssh.py @@ -22,6 +22,7 @@ from copy import copy import logging import os.path import sys +import traceback import paramiko @@ -30,6 +31,7 @@ from ryu.lib import hub from ryu.services.protocols.bgp.base import Activity from ryu.services.protocols.bgp.operator.command import Command from ryu.services.protocols.bgp.operator.command import CommandsResponse +from ryu.services.protocols.bgp.operator.command import STATUS_ERROR from ryu.services.protocols.bgp.operator.command import STATUS_OK from ryu.services.protocols.bgp.operator.commands.root import RootCmd from ryu.services.protocols.bgp.operator.internal_api import InternalApi @@ -350,7 +352,12 @@ class SshServer(paramiko.ServerInterface): return ret def _execute_cmd(self, cmds): - result, _ = self.root(cmds) + try: + result, _ = self.root(cmds) + except: + tb = traceback.format_exc() + LOG.error(tb) + result = CommandsResponse(STATUS_ERROR, 'Internal error') LOG.debug("result: %s", result) if cmds[0] == 'quit': self.is_connected = False -- cgit v1.2.3