Неудачное создание машины: панель больше не предлагает экран несуществующей машины, даёт «Создать заново» с тем же образом и удаляет недосозданный диск

Этот коммит содержится в:
2026-09-27 17:24:01 +09:00
родитель 48ac535c3a
Коммит 984eb85a5a
4 изменённых файлов: 74 добавлений и 5 удалений
+34
Просмотреть файл
@@ -1,3 +1,4 @@
import uuid
from pathlib import Path
from urllib.parse import unquote
@@ -220,3 +221,36 @@ def test_vm_create_disk_bigger_than_free_space_needs_confirmation(logged_in, dat
response = logged_in.post("/vm/create", data={**form, "name": "small", "disk_size": 20}, follow_redirects=False)
assert response.status_code == 303 and "--check" not in started[1]
def failed_create(data_dirs, name, disk=True, **extra):
"""Операция создания машины, у которой virt-install завершился с ошибкой."""
disk_path = data_dirs["images"] / f"{name}.qcow2"
if disk:
disk_path.write_bytes(b"QFI\xfb")
operation = {"id": str(uuid.uuid4()), "type": "vm_create", "title": f"Создание VM {name}", "status": "queued", "progress": 0, "message": "", "created_at": app.utc_now(), "updated_at": app.utc_now(), "vm_name": name, "disk_path": str(disk_path), "network_mode": "bridge", **extra}
app.write_operation(operation)
app.run_operation_worker(operation["id"], ["bash", "-c", "echo 'ERROR The requested volume capacity will exceed the available pool space'; exit 1"])
return app.read_operation(operation["id"]), disk_path
def test_failed_vm_create_cleans_up_and_offers_retry(logged_in, data_dirs):
"""Страница упавшей задачи предлагала «Открыть экран машины», хотя машины нет; недосозданный диск мешал повтору."""
operation, disk_path = failed_create(data_dirs, "smk", iso_path=str(data_dirs["iso"] / "smk-server-_1.iso"))
assert operation["status"] == "error" and "ничего не осталось" in operation["message"]
assert not disk_path.exists() and "Недосозданный диск smk.qcow2 удалён" in operation["log_tail"]
html = logged_in.get(f"/operations/{operation['id']}").text
assert 'data-op-done="success" hidden' in html
assert 'href="/vm/create?iso=smk-server-_1.iso"' in html and "Создать заново" in html
def test_failed_create_of_existing_vm_keeps_its_disk(logged_in, data_dirs):
operation, disk_path = failed_create(data_dirs, "web01") # машина определена в libvirt: её диск не трогаем
assert disk_path.exists() and "ничего не осталось" not in operation["message"]
html = logged_in.get(f"/operations/{operation['id']}").text
assert "Создать заново" not in html and 'href="/vm/web01">Перейти к машине' in html
def test_operation_page_reveals_only_buttons_for_its_result():
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