Fix noVNC failed TCs
- Fix noVNC failed TCs tempest.api.compute.servers.test_novnc.NoVNCConsoleTestJSON.test_novnc:
* Current noVNC request miss the / prefix in GET header in the websocket upgrade request.
* Current GET header GET ?token=xxx HTTP/1 can cause "HTTP/1.1 400 Bad Request" error.
* Fix the issue by adding / prefix and
# updated request format is: GET /?token=xxx HTTP/1.1 or GET /websockify HTTP/1.1
Related-PRODX: PRODX-28660
Change-Id: I38a91b8e293e39625d08073e2b898451b6126ecb
diff --git a/tempest/common/compute.py b/tempest/common/compute.py
index 4ac92d9..8c189f3 100644
--- a/tempest/common/compute.py
+++ b/tempest/common/compute.py
@@ -394,9 +394,24 @@
"""Upgrade the HTTP connection to a WebSocket and verify."""
# It is possible to pass the path as a query parameter in the request,
# so use it if present
+ # Given noVNC format
+ # https://x.com/vnc_auto.html?path=%3Ftoken%3Dxxx,
+ # url format is
+ # ParseResult(scheme='https', netloc='x.com',
+ # path='/vnc_auto.html', params='',
+ # query='path=%3Ftoken%3Dxxx', fragment='').
+ # qparams format is {'path': ['?token=xxx']}
qparams = urlparse.parse_qs(url.query)
- path = qparams['path'][0] if 'path' in qparams else '/websockify'
- reqdata = 'GET %s HTTP/1.1\r\n' % path
+ # according to references
+ # https://docs.python.org/3/library/urllib.parse.html
+ # https://tools.ietf.org/html/rfc3986#section-3.4
+ # qparams['path'][0] format is '?token=xxx' without / prefix
+ # remove / in /websockify to comply to references.
+ path = qparams['path'][0] if 'path' in qparams else 'websockify'
+ # Fix websocket request format by adding / prefix.
+ # Updated request format: GET /?token=xxx HTTP/1.1
+ # or GET /websockify HTTP/1.1
+ reqdata = 'GET /%s HTTP/1.1\r\n' % path
reqdata += 'Host: %s' % url.hostname
# Add port only if we have one specified
if url.port: