diff --git a/computes/models.py b/computes/models.py
index 94f64f94..d9cc3e19 100644
--- a/computes/models.py
+++ b/computes/models.py
@@ -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):
diff --git a/instances/templates/allinstances_index_grouped.html b/instances/templates/allinstances_index_grouped.html
index bbc60edf..e320b729 100644
--- a/instances/templates/allinstances_index_grouped.html
+++ b/instances/templates/allinstances_index_grouped.html
@@ -41,7 +41,7 @@
{% trans "collapsed" %}
- {% if compute.status is True %}
+ {% if compute.status is True and compute.ram_usage is not None %}
{{ compute.cpu_count }} |
{{ compute.ram_size|filesizeformat }} |
diff --git a/instances/tests/test_list_unreachable.py b/instances/tests/test_list_unreachable.py
index 19fd0ce7..96ef14f9 100644
--- a/instances/tests/test_list_unreachable.py
+++ b/instances/tests/test_list_unreachable.py
@@ -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"))
diff --git a/instances/views.py b/instances/views.py
index 4f748712..ad06070b 100755
--- a/instances/views.py
+++ b/instances/views.py
@@ -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")},
|