1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-02 00:46:05 +00:00

perf(instances): the VM page reads each disk, the state and host info once

Measured on a VM with two disks, a CD-ROM and a NIC: 70 libvirt calls per
page, now 43. Within the page's cached_reads block the VM's state, the
host's info and domain capabilities, and each disk path's volume are read
once; the running and the persistent disk lists share a path's volume.
The ISO list takes the active pools in one call instead of looking each up
by name; it still refreshes them, so an image copied in by hand shows up.

The opt-in DRBD status waits at most 10 s for the compute's ssh, then
leaves the status unknown instead of holding the page.
This commit is contained in:
catborise 2026-10-09 08:21:28 +03:00
parent 95b4418c96
commit 439f24041e
6 changed files with 278 additions and 52 deletions

View file

@ -1,10 +1,13 @@
"""drbd_status runs ssh with the compute's login@hostname; a compute whose
values would inject an ssh option (an existing or bypassed row) is skipped."""
values would inject an ssh option (an existing or bypassed row) is skipped,
and a compute that does not answer in time leaves the status unknown."""
import subprocess
import unittest
from types import SimpleNamespace
from unittest.mock import patch
from instances.views import _valid_ssh_target
from instances.views import DRBD_STATUS_TIMEOUT, _valid_ssh_target, drbd_status
class DrbdTargetTestCase(unittest.TestCase):
@ -15,3 +18,11 @@ class DrbdTargetTestCase(unittest.TestCase):
for login, hostname in (("-oProxyCommand=x", "192.0.2.1"), ("root", "-x"), ("root", "a b")):
with self.subTest(login=login, hostname=hostname):
self.assertFalse(_valid_ssh_target(SimpleNamespace(login=login, hostname=hostname)))
def test_a_compute_that_does_not_answer_leaves_the_status_unknown(self):
vm = SimpleNamespace(name="vm1", compute=SimpleNamespace(type=2, login="root", hostname="192.0.2.1"))
with patch("instances.views.get_instance", return_value=vm), patch(
"instances.views.subprocess.run", side_effect=subprocess.TimeoutExpired("ssh", DRBD_STATUS_TIMEOUT)
) as run:
self.assertEqual(drbd_status(SimpleNamespace(user=None), 1), "None DRBD")
self.assertEqual(run.call_args.kwargs["timeout"], DRBD_STATUS_TIMEOUT)