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
This commit is contained in:
@@ -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']
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user