1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-09 19:56:48 +00:00

fix(appsettings): settings take only the values the panel can use

The Settings page saved whatever was posted, and some lists offered
values the panel cannot use:

- Quota Debug could not be turned off: "False" is a non-empty text and
  counted as on.
- VM Clone Name Prefix showed as a True/False list, so no prefix could
  be typed, and touching it set the prefix to True.
- Disk SCSI Controller listed " lsilogic" with a space, never shown as
  chosen, and virtio-blk, which is no SCSI controller.
- VM Machine Type listed x86_64, an architecture; VM CD-ROM Device
  listed virtio, a bus a CD-ROM cannot use.
- Logs per Page and Disk Owner UID/GID are read with int(): a letter
  broke the logs page and VM create.

A migration fixes the lists and moves a value they no longer offer to
the default (the clone prefix keeps its text). A listed setting now
takes one of its choices, and every number setting a whole number in
its range, checked before it is saved.
This commit is contained in:
catborise 2026-10-25 21:47:11 +03:00
parent 9cf2d55b6e
commit 7392a5b4d2
7 changed files with 132 additions and 9 deletions

View file

@ -111,6 +111,19 @@ class QuotaTests(TestCase):
Instance.objects.filter(pk=vm.pk).update(is_template=True)
self.assertEqual(self.check(0, 2, 0, 0), ("", 3))
def test_the_numbers_show_only_with_quota_debug_on(self):
# the setting is the text "True" or "False": "False" turns them off
from appsettings.models import AppSettings
for i in range(5):
self.own(self.up, i)
for value, expected in (("True", "instance (6 > 5)"), ("False", "instance")):
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)
class QuotaViewTests(TestCase):
"""The resize views turn the result into a message and charge only what changes."""

View file

@ -62,7 +62,7 @@ def check_user_quota(user, instance, cpu, memory, disk_size):
if instance <= 0 and cpu <= 0 and memory <= 0 and disk_size <= 0:
return msg
quota_debug = app_settings.QUOTA_DEBUG
quota_debug = app_settings.QUOTA_DEBUG == "True"
user_instances = UserInstance.objects.filter(user=user, instance__is_template=False).select_related(
"instance__compute"