1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-08 19:26:48 +00:00
webvirtcloud/computes/test_overview_status.py
catborise 5e26f5a473 fix(computes): overview state comes from the connection
The overview page decided whether the host is up with a TCP probe of
the compute's hostname. For an ssh compute named by an ssh_config alias
or reached through ProxyJump, that name and port cannot be reached from
WebVirtCloud directly, so the probe failed while the connection worked:
the page showed the host details and never started the CPU and memory
graphs. The overview now uses Compute.status, the connection
WebVirtCloud uses for everything else.

The compute list shows why a host is not connected (Compute.connection_error)
under "Not Connected", for example a host key verification failure.

Checked against the ssh compute of the test setup through an
ssh_config alias: the previous code renders the overview with the
graphs off, the new one with them on. Both new tests fail on the
previous code.
2026-10-05 11:10:01 +03:00

37 lines
1.8 KiB
Python

from unittest.mock import PropertyMock, patch
from django.contrib.auth import get_user_model
from django.test import TestCase
from django.urls import reverse
from computes.models import Compute
ERROR = "Connection Failed: Host key verification failed."
class OverviewStatusTests(TestCase):
def setUp(self):
self.client.force_login(
get_user_model().objects.create_superuser(username="ov-admin", password="pwd", email="ov@example.com")
)
# an ssh_config alias: not a name a TCP probe can reach
self.compute = Compute.objects.create(name="ov-alias", hostname="wvc-alias", login="root", password="", type=2)
@patch("vrtManager.connection.connection_manager.host_is_up", return_value=False)
@patch("computes.views.wvmHostDetails")
def test_overview_state_comes_from_the_connection(self, host_details, host_is_up):
conn = host_details.return_value
conn.get_node_info.return_value = ("host", "x86_64", 1024, 2, "cpu", "qemu+ssh://root@wvc-alias/system")
conn.get_memory_usage.return_value = {"total": 1024, "usage": 512, "percent": 50}
with patch.object(Compute, "status", new_callable=PropertyMock, return_value=True):
response = self.client.get(reverse("overview", args=[self.compute.id]))
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context["status"], "true")
def test_compute_list_shows_why_a_host_is_not_connected(self):
with patch.object(Compute, "status", new_callable=PropertyMock, return_value=False), patch.object(
Compute, "connection_error", new_callable=PropertyMock, return_value=ERROR
):
response = self.client.get(reverse("computes"))
self.assertContains(response, "Not Connected")
self.assertContains(response, ERROR)