Handle websockify v0.9.0 in console proxy
In websockify v0.9.0, the 'socket' staticmethod moved from the websockfiy.websocket.WebSocketServer class to the websockify.websockifyserver.WebSockifyServer class [1][2], so our import of the top-level module is no longer sufficient for accessing the 'socket' method [3] when using v0.9.0: AttributeError: module 'websockify' has no attribute 'WebSocketServer' This adds a try_import from the v0.9.0 location and uses WebSockifyServer.socket if the module is present. Otherwise, it will fall back on the old location. This way, we are able to run with websockify v0.9.0 and earlier versions with the same code. Partial-Bug: #1840788 [1]8a69762249
[2]e47591f4aa
[3] https://github.com/novnc/websockify/blob/v0.9.0/websockify/__init__.py Change-Id: I4a50e2f772101315140df43910be2e3f69a63b73
This commit is contained in:
parent
6ddfad5935
commit
791fa595e6
|
@ -23,6 +23,7 @@ import sys
|
|||
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import encodeutils
|
||||
from oslo_utils import importutils
|
||||
import six
|
||||
from six.moves import http_cookies as Cookie
|
||||
import six.moves.urllib.parse as urlparse
|
||||
|
@ -35,6 +36,9 @@ from nova import exception
|
|||
from nova.i18n import _
|
||||
from nova import objects
|
||||
|
||||
# Location of WebSockifyServer class in websockify v0.9.0
|
||||
websockifyserver = importutils.try_import('websockify.websockifyserver')
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
CONF = nova.conf.CONF
|
||||
|
@ -284,7 +288,16 @@ class NovaProxyRequestHandler(NovaProxyRequestHandlerBase,
|
|||
return self._compute_rpcapi
|
||||
|
||||
def socket(self, *args, **kwargs):
|
||||
return websockify.WebSocketServer.socket(*args, **kwargs)
|
||||
# TODO(melwitt): The try_import and if-else condition can be removed
|
||||
# when we get to the point where we're requiring at least websockify
|
||||
# v.0.9.0 in our lower-constraints.
|
||||
if websockifyserver is not None:
|
||||
# In websockify v0.9.0, the 'socket' method moved to the
|
||||
# websockify.websockifyserver.WebSockifyServer class.
|
||||
return websockifyserver.WebSockifyServer.socket(*args, **kwargs)
|
||||
else:
|
||||
# Fall back to the websockify <= v0.8.0 'socket' method location.
|
||||
return websockify.WebSocketServer.socket(*args, **kwargs)
|
||||
|
||||
|
||||
class NovaWebSocketProxy(websockify.WebSocketProxy):
|
||||
|
|
Loading…
Reference in New Issue