1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-02 17:06:09 +00:00
webvirtcloud/instances/tests/test_guest_info.py
catborise 79f3b906dd fix(instances): Guest Info fits the tab, reads odd agent answers and says when usage is unknown
Audit and review (Codex, agy) of the file system list:
- the table had a side margin on a full-width table and ran past the tab's
  edge (on a phone its Used column was cut off); it now sits in a box that
  scrolls a long mount point, and on a phone the labels above it wrap by word;
- an agent answer that is not a list, an entry that is not an object, a
  negative, boolean or oversized size, or a null mount point or type no longer
  fails the tab or shows "None"; a "filesystems" key of another command is not
  taken for the list; the total is the whole file system's when the agent
  tells it (total-bytes-privileged), so used no longer passes it;
- when the agent does not give the file systems, a note says so;
- Turkish labels: "Kernel Version" was "Çekirdek Sürümü" like "Kernel Release",
  "OS Pretty-Name" read as a short name, "Timezone / Offset" as a location;
- the bulk migration live test's name no longer claims two at once, which its
  unit test checks.
2026-11-20 10:28:35 +03:00

47 lines
2.7 KiB
Python

"""The Guest Info tab's reading: the guest's OS and its file systems, their
sizes in words for the page."""
from unittest.mock import PropertyMock, patch
from django.contrib.auth import get_user_model
from django.template.loader import render_to_string
from django.test import TestCase
from django.urls import reverse
from lxml import html
from computes.models import Compute
from instances.models import Instance
class GuestInfoTestCase(TestCase):
def setUp(self):
compute = Compute.objects.create(name="gi", hostname="192.0.2.41", login="root", password="", type=1)
self.instance = Instance.objects.create(compute=compute, name="gi-vm", uuid="00000000-0000-4000-8000-0000000000a1")
self.client.force_login(get_user_model().objects.create_superuser("gi-admin", "gi@example.com", "pw"))
patcher = patch.object(Instance, "proxy", new_callable=PropertyMock)
self.proxy = patcher.start().return_value
self.addCleanup(patcher.stop)
def test_each_file_system_is_told_in_words(self):
self.proxy.osinfo.return_value = {"id": "rocky", "filesystems": [
{"mountpoint": "/", "type": "xfs", "used": 9 * 2**30, "total": 10 * 2**30}]}
data = self.client.get(reverse("instances:osinfo", args=[self.instance.pk])).json()
self.assertEqual(data["filesystems"], [{"mountpoint": "/", "type": "xfs", "used": 9 * 2**30, "total": 10 * 2**30,
"used_text": "9.0\xa0GB", "total_text": "10.0\xa0GB", "percent": 90}])
def test_a_file_system_used_past_its_total_is_full(self):
# a BSD guest's total leaves out the space reserved for root, which used counts
self.proxy.osinfo.return_value = {"filesystems": [{"mountpoint": "/", "type": "ufs", "used": 104, "total": 100}]}
data = self.client.get(reverse("instances:osinfo", args=[self.instance.pk])).json()
self.assertEqual(data["filesystems"][0]["percent"], 100)
def test_the_tab_has_a_hidden_table_for_them(self):
# filled and shown by instance_page.js when the agent gives some
table = html.fromstring(render_to_string("instances/info_tab.html")).xpath("//table[@id='osfilesystems']")[0]
self.assertIsNotNone(table.get("hidden"))
self.assertEqual(table.xpath(".//th/text()"), ["Mount point", "Type", "Used"])
# in a box that scrolls a long mount point, not in a margin past the tab's edge
self.assertIn("table-responsive", table.getparent().get("class"))
self.assertNotIn("mx-3", table.get("class"))
(note,) = html.fromstring(render_to_string("instances/info_tab.html")).xpath("//p[@id='osfilesystems-unread']")
self.assertIsNotNone(note.get("hidden"))