1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 12:46:49 +00:00

feat(locale): quota refusals and connection errors show in the reader's language

A quota refusal put the English name of the quota (cpu, memory, disk,
instance) into a translated sentence, so a Turkish page read "memory
kotası doldu". check_user_quota now returns which quota and its numbers
(QuotaExceeded), each quota has a whole sentence, and the refusals put
that sentence before what is refused; QUOTA_DEBUG adds the numbers as
before. The clone job stores the refusal as a message, so the Jobs page
shows it in its reader's language.

The connection errors of vrtManager (did not answer within, still
waited for, closed, failed with libvirt's text) were English f-strings;
they are messages now, each close reason a whole one. A connection
that died without a close callback raised an error reading "None"; it
now names the host. Logs keep the English text.
This commit is contained in:
catborise 2026-11-03 18:18:51 +03:00
parent 50f861b2aa
commit 4da64c46cd
11 changed files with 698 additions and 567 deletions

View file

@ -12,7 +12,8 @@ from django.contrib.messages import get_messages
from django.test import TestCase
from django.urls import reverse
from instances.models import Instance
from instances.utils import QUOTA_UNVERIFIED, check_user_quota
from instances.utils import QUOTA_UNVERIFIED, QuotaExceeded, check_user_quota, quota_message
from vrtManager.util import render
from libvirt import VIR_DOMAIN_PAUSED, VIR_DOMAIN_RUNNING
from operations.models import Operation
from vrtManager.util import OperationError
@ -71,7 +72,7 @@ class QuotaTests(TestCase):
"instances.utils.wvmInstance", side_effect=reader
) as wvm:
result = check_user_quota(self.user, *delta)
return result.split(" ")[0], wvm.call_count # without the QUOTA_DEBUG detail
return getattr(result, "kind", result), wvm.call_count # a QuotaExceeded names the quota
def test_vms_on_a_host_without_a_tcp_route_are_counted(self):
# an ssh_config alias: the old TCP probe failed and skipped these VMs
@ -191,12 +192,15 @@ class QuotaTests(TestCase):
for i in range(5):
self.own(self.up, i)
for value, expected in (("True", "instance (6 > 5)"), ("False", "instance")):
with patch.object(Compute, "status", True), patch("instances.utils.wvmInstance", side_effect=vm_reader()):
exceeded = check_user_quota(self.user, 1, 0, 0, 0)
self.assertEqual(exceeded, QuotaExceeded("instance", 6, 5))
for value, expected in (("True", "The quota of virtual machines is reached (6 > 5)"),
("False", "The quota of virtual machines is reached")):
with self.subTest(value=value):
AppSettings.objects.filter(key="QUOTA_DEBUG").update(value=value)
get_settings()
with patch.object(Compute, "status", True), patch("instances.utils.wvmInstance", side_effect=vm_reader()):
self.assertEqual(check_user_quota(self.user, 1, 0, 0, 0), expected)
self.assertEqual(render("%(quota)s", {"quota": quota_message(exceeded)}, str), expected)
class QuotaViewTests(TestCase):
@ -228,7 +232,7 @@ class QuotaViewTests(TestCase):
status=5)
self.assertEqual(len(messages), 1)
self.assertIn("a host of your virtual machines cannot be reached", messages[0])
self.assertNotIn("quota reached", messages[0])
self.assertNotIn("quota is reached", messages[0])
proxy.resize_cpu.assert_not_called()
def test_running_vm_memory_charges_no_maximum_change(self):

View file

@ -11,7 +11,7 @@ from django.contrib.messages import get_messages
from django.test import TestCase
from django.urls import reverse
from instances.models import Instance
from instances.utils import QUOTA_UNVERIFIED
from instances.utils import QUOTA_UNVERIFIED, QuotaExceeded
class TemplateFlagQuotaTests(TestCase):
@ -49,7 +49,7 @@ class TemplateFlagQuotaTests(TestCase):
def test_over_quota_the_template_stays_a_template(self):
Instance.objects.filter(pk=self.vm.pk).update(is_template=True)
_, messages = self.post(self.staff, is_template=False, quota="cpu")
_, messages = self.post(self.staff, is_template=False, quota=QuotaExceeded("cpu", 9, 8))
self.assertTrue(self.vm.is_template)
self.assertTrue(any("quota" in m for m in messages), messages)
@ -70,6 +70,6 @@ class TemplateFlagQuotaTests(TestCase):
def test_superusers_have_no_quota(self):
Instance.objects.filter(pk=self.vm.pk).update(is_template=True)
admin = get_user_model().objects.create_superuser("tq-admin", "tq@example.com", "pw")
check, _ = self.post(admin, is_template=False, quota="cpu")
check, _ = self.post(admin, is_template=False, quota=QuotaExceeded("cpu", 9, 8))
self.assertFalse(self.vm.is_template)
check.assert_not_called()