Экран машины снова подключается: noVNC 1.6 строил адрес WebSocket от своей страницы и уходил в /novnc/console/ws, путь теперь работает и с 1.6, и с 1.3

Этот коммит содержится в:
2026-09-27 17:32:45 +09:00
родитель 5d4525f78d
Коммит 209e83044a
2 изменённых файлов: 20 добавлений и 1 удалений
+17
Просмотреть файл
@@ -254,3 +254,20 @@ def test_failed_create_of_existing_vm_keeps_its_disk(logged_in, data_dirs):
def test_operation_page_reveals_only_buttons_for_its_result(): def test_operation_page_reveals_only_buttons_for_its_result():
script = (Path(__file__).resolve().parents[1] / "web" / "static" / "panel.js").read_text() script = (Path(__file__).resolve().parents[1] / "web" / "static" / "panel.js").read_text()
assert '$$(`[data-op-done="${status}"]`)' in script and "$$('[data-op-done]')" not in script assert '$$(`[data-op-done="${status}"]`)' in script and "$$('[data-op-done]')" not in script
def test_console_websocket_path_works_with_old_and_new_novnc(tmp_path, monkeypatch):
"""noVNC 1.6 (Ubuntu 26.04) считает path от /novnc/vnc.html: без "../" экран стучался в /novnc/console/ws/… и не подключался."""
import posixpath
from urllib.parse import parse_qs, urljoin, urlsplit
(tmp_path / "vnc.html").write_text("<html></html>")
monkeypatch.setattr(app, "NOVNC_DIR", tmp_path)
monkeypatch.setattr(app, "vm_vnc_display", lambda name: "127.0.0.1:0")
info = app.console_info("web01")
page = "https://panel.test:8443" + info["url"]
path = parse_qs(urlsplit(page).query)["path"][0]
token = path.rsplit("/", 1)[1]
assert app.console_serializer.loads(token) == {"vm": "web01", "port": 5900}
assert urlsplit(urljoin(page, path)).path == f"/console/ws/{token}" # noVNC 1.6: new URL(path, location.href)
assert posixpath.normpath("/" + path) == f"/console/ws/{token}" # noVNC 1.3: "wss://host:port/" + path
+3 -1
Просмотреть файл
@@ -939,7 +939,9 @@ def console_info(name: str) -> dict[str, Any]:
url = None url = None
if port and has_novnc: if port and has_novnc:
token = console_serializer.dumps({"vm": name, "port": port}) token = console_serializer.dumps({"vm": name, "port": port})
url = f"/novnc/vnc.html?autoconnect=1&resize=scale&path=console/ws/{token}" # "../": noVNC 1.6 (Ubuntu 26.04) строит адрес от своей страницы /novnc/vnc.html, а 1.3 (Ubuntu 24.04)
# приклеивает path к корню сайта; в обоих случаях получается /console/ws/<токен>.
url = f"/novnc/vnc.html?autoconnect=1&resize=scale&path=../console/ws/{token}"
return {"vm": name, "display": display, "port": port, "has_novnc": has_novnc, "novnc_dir": str(NOVNC_DIR) if NOVNC_DIR else "not installed", "url": url} return {"vm": name, "display": display, "port": port, "has_novnc": has_novnc, "novnc_dir": str(NOVNC_DIR) if NOVNC_DIR else "not installed", "url": url}