From 3d208125a35ddab747c349ac420ef84cc98dd110 Mon Sep 17 00:00:00 2001 From: Sahid Orentino Ferdjaoui Date: Mon, 29 Sep 2014 11:40:26 -0400 Subject: [PATCH] console: introduce a new exception InvalidToken Introduces a new exception InvalidToken used when an effectively invalid token has be sent to a console proxy. Updates the code to take advantage of this new one. Change-Id: I9eb18541847e0ce22d5a449268876043ed8eb3a1 --- nova/console/websocketproxy.py | 3 ++- nova/exception.py | 4 ++++ nova/tests/console/test_websocketproxy.py | 7 +++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/nova/console/websocketproxy.py b/nova/console/websocketproxy.py index ef684f56a28a..903e4d97c83f 100644 --- a/nova/console/websocketproxy.py +++ b/nova/console/websocketproxy.py @@ -26,6 +26,7 @@ import websockify from nova.consoleauth import rpcapi as consoleauth_rpcapi from nova import context +from nova import exception from nova.i18n import _ from nova.openstack.common import log as logging @@ -60,7 +61,7 @@ class NovaProxyRequestHandlerBase(object): connect_info = rpcapi.check_token(ctxt, token=token) if not connect_info: - raise Exception(_("Invalid Token")) + raise exception.InvalidToken(token=token) self.msg(_('connect info: %s'), str(connect_info)) host = connect_info['host'] diff --git a/nova/exception.py b/nova/exception.py index efc5492529cc..b7464de5a1a4 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -1754,3 +1754,7 @@ class InvalidHypervisorVirtType(Invalid): class InvalidVirtualMachineMode(Invalid): msg_fmt = _("Virtual machine mode '%(vmmode)s' is not recognised") + + +class InvalidToken(Invalid): + msg_fmt = _("The token '%(token)s' is invalid or has expired") diff --git a/nova/tests/console/test_websocketproxy.py b/nova/tests/console/test_websocketproxy.py index 1e51a4d5ec42..d0d37b82187f 100644 --- a/nova/tests/console/test_websocketproxy.py +++ b/nova/tests/console/test_websocketproxy.py @@ -18,6 +18,7 @@ import mock from nova.console import websocketproxy +from nova import exception from nova import test @@ -53,7 +54,8 @@ class NovaProxyRequestHandlerBaseTestCase(test.TestCase): self.wh.path = "ws://127.0.0.1/?token=XXX" - self.assertRaises(Exception, self.wh.new_websocket_client) # noqa + self.assertRaises(exception.InvalidToken, + self.wh.new_websocket_client) check_token.assert_called_with(mock.ANY, token="XXX") @mock.patch('nova.consoleauth.rpcapi.ConsoleAuthAPI.check_token') @@ -79,5 +81,6 @@ class NovaProxyRequestHandlerBaseTestCase(test.TestCase): self.wh.path = "http://127.0.0.1/" self.wh.headers.getheader.return_value = "token=XXX" - self.assertRaises(Exception, self.wh.new_websocket_client) # noqa + self.assertRaises(exception.InvalidToken, + self.wh.new_websocket_client) check_token.assert_called_with(mock.ANY, token="XXX")