1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-09 19:56:48 +00:00
webvirtcloud/computes/tests/test_unreachable_host_pages.py
catborise d1fb9bd2d4 fix(console,computes): an unreachable host is named as the cause, not an empty list
The console page of a VM whose host does not answer said "Fail to get
console. Please check the console configuration of your VM." and logged
nothing. It now shows the connection error (to users who do not see the
hosts, that the host cannot be reached) and logs it with the VM and host.

A host's Storage, Networks, Interfaces, Filters and Secrets pages showed
the connection error and also "This host has no ...". The list is None
when it was not read, and the page shows only the error.
2026-11-06 23:08:11 +03:00

32 lines
1.4 KiB
Python

"""A host page whose list could not be read says why, and not that the host has none."""
from unittest.mock import patch
from django.contrib.auth.models import User
from django.test import TestCase
from django.urls import reverse
from vrtManager.util import ConnectionFailed
from computes.models import Compute
EMPTY = {
"storages": "This host has no storage pools.",
"networks": "This host has no networks.",
"interfaces": "libvirt lists no interfaces of this host.",
"nwfilters": "This host has no network filters.",
"virtsecrets": "This host has no secrets.",
}
class UnreachableHostPagesTestCase(TestCase):
def setUp(self):
self.compute = Compute.objects.create(name="c", hostname="192.0.2.10", login="u", password="p", type=1)
self.client.force_login(User.objects.create_superuser("hostadmin", "hostadmin@example.com", "pw"))
def test_the_connection_error_shows_without_an_empty_list(self):
failed = ConnectionFailed("Connection Failed: %(host)s did not answer within 5 s", host="192.0.2.10")
for page, empty in EMPTY.items():
with self.subTest(page), patch("vrtManager.connection.connection_manager.get_connection", side_effect=failed):
content = self.client.get(reverse(page, args=[self.compute.id])).content.decode()
self.assertIn("192.0.2.10 did not answer within 5 s", content)
self.assertNotIn(empty, content)