From: Mukund Sivaraman Date: Wed, 6 Mar 2013 04:04:14 +0000 (+0530) Subject: [2641] Unify exception handling code X-Git-Tag: bind10-1.1.0beta1-release~51^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ee109e14bb0c0409c689ca73fb9ddd5f2435e29b;p=thirdparty%2Fkea.git [2641] Unify exception handling code Also don't catch specific exception errnos. Just handle them all equally. --- diff --git a/src/bin/bindctl/bindcmd.py b/src/bin/bindctl/bindcmd.py index ae6e3a0bdf..3bc25cc6fe 100644 --- a/src/bin/bindctl/bindcmd.py +++ b/src/bin/bindctl/bindcmd.py @@ -215,10 +215,6 @@ WARNING: Python readline module isn't available, so the command line editor return True - def __print_check_ssl_msg(self): - self._print("Please check the logs of b10-cmdctl, there may " - "have been a problem accepting SSL connections.") - def _try_login(self, username, password): ''' Attempts to log into cmdctl by sending a POST with the given @@ -236,16 +232,10 @@ WARNING: Python readline module isn't available, so the command line editor data = response.read().decode() # return here (will raise error after try block) return (response, data) - except ssl.SSLError as err: - self._print("SSL error while sending login information: ", err) - if err.errno == ssl.SSL_ERROR_EOF: - self.__print_check_ssl_msg() - except socket.error as err: - self._print("Socket error while sending login information: ", err) - # An SSL setup error can also bubble up as a plain CONNRESET... - # (on some systems it usually does) - if err.errno == errno.ECONNRESET: - self.__print_check_ssl_msg() + except (ssl.SSLError, socket.error) as err: + self._print("Error while sending login information: ", err) + self._print("Please check the logs of b10-cmdctl, there may " + "have been a problem accepting SSL connections.") pass raise FailToLogin() diff --git a/src/bin/bindctl/tests/bindctl_test.py b/src/bin/bindctl/tests/bindctl_test.py index c6512be607..921a9f5186 100644 --- a/src/bin/bindctl/tests/bindctl_test.py +++ b/src/bin/bindctl/tests/bindctl_test.py @@ -387,7 +387,11 @@ class TestConfigCommands(unittest.TestCase): self.tool.send_POST = send_POST_raiseImmediately self.assertRaises(FailToLogin, self.tool._try_login, "foo", "bar") expected_printed_messages.append( - 'Socket error while sending login information: test error') + 'Error while sending login information: test error') + expected_printed_messages.append( + 'Please check the logs of b10-cmdctl, there may have been a ' + 'problem accepting SSL connections.' + ) self.__check_printed_messages(expected_printed_messages) def create_send_POST_raiseOnRead(exception): @@ -406,7 +410,11 @@ class TestConfigCommands(unittest.TestCase): create_send_POST_raiseOnRead(socket.error("read error")) self.assertRaises(FailToLogin, self.tool._try_login, "foo", "bar") expected_printed_messages.append( - 'Socket error while sending login information: read error') + 'Error while sending login information: read error') + expected_printed_messages.append( + 'Please check the logs of b10-cmdctl, there may have been a ' + 'problem accepting SSL connections.' + ) self.__check_printed_messages(expected_printed_messages) # connection reset @@ -416,12 +424,10 @@ class TestConfigCommands(unittest.TestCase): create_send_POST_raiseOnRead(exc) self.assertRaises(FailToLogin, self.tool._try_login, "foo", "bar") expected_printed_messages.append( - 'Socket error while sending login information: ' - 'connection reset') + 'Error while sending login information: connection reset') expected_printed_messages.append( - 'Please check the logs of b10-cmdctl, there may be a ' - 'problem accepting SSL connections, such as a permission ' - 'problem on the server certificate file.' + 'Please check the logs of b10-cmdctl, there may have been a ' + 'problem accepting SSL connections.' ) self.__check_printed_messages(expected_printed_messages) @@ -431,7 +437,11 @@ class TestConfigCommands(unittest.TestCase): create_send_POST_raiseOnRead(exc) self.assertRaises(FailToLogin, self.tool._try_login, "foo", "bar") expected_printed_messages.append( - 'SSL error while sending login information: .*') + 'Error while sending login information: .*') + expected_printed_messages.append( + 'Please check the logs of b10-cmdctl, there may have been a ' + 'problem accepting SSL connections.' + ) self.__check_printed_messages(expected_printed_messages) # 'EOF' SSL error @@ -441,11 +451,10 @@ class TestConfigCommands(unittest.TestCase): create_send_POST_raiseOnRead(exc) self.assertRaises(FailToLogin, self.tool._try_login, "foo", "bar") expected_printed_messages.append( - 'SSL error while sending login information: .*') + 'Error while sending login information: .*') expected_printed_messages.append( - 'Please check the logs of b10-cmdctl, there may be a ' - 'problem accepting SSL connections, such as a permission ' - 'problem on the server certificate file.' + 'Please check the logs of b10-cmdctl, there may have been a ' + 'problem accepting SSL connections.' ) self.__check_printed_messages(expected_printed_messages)