1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +00:00
webvirtcloud/instances/tests/test_guest_info.py
catborise 46931bdbdb feat(instances): the Guest Info tab shows how full the guest's file systems are
A disk filling up inside a guest was seen only from the guest. The Guest Info
tab now lists, from the guest agent, each mounted file system with its type
and used / total size, a bar turning amber from 85 %. File systems the agent
gives no size of (pseudo ones, Windows' System Reserved) are left out; an
agent without the command still shows the rest of the tab.
2026-11-20 09:30:15 +03:00

42 lines
2.3 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"])