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

fix(computes): host pages survive a down host and a vTPM secret

- The host graphs and the machine/bus lists connect inside their libvirt
  error handling, so a down host gives empty answers instead of a 500 page
  the polling script drops.
- The Secrets page lists vTPM secrets instead of failing on them, and a
  secret without usage data shows an empty cell instead of "None".
- A TCP/TLS host takes a SASL password longer than 14 characters and a
  login up to the Linux limit of 32.
- The compute edit page says "Edit Compute"; a host without VMs no longer
  closes an extra page element; the memory graph is labelled MiB.
This commit is contained in:
catborise 2026-10-26 14:13:29 +03:00
parent 316cdadba2
commit 2ae7d8f967
12 changed files with 63 additions and 22 deletions

View file

@ -26,3 +26,8 @@ class ComputePasswordTests(TestCase):
password="secret", type=conn_type)
self.assertEqual(self.edit(compute, ""), "secret")
self.assertEqual(self.edit(compute, "other"), "other")
def test_a_long_password_is_kept_and_the_page_says_edit(self):
compute = Compute.objects.create(name="cp-long", hostname="192.0.2.7", login="admin", password="", type=1)
self.assertContains(self.client.get(reverse("compute_update", args=[compute.id])), "Edit Compute")
self.assertEqual(self.edit(compute, "p" * 40), "p" * 40)

View file

@ -20,6 +20,7 @@ from lxml import html
from computes.models import Compute
from computes.views import CPU_SAMPLE_MAX_AGE, CPU_SAMPLE_SIGNER
from vrtManager.hostdetails import cpu_percent, wvmHostDetails
from vrtManager.util import ConnectionFailed
# the page script runs after the shared chart helpers
CHARTS_JS = settings.BASE_DIR / "static" / "js" / "charts.js"
@ -77,7 +78,7 @@ class GraphTestCase(TestCase):
self.other = Compute.objects.create(name="other", hostname="192.0.2.2", login="u", password="p", type=1)
admin = get_user_model().objects.create_superuser("graph-admin", "graph@example.com", "pw")
self.client.force_login(admin)
for target in ("computes.views.wvmConnect", "computes.views.wvmHostDetails"):
for target in ("computes.models.wvmHostDetails", "computes.views.wvmHostDetails"):
patcher = patch(target)
self.addCleanup(patcher.stop)
self.conn = patcher.start().return_value # the graph reads through wvmHostDetails
@ -117,6 +118,16 @@ class GraphTestCase(TestCase):
self.assertEqual((data["cpudata"], data["memdata"]["total"]), (None, None))
self.assertNotIn("cpu_sample", data)
def test_a_host_that_cannot_be_connected_to_answers_without_values(self):
down = ConnectionFailed("192.0.2.1 is down")
with patch("computes.views.wvmHostDetails", side_effect=down), patch(
"computes.models.wvmHostDetails", side_effect=down
):
self.assertIsNone(self.graph()["cpudata"])
for url in (reverse("machines", args=[self.compute.id, "x86_64"]),
reverse("buses", args=[self.compute.id, "x86_64", "q35", "disk"])):
self.assertEqual(json.loads(self.client.get(url).content), {})
@unittest.skipUnless(shutil.which("node"), "node is not installed")
class GraphScriptTestCase(TestCase):

View file

@ -180,7 +180,7 @@ class ComputesTestCase(TestCase):
self.assertEqual(response.status_code, 200)
def test_a_disk_is_offered_the_hosts_disk_buses(self):
with patch("computes.views.wvmConnect") as conn:
with patch("computes.models.wvmHostDetails") as conn:
conn.return_value.get_disk_device_types.return_value = ["disk", "cdrom", "lun"]
conn.return_value.get_disk_bus_types.return_value = ["virtio", "sata", "scsi"]
response = self.client.get(reverse("buses", args=[self.compute.id, "x86_64", "q35", "disk"]))