mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 12:46:49 +00:00
fix(instances): the VM list survives a host that stops answering mid-request
The VM list reads each reachable host's CPUs and memory while it renders, after it has found the host reachable. When the network to a host dropped during that request, libvirt's keepalive closed the connection in between, and the read raised: the whole list became the 500 error page after about 40 s. Only the next load showed the host as down. The host's CPU, memory and memory-use reads now give None for a host that stopped answering; the list leaves its numbers out and the New VM dialog does not offer it. Checked on compute1 with its libvirt port dropped mid-request: the list answers 200. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
parent
b70bab2144
commit
6cdda6d4f3
4 changed files with 35 additions and 5 deletions
|
|
@ -88,17 +88,28 @@ class Compute(Model):
|
|||
self.type,
|
||||
)
|
||||
|
||||
# The VM list reads these when it renders, after status: a host that
|
||||
# stopped answering meanwhile gives None, not an error page.
|
||||
@cached_property
|
||||
def cpu_count(self):
|
||||
return self.proxy.host_info[2]
|
||||
try:
|
||||
return self.proxy.host_info[2]
|
||||
except libvirtError:
|
||||
return None
|
||||
|
||||
@cached_property
|
||||
def ram_size(self):
|
||||
return self.proxy.host_info[1] * 1048576 # MiB
|
||||
try:
|
||||
return self.proxy.host_info[1] * 1048576 # MiB
|
||||
except libvirtError:
|
||||
return None
|
||||
|
||||
@cached_property
|
||||
def ram_usage(self):
|
||||
return self.proxy.get_memory_usage()["percent"]
|
||||
try:
|
||||
return self.proxy.get_memory_usage()["percent"]
|
||||
except libvirtError:
|
||||
return None
|
||||
|
||||
@cached_property
|
||||
def capacity(self):
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@
|
|||
<span class="host-collapsed-badge badge text-bg-secondary d-none">{% trans "collapsed" %}</span>
|
||||
</div>
|
||||
</td>
|
||||
{% if compute.status is True %}
|
||||
{% if compute.status is True and compute.ram_usage is not None %}
|
||||
<td class="d-none d-sm-table-cell">{{ compute.cpu_count }}</td>
|
||||
<td class="d-none d-sm-table-cell">{{ compute.ram_size|filesizeformat }}</td>
|
||||
<td>
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ from django.test import TestCase
|
|||
from django.urls import reverse
|
||||
from instances.models import Instance
|
||||
from lxml import html
|
||||
from libvirt import libvirtError
|
||||
from vrtManager.util import OperationError
|
||||
|
||||
ERROR = "Connection Failed: No route to host"
|
||||
|
|
@ -75,6 +76,23 @@ class UnreachableListTests(TestCase):
|
|||
self.assert_unknown(response, [self.vm_a, self.vm_b])
|
||||
self.assertContains(response, ERROR)
|
||||
|
||||
def test_a_host_that_stops_answering_while_the_list_is_made_is_no_error_page(self):
|
||||
# status read True, then the host's keepalive ran out: its numbers fail
|
||||
AppSettings.objects.filter(key="VIEW_INSTANCES_LIST_STYLE").update(value="grouped")
|
||||
def gone():
|
||||
raise libvirtError("internal error: client socket is closed")
|
||||
with patch.object(Compute, "status", new_callable=PropertyMock, return_value=True), \
|
||||
patch.object(Compute, "connection_error", new_callable=PropertyMock, return_value=None), \
|
||||
patch("instances.views.refresh_instance_database"), \
|
||||
patch.object(Compute, "proxy", new_callable=PropertyMock, return_value=type("P", (), {
|
||||
"get_domain_rows": lambda self, uuids=None: {}, "get_memory_usage": lambda self: gone(),
|
||||
"host_info": property(lambda self: gone())})()):
|
||||
response = self.client.get(reverse("instances:index"))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, "vm-a")
|
||||
# not offered for a new VM
|
||||
self.assertNotContains(response, reverse("instances:create_instance_select_type", args=[self.compute.id]))
|
||||
|
||||
def test_grouped_index_lists_the_vms_of_a_down_host(self):
|
||||
AppSettings.objects.filter(key="VIEW_INSTANCES_LIST_STYLE").update(value="grouped")
|
||||
response = self.get(reverse("instances:index"))
|
||||
|
|
|
|||
|
|
@ -105,7 +105,8 @@ def index(request):
|
|||
request,
|
||||
"allinstances.html",
|
||||
{"computes": computes, "instances": instances, "show_hosts": show_hosts, "own_hosts_down": own_hosts_down,
|
||||
"reachable_computes": [c for c in computes if c.status is True],
|
||||
# the hosts a new VM can go to: one that stopped answering since status has no numbers
|
||||
"reachable_computes": [c for c in computes if c.status is True and c.ram_usage is not None],
|
||||
"unreachable_computes": [c for c in computes if c.status is not True],
|
||||
"states": [label for label, _color in STATES.values()] + [UNKNOWN[0]],
|
||||
"states_url": reverse("instances:states")},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue