1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 09:26:03 +00:00

feat(storages): a volume downloads from its pool page

The volume menu of a pool page gets Download: the host reads the volume
with libvirt's download stream and the panel passes it on in chunks, so
a disk image never sits in the panel's memory. The file is the volume as
stored: a qcow2 volume comes as its qcow2 file. A volume a running VM
uses is refused, as for a copy; the refusal is a message on the pool
page. Each download is a row in the audit log.

gunicorn's worker exits when a request runs past its timeout (600 s), to
end requests stuck on a host. A download of a large disk runs longer, so
each chunk sent starts the request's timeout again: a download that stops
sending is still ended. nginx passes the chunks on as they come
(X-Accel-Buffering: no) instead of spooling them to a file.
This commit is contained in:
catborise 2026-11-15 00:31:42 +03:00
parent 44b6e42f8f
commit c9fef349d5
13 changed files with 239 additions and 52 deletions

View file

@ -7,6 +7,18 @@ import time
from gunicorn.workers.gthread import ThreadWorker
_worker = None # this process's worker; None outside gunicorn
def request_progressed():
"""The calling request is still sending, not stuck: its timeout starts
again (a download streams for longer than the timeout)."""
if _worker is not None:
with _worker.started_lock:
if threading.get_ident() in _worker.started:
_worker.started[threading.get_ident()] = time.monotonic()
class Worker(ThreadWorker):
"""gunicorn kills a sync worker whose request runs past its timeout; a
threaded worker keeps reporting in while one of its threads waits on a
@ -18,6 +30,8 @@ class Worker(ThreadWorker):
super().__init__(*args, **kwargs)
self.started = {} # thread: when its request started
self.started_lock = threading.Lock()
global _worker
_worker = self
def handle(self, conn):
thread = threading.get_ident()

View file

@ -8,7 +8,7 @@ from unittest.mock import MagicMock, patch
from gunicorn.workers.gthread import ThreadWorker
from webvirtcloud.gunicorn_worker import Worker
from webvirtcloud.gunicorn_worker import Worker, request_progressed
def worker():
@ -42,6 +42,16 @@ class WorkerTestCase(unittest.TestCase):
notify.assert_called_once_with()
exit_.assert_not_called()
def test_a_request_that_still_sends_is_timed_from_its_last_progress(self):
w = worker()
w.started[threading.get_ident()] = time.monotonic() - 601
with patch("webvirtcloud.gunicorn_worker._worker", w):
request_progressed()
with patch.object(ThreadWorker, "notify") as notify, patch("os._exit") as exit_:
w.notify()
notify.assert_called_once_with()
exit_.assert_not_called()
def test_the_worker_exits_when_a_request_runs_past_the_timeout(self):
w = worker()
w.started.update({1: time.monotonic(), 2: time.monotonic() - 601})